-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
200 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using BlazorDatasheet.Data; | ||
|
||
namespace BlazorDatasheet.Commands; | ||
|
||
public class SetMetaDataCommand : IUndoableCommand | ||
{ | ||
private readonly int _row; | ||
private readonly int _col; | ||
private readonly string _name; | ||
private readonly object? _value; | ||
private object? _oldValue; | ||
|
||
public SetMetaDataCommand(int row, int col, string name, object? value) | ||
{ | ||
_row = row; | ||
_col = col; | ||
_name = name; | ||
_value = value; | ||
} | ||
|
||
public bool Execute(Sheet sheet) | ||
{ | ||
_oldValue = sheet.GetMetaData(_row, _col, _name); | ||
sheet.SetMetaDataImpl(_row, _col, _name, _value); | ||
return true; | ||
} | ||
|
||
public bool Undo(Sheet sheet) | ||
{ | ||
sheet.SetMetaDataImpl(_row, _col, _name, _oldValue); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace BlazorDatasheet.Events; | ||
|
||
public class CellMetaDataChangeEventArgs | ||
{ | ||
public CellMetaDataChangeEventArgs(int row, int col, string name, object? oldValue, object? newValue) | ||
{ | ||
Name = name; | ||
OldValue = oldValue; | ||
NewValue = newValue; | ||
Row = row; | ||
Col = col; | ||
} | ||
|
||
public int Row { get; } | ||
public int Col { get; } | ||
public string Name { get; } | ||
public object? OldValue { get; } | ||
public object? NewValue { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using BlazorDatasheet.Data; | ||
using NUnit.Framework; | ||
|
||
namespace BlazorDatasheet.Test; | ||
|
||
public class MetaDataTests | ||
{ | ||
[Test] | ||
public void Set_Cell_MetaData_And_Undo_Works() | ||
{ | ||
var sheet = new Sheet(3, 3); | ||
sheet.SetCellMetaData(1, 1, "test", 7); | ||
Assert.AreEqual(7, sheet.GetMetaData(1, 1, "test")); | ||
sheet.SetCellMetaData(1, 1, "test", 8); | ||
Assert.AreEqual(8, sheet.GetMetaData(1, 1, "test")); | ||
sheet.Commands.Undo(); | ||
Assert.AreEqual(7, sheet.GetMetaData(1, 1, "test")); | ||
} | ||
|
||
[Test] | ||
public void Set_Cell_MetaData_Fires_Event() | ||
{ | ||
var sheet = new Sheet(3, 3); | ||
var fired = false; | ||
var rowFired = -1; | ||
var colFired = -1; | ||
var nameFired = ""; | ||
object? newData = null; | ||
sheet.MetaDataChanged += (sender, args) => | ||
{ | ||
fired = true; | ||
rowFired = args.Row; | ||
colFired = args.Col; | ||
newData = args.NewValue; | ||
nameFired = args.Name; | ||
}; | ||
|
||
sheet.SetCellMetaData(1, 2, "test", "value"); | ||
|
||
Assert.True(fired); | ||
Assert.AreEqual(1, rowFired); | ||
Assert.AreEqual(2, colFired); | ||
Assert.AreEqual("test", nameFired); | ||
Assert.AreEqual("value", newData); | ||
} | ||
} |