forked from danieldantasdev/DesignPatternsInUse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandManager.cs
More file actions
32 lines (29 loc) · 727 Bytes
/
CommandManager.cs
File metadata and controls
32 lines (29 loc) · 727 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public class CommandManager
{
private Stack<ICommand> _undoStack = new Stack<ICommand>();
private Stack<ICommand> _redoStack = new Stack<ICommand>();
public void ExecuteCommand(ICommand command)
{
command.Execute();
_undoStack.Push(command);
_redoStack.Clear();
}
public void Undo()
{
if (_undoStack.Count > 0)
{
ICommand command = _undoStack.Pop();
command.Undo();
_redoStack.Push(command);
}
}
public void Redo()
{
if (_redoStack.Count > 0)
{
ICommand command = _redoStack.Pop();
command.Execute();
_undoStack.Push(command);
}
}
}