Prevent single-node ways from being created by undo.
[potlatch2.git] / net / systemeD / halcyon / connection / MainUndoStack.as
index b2450fe..38f87ff 100644 (file)
@@ -2,6 +2,13 @@ package net.systemeD.halcyon.connection {
 
     import flash.events.*;
 
+
+    /**
+    * The main undo stack controls which actions can be undone or redone from the current situation.
+    *
+    * @see UndoableAction All actions inherit from undoable action
+    */
+
     public class MainUndoStack extends EventDispatcher {
         private static const GLOBAL_INSTANCE:MainUndoStack = new MainUndoStack();
         
@@ -12,7 +19,7 @@ package net.systemeD.halcyon.connection {
         private var undoActions:Array = [];
         private var redoActions:Array = [];
 
-        /*
+        /**
          * Performs the action, then puts it on the undo stack.
          *
          * If you want to delay execution don't put it on this
@@ -50,8 +57,8 @@ package net.systemeD.halcyon.connection {
             }
         }
         
-        /*
-         * Call to kill the undo queue -- the user will not be able to undo
+        /**
+         * Call to kill the undo and redo stacks -- the user will not be able to undo
          * anything they previously did after this is called.
          */
         public function breakUndo():void {
@@ -70,7 +77,10 @@ package net.systemeD.halcyon.connection {
         public function canRedo():Boolean {
             return redoActions.length > 0;
         }
-        
+
+        /**
+        * Undo the most recent action, and add it to the top of the redo stack
+        */
         public function undo():void {
                        if (!undoActions.length) { return; }
             var action:UndoableAction = undoActions.pop();
@@ -79,7 +89,11 @@ package net.systemeD.halcyon.connection {
             dispatchEvent(new Event("new_undo_item"));
             dispatchEvent(new Event("new_redo_item"));
         }
-        
+
+        /**
+        * Undo the most recent action, but only if it's a particular class
+        * @param action The class of the previous action, for testing
+        */
                public function undoIfAction(action:Class):Boolean {
                        if (!undoActions.length) { return false; }
                        if (undoActions[undoActions.length-1] is action) {
@@ -89,7 +103,30 @@ package net.systemeD.halcyon.connection {
                                return false;
                        }
                }
+               
+               public function removeLastIfAction(action:Class):void {
+                       if (undoActions.length && undoActions[undoActions.length-1] is action) {
+                               undoActions.pop();
+                       }
+               }
+
+        [Bindable(event="new_undo_item")]
+               public function getUndoDescription():String {
+                       if (undoActions.length==0) return null;
+                       if (undoActions[undoActions.length-1].name) return undoActions[undoActions.length-1].name;
+                       return null;
+               }
+
+        [Bindable(event="new_redo_item")]
+               public function getRedoDescription():String {
+                       if (redoActions.length==0) return null;
+                       if (redoActions[redoActions.length-1].name) return redoActions[redoActions.length-1].name;
+                       return null;
+               }
 
+        /**
+        * Takes the action most recently undone, does it, and adds it to the undo stack
+        */
         public function redo():void {
                        if (!redoActions.length) { return; }
             var action:UndoableAction = redoActions.pop();