Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Diagnostics;
|
---|
6 |
|
---|
7 | namespace Microsoft.Research.DynamicDataDisplay.Common.UndoSystem
|
---|
8 | {
|
---|
9 | [DebuggerDisplay("Count = {Count}")]
|
---|
10 | public sealed class ActionStack
|
---|
11 | {
|
---|
12 | private readonly Stack<UndoAction> stack = new Stack<UndoAction>();
|
---|
13 |
|
---|
14 | public void Push(UndoAction action)
|
---|
15 | {
|
---|
16 | stack.Push(action);
|
---|
17 |
|
---|
18 | if (stack.Count == 1)
|
---|
19 | RaiseIsEmptyChanged();
|
---|
20 | }
|
---|
21 |
|
---|
22 | public UndoAction Pop()
|
---|
23 | {
|
---|
24 | var action = stack.Pop();
|
---|
25 |
|
---|
26 | if (stack.Count == 0)
|
---|
27 | RaiseIsEmptyChanged();
|
---|
28 |
|
---|
29 | return action;
|
---|
30 | }
|
---|
31 |
|
---|
32 | public int Count { get { return stack.Count; } }
|
---|
33 |
|
---|
34 | public void Clear()
|
---|
35 | {
|
---|
36 | stack.Clear();
|
---|
37 | RaiseIsEmptyChanged();
|
---|
38 | }
|
---|
39 |
|
---|
40 | public bool IsEmpty
|
---|
41 | {
|
---|
42 | get { return stack.Count == 0; }
|
---|
43 | }
|
---|
44 |
|
---|
45 | private void RaiseIsEmptyChanged()
|
---|
46 | {
|
---|
47 | IsEmptyChanged.Raise(this);
|
---|
48 | }
|
---|
49 | public event EventHandler IsEmptyChanged;
|
---|
50 | }
|
---|
51 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.