diff doodle/undo/undo.d @ 40:1f97022e5c6d

Checkpoint. Development continues...
author daveb
date Mon, 12 Apr 2010 14:01:54 +0930
parents
children ad3ba55ae57b
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/doodle/undo/undo.d	Mon Apr 12 14:01:54 2010 +0930
@@ -0,0 +1,66 @@
+module doodle.undo.undo;
+
+// http://doc.trolltech.com/4.2/qundo.html
+// http://www.codeproject.com/KB/cs/undo_support.aspx
+
+// rename Action to Edit?
+
+// Related design patterns: Command, Memento
+
+// Action represents and encapsulates the information needed 
+// Consider command merging and time-stamping of commands
+
+abstract class Action {
+    void undo();
+    void redo();
+    //string description() const;
+    // bool merge(Action other);
+    // time-stamp
+}
+
+final class CompoundAction {
+    this(in Action[] sub_actions) {
+        mSubActions = sub_actions.dup;
+    }
+
+    void undo() {
+        foreach_reverse(a; mSubActions) { a.undo(); }
+    }
+
+    void redo() {
+        foreach(a; mSubActions) { a.redo(); }
+    }
+
+    private {
+        Action[] mSubActions;
+    }
+}
+
+interface IUndoManagerObserver {
+    void canUndo(in bool value, in string description);
+    void canRedo(in bool value, in string description);
+}
+
+interface IUndoManager {
+    void addAction(Action action);
+    void undo();
+    void redo();
+    // bool can_undo() const;
+    // bool can_redo() const;
+}
+
+class UndoManager : IUndoManager {
+    this(int max_undo_level = -1) {
+    }
+
+    void addAction(Action action);
+    void undo();
+    void redo();
+
+    // IUndoManager overrides:
+
+    private {
+        Action[] mUndoActions;
+        Action[] mRedoActions;
+    }
+}