40
|
1 module doodle.undo.undo;
|
|
2
|
|
3 // http://doc.trolltech.com/4.2/qundo.html
|
|
4 // http://www.codeproject.com/KB/cs/undo_support.aspx
|
|
5
|
|
6 // rename Action to Edit?
|
|
7
|
|
8 // Related design patterns: Command, Memento
|
|
9
|
|
10 // Action represents and encapsulates the information needed
|
|
11 // Consider command merging and time-stamping of commands
|
|
12
|
|
13 abstract class Action {
|
|
14 void undo();
|
|
15 void redo();
|
|
16 //string description() const;
|
|
17 // bool merge(Action other);
|
|
18 // time-stamp
|
|
19 }
|
|
20
|
|
21 final class CompoundAction {
|
|
22 this(in Action[] sub_actions) {
|
|
23 mSubActions = sub_actions.dup;
|
|
24 }
|
|
25
|
|
26 void undo() {
|
|
27 foreach_reverse(a; mSubActions) { a.undo(); }
|
|
28 }
|
|
29
|
|
30 void redo() {
|
|
31 foreach(a; mSubActions) { a.redo(); }
|
|
32 }
|
|
33
|
|
34 private {
|
|
35 Action[] mSubActions;
|
|
36 }
|
|
37 }
|
|
38
|
|
39 interface IUndoManagerObserver {
|
|
40 void canUndo(in bool value, in string description);
|
|
41 void canRedo(in bool value, in string description);
|
|
42 }
|
|
43
|
|
44 interface IUndoManager {
|
|
45 void addAction(Action action);
|
|
46 void undo();
|
|
47 void redo();
|
|
48 // bool can_undo() const;
|
|
49 // bool can_redo() const;
|
|
50 }
|
|
51
|
|
52 class UndoManager : IUndoManager {
|
|
53 this(int max_undo_level = -1) {
|
|
54 }
|
|
55
|
|
56 void addAction(Action action);
|
|
57 void undo();
|
|
58 void redo();
|
|
59
|
|
60 // IUndoManager overrides:
|
|
61
|
|
62 private {
|
|
63 Action[] mUndoActions;
|
|
64 Action[] mRedoActions;
|
|
65 }
|
|
66 }
|