Escape on a newly-begun way cancels it properly (using Undo if possible)
authorRichard Fairhurst <richard@systemed.net>
Wed, 8 Sep 2010 13:22:28 +0000 (13:22 +0000)
committerRichard Fairhurst <richard@systemed.net>
Wed, 8 Sep 2010 13:22:28 +0000 (13:22 +0000)
net/systemeD/halcyon/connection/MainUndoStack.as
net/systemeD/potlatch2/controller/DrawWay.as

index f76aa8b..b2450fe 100644 (file)
@@ -80,6 +80,16 @@ package net.systemeD.halcyon.connection {
             dispatchEvent(new Event("new_redo_item"));
         }
         
+               public function undoIfAction(action:Class):Boolean {
+                       if (!undoActions.length) { return false; }
+                       if (undoActions[undoActions.length-1] is action) {
+                               undo();
+                               return true;
+                       } else {
+                               return false;
+                       }
+               }
+
         public function redo():void {
                        if (!redoActions.length) { return; }
             var action:UndoableAction = redoActions.pop();
index 05d9499..886ef56 100644 (file)
@@ -154,8 +154,8 @@ package net.systemeD.potlatch2.controller {
 
                override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
                        switch (event.keyCode) {
-                               case 13:                                        return stopDrawing();
-                               case 27:                                        return stopDrawing();
+                               case 13:                                        return keyExitDrawing();
+                               case 27:                                        return keyExitDrawing();
                                case Keyboard.DELETE:           return backspaceNode(MainUndoStack.getGlobalStack().addAction);
                                case Keyboard.BACKSPACE:        return backspaceNode(MainUndoStack.getGlobalStack().addAction);
                                case 82:                                        repeatTags(selectedWay); return this;
@@ -164,6 +164,16 @@ package net.systemeD.potlatch2.controller {
                        return cs ? cs : this;
                }
                
+               protected function keyExitDrawing():ControllerState {
+                       if (selectedWay.length==1) { 
+                               if (MainUndoStack.getGlobalStack().undoIfAction(BeginWayAction)) { 
+                                       return new NoSelection();
+                               }
+                               return deleteWay();
+                       }
+                       return stopDrawing();
+               }
+               
                protected function stopDrawing():ControllerState {
                        if ( hoverEntity ) {
                                controller.map.setHighlightOnNodes(hoverEntity as Way, { hoverway: false });