-
Notifications
You must be signed in to change notification settings - Fork 95
/
CommandManager.cs
53 lines (44 loc) · 1.09 KB
/
CommandManager.cs
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System.Collections.Generic;
namespace NoteEditor.Common
{
public class CommandManager
{
Stack<Command> undoStack = new Stack<Command>();
Stack<Command> redoStack = new Stack<Command>();
public void Do(Command command)
{
command.Do();
undoStack.Push(command);
redoStack.Clear();
}
public void Clear()
{
undoStack.Clear();
redoStack.Clear();
}
public void Undo()
{
if (undoStack.Count == 0)
return;
var command = undoStack.Pop();
command.Undo();
redoStack.Push(command);
}
public void Redo()
{
if (redoStack.Count == 0)
return;
var command = redoStack.Pop();
command.Redo();
undoStack.Push(command);
}
public bool CanUndo()
{
return undoStack.Count > 0;
}
public bool CanRedo()
{
return redoStack.Count > 0;
}
}
}