press J to merge ways
authorRichard Fairhurst <richard@systemed.net>
Sun, 16 Jan 2011 16:52:28 +0000 (16:52 +0000)
committerRichard Fairhurst <richard@systemed.net>
Sun, 16 Jan 2011 16:52:28 +0000 (16:52 +0000)
net/systemeD/potlatch2/Toolbox.mxml
net/systemeD/potlatch2/controller/SelectedMultiple.as

index bd1cd80c2ae0cda8abd8e95a37f29811cd9c31fb..88cf90aa9e9246fc245618025ef745ec86c00d09 100644 (file)
                }
                
                public function doMerge():void {
-                       var changed:Boolean;
-                       var waylist:Array=controller.state.selectedWays;
-                       do {
-                               // ** FIXME - we should have one CompositeUndoableAction for the whole caboodle,
-                               // but that screws up the execution order and can make the merge not work
-                               var undo:CompositeUndoableAction = new CompositeUndoableAction("Merge ways");
-                               changed=tryMerge(waylist, undo);
-                               MainUndoStack.getGlobalStack().addAction(undo);
-                       } while (changed==true);
-                       controller.setState(controller.findStateForSelection(waylist));
-               }
-               
-               private function tryMerge(waylist:Array, undo:CompositeUndoableAction):Boolean {
-                       var way1:Way, way2:Way, del:uint;
-                       for (var i:uint=0; i<waylist.length; i++) {
-                               for (var j:uint=0; j<waylist.length; j++) {
-                                       if (waylist[i]!=waylist[j]) {
-
-                                               // Preserve positive IDs if we can
-                                               if (waylist[i].id < waylist[j].id && waylist[i].id >= 0) {
-                                                       way1=waylist[i]; way2=waylist[j]; del=j;
-                                               } else {
-                                                       way1=waylist[j]; way2=waylist[i]; del=i;
-                                               }
-
-                                               // Merge as appropriate
-                                               if (way1.getNode(0)==way2.getNode(0)) {
-                                                       waylist.splice(del,1);
-                                                       undo.push(new MergeWaysAction(way1,way2,0,0));
-                                                       return true;
-                                               } else if (way1.getNode(0)==way2.getLastNode()) { 
-                                                       waylist.splice(del,1);
-                                                       undo.push(new MergeWaysAction(way1,way2,0,way2.length-1));
-                                                       return true;
-                                               } else if (way1.getLastNode()==way2.getNode(0)) {
-                                                       waylist.splice(del,1);
-                                                       undo.push(new MergeWaysAction(way1,way2,way1.length-1,0));
-                                                       return true;
-                                               } else if (way1.getLastNode()==way2.getLastNode()) { 
-                                                       waylist.splice(del,1);
-                                                       undo.push(new MergeWaysAction(way1,way2,way1.length-1,way2.length-1));
-                                                       return true;
-                                               }
-                                       }
-                               }
-                       }
-                       return false;
+                       controller.setState(SelectedMultiple(controller.state).mergeWays());
                }
 
                public function doReverseDirection():void {
index 912195e5adc69de6cf871329cb28ffc07e18e42d..11352357bffbe86c25f2f8a9d1d1e98cf98ec017 100644 (file)
@@ -4,6 +4,7 @@ package net.systemeD.potlatch2.controller {
        import flash.ui.Keyboard;
        import net.systemeD.potlatch2.EditController;
        import net.systemeD.halcyon.connection.*;
+       import net.systemeD.halcyon.connection.actions.MergeWaysAction;
        import net.systemeD.halcyon.MapPaint;
        import net.systemeD.halcyon.WayUI;
        import net.systemeD.halcyon.Globals;
@@ -32,9 +33,60 @@ package net.systemeD.potlatch2.controller {
                }
 
                override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
+                       if (event.keyCode==74) return mergeWays();      // 'J'
                        var cs:ControllerState = sharedKeyboardEvents(event);
                        return cs ? cs : this;
                }
+               
+               public function mergeWays():ControllerState {
+                       var changed:Boolean;
+                       var waylist:Array=selectedWays;
+                       do {
+                               // ** FIXME - we should have one CompositeUndoableAction for the whole caboodle,
+                               // but that screws up the execution order and can make the merge not work
+                               var undo:CompositeUndoableAction = new CompositeUndoableAction("Merge ways");
+                               changed=tryMerge(waylist, undo);
+                               MainUndoStack.getGlobalStack().addAction(undo);
+                       } while (changed==true);
+                       return controller.findStateForSelection(waylist);
+               }
+               
+               private function tryMerge(waylist:Array, undo:CompositeUndoableAction):Boolean {
+                       var way1:Way, way2:Way, del:uint;
+                       for (var i:uint=0; i<waylist.length; i++) {
+                               for (var j:uint=0; j<waylist.length; j++) {
+                                       if (waylist[i]!=waylist[j]) {
+
+                                               // Preserve positive IDs if we can
+                                               if (waylist[i].id < waylist[j].id && waylist[i].id >= 0) {
+                                                       way1=waylist[i]; way2=waylist[j]; del=j;
+                                               } else {
+                                                       way1=waylist[j]; way2=waylist[i]; del=i;
+                                               }
+
+                                               // Merge as appropriate
+                                               if (way1.getNode(0)==way2.getNode(0)) {
+                                                       waylist.splice(del,1);
+                                                       undo.push(new MergeWaysAction(way1,way2,0,0));
+                                                       return true;
+                                               } else if (way1.getNode(0)==way2.getLastNode()) { 
+                                                       waylist.splice(del,1);
+                                                       undo.push(new MergeWaysAction(way1,way2,0,way2.length-1));
+                                                       return true;
+                                               } else if (way1.getLastNode()==way2.getNode(0)) {
+                                                       waylist.splice(del,1);
+                                                       undo.push(new MergeWaysAction(way1,way2,way1.length-1,0));
+                                                       return true;
+                                               } else if (way1.getLastNode()==way2.getLastNode()) { 
+                                                       waylist.splice(del,1);
+                                                       undo.push(new MergeWaysAction(way1,way2,way1.length-1,way2.length-1));
+                                                       return true;
+                                               }
+                                       }
+                               }
+                       }
+                       return false;
+               }
 
                override public function enterState():void {
                        selection=initSelection.concat();