1
This commit is contained in:
@@ -4,8 +4,16 @@ namespace XED.Command
|
||||
{
|
||||
public class CommandInvoker
|
||||
{
|
||||
public Stack<ICommand> commandStack = new Stack<ICommand>();
|
||||
public void Invoke<T>(T command) where T : IReversibleCommand
|
||||
Stack<ICommand> commandStack = new();
|
||||
Stack<IReversibleCommand> undoableStack = new ();
|
||||
public void Invoke(IReversibleCommand command)
|
||||
{
|
||||
command.Execute();
|
||||
commandStack.Push(command);
|
||||
undoableStack.Push(command);
|
||||
}
|
||||
|
||||
public void Invoke(IIrreversibleCommand command)
|
||||
{
|
||||
command.Execute();
|
||||
commandStack.Push(command);
|
||||
@@ -13,12 +21,12 @@ namespace XED.Command
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
if (commandStack.Count == 0)
|
||||
if (undoableStack.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var command = commandStack.Pop();
|
||||
(command as IReversibleCommand) .Undo();
|
||||
var command = undoableStack.Pop();
|
||||
command.Undo();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user