keyboard shortcut for Undo, plus gratuitous use of ternary operator
authorRichard Fairhurst <richard@systemed.net>
Sat, 22 May 2010 08:50:27 +0000 (08:50 +0000)
committerRichard Fairhurst <richard@systemed.net>
Sat, 22 May 2010 08:50:27 +0000 (08:50 +0000)
net/systemeD/halcyon/connection/MainUndoStack.as
net/systemeD/potlatch2/controller/ControllerState.as
net/systemeD/potlatch2/controller/DrawWay.as
net/systemeD/potlatch2/controller/NoSelection.as
net/systemeD/potlatch2/controller/SelectedPOINode.as
net/systemeD/potlatch2/controller/SelectedWay.as
net/systemeD/potlatch2/controller/SelectedWayNode.as

index 5f9790d..4e7fdb7 100644 (file)
@@ -68,6 +68,7 @@ package net.systemeD.halcyon.connection {
         }
         
         public function undo():void {
+                       if (!undoActions.length) { return; }
             var action:UndoableAction = undoActions.pop();
             trace("undoing "+action);
             action.undoAction();
@@ -77,6 +78,7 @@ package net.systemeD.halcyon.connection {
         }
         
         public function redo():void {
+                       if (!redoActions.length) { return; }
             var action:UndoableAction = redoActions.pop();
             trace("redoing "+action);
             action.doAction();
index 23946f4..8db5a01 100644 (file)
@@ -45,6 +45,13 @@ package net.systemeD.potlatch2.controller {
                        return "(No state)";
                }
                
+               protected function sharedKeyboardEvents(event:KeyboardEvent):ControllerState {
+                       switch (event.keyCode) {
+                               case 90:        MainUndoStack.getGlobalStack().undo(); return null;             // Z
+                       }
+                       return null;
+               }
+               
                protected function sharedMouseEvents(event:MouseEvent, entity:Entity):ControllerState {
                        var paint:MapPaint = getMapPaint(DisplayObject(event.target));
             var focus:Entity = getTopLevelFocusEntity(entity);
index 1772146..af1cdeb 100644 (file)
@@ -96,7 +96,8 @@ package net.systemeD.potlatch2.controller {
                override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
                        if ( event.keyCode == 13 || event.keyCode == 27 ) { return stopDrawing(); }
                        else if (event.keyCode == Keyboard.BACKSPACE) { return backspaceNode(MainUndoStack.getGlobalStack().addAction); }
-                       return this;
+                       var cs:ControllerState = sharedKeyboardEvents(event);
+                       return cs ? cs : this;
                }
                
                protected function stopDrawing():ControllerState {
index 83bdb05..e40eaa0 100644 (file)
@@ -28,8 +28,12 @@ package net.systemeD.potlatch2.controller {
                                return new DrawWay(way, true, false);
                        }
                        var cs:ControllerState = sharedMouseEvents(event, entity);
-                       if (cs) return cs;
-                       return this;
+                       return cs ? cs : this;
+               }
+               
+               override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
+                       var cs:ControllerState = sharedKeyboardEvents(event);
+                       return cs ? cs : this;
                }
                
         override public function enterState():void {
index 8472563..9d158d9 100644 (file)
@@ -34,8 +34,7 @@ package net.systemeD.potlatch2.controller {
         override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
                        if (event.type==MouseEvent.MOUSE_MOVE) { return this; }
                        var cs:ControllerState = sharedMouseEvents(event, entity);
-                       if (cs) return cs;
-            return this;
+                       return cs ? cs : this;
         }
 
                override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
@@ -43,7 +42,8 @@ package net.systemeD.potlatch2.controller {
                                case Keyboard.BACKSPACE:        return deletePOI();
                                case Keyboard.DELETE:           return deletePOI();
                        }
-                       return this;
+                       var cs:ControllerState = sharedKeyboardEvents(event);
+                       return cs ? cs : this;
                }
                
                public function deletePOI():ControllerState {
index 7762b7c..f7e6d32 100644 (file)
@@ -54,8 +54,7 @@ package net.systemeD.potlatch2.controller {
                                return d;
                        }
                        var cs:ControllerState = sharedMouseEvents(event, entity);
-                       if (cs) return cs;
-                       return this;
+                       return cs ? cs : this;
         }
         
                override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
@@ -68,7 +67,8 @@ package net.systemeD.potlatch2.controller {
                                case Keyboard.BACKSPACE:        if (event.shiftKey) { return deleteWay(); } break;
                                case Keyboard.DELETE:           if (event.shiftKey) { return deleteWay(); } break;
                        }
-                       return this;
+                       var cs:ControllerState = sharedKeyboardEvents(event);
+                       return cs ? cs : this;
                }
 
         protected function addNode(event:MouseEvent):int {
index 502644b..be414df 100644 (file)
@@ -56,8 +56,7 @@ package net.systemeD.potlatch2.controller {
                                return d;
                        }
                        var cs:ControllerState = sharedMouseEvents(event, entity);
-                       if (cs) return cs;
-                       return this;
+                       return cs ? cs : this;
         }
 
                override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
@@ -67,7 +66,8 @@ package net.systemeD.potlatch2.controller {
                                case Keyboard.BACKSPACE:        return deleteNode();
                                case Keyboard.DELETE:           return deleteNode();
                        }
-                       return this;
+                       var cs:ControllerState = sharedKeyboardEvents(event);
+                       return cs ? cs : this;
                }
                
                override public function enterState():void {