Shift-R: paste relations from previously selected object, as per #3596.
[potlatch2.git] / net / systemeD / potlatch2 / controller / SelectedPOINode.as
index fa278fd..46d0b75 100644 (file)
@@ -1,38 +1,49 @@
 package net.systemeD.potlatch2.controller {
        import flash.events.*;
+       import flash.display.*;
        import flash.ui.Keyboard;
     import net.systemeD.potlatch2.EditController;
     import net.systemeD.halcyon.connection.*;
-       import net.systemeD.halcyon.Globals;
+    import net.systemeD.halcyon.MapPaint;
 
     public class SelectedPOINode extends ControllerState {
         protected var initNode:Node;
 
-        public function SelectedPOINode(node:Node) {
+        public function SelectedPOINode(node:Node, layer:MapPaint=null) {
+                       if (layer) this.layer=layer;
             initNode = node;
         }
  
         protected function selectNode(node:Node):void {
-            if ( node == selectedNode )
+            if ( firstSelected is Node && Node(firstSelected)==node )
                 return;
 
             clearSelection(this);
-            controller.setSelectedEntity(node);
-            controller.map.setHighlight(node, { selected: true });
-            selectedNode = node;
+            layer.setHighlight(node, { selected: true });
+            selection = [node];
+            controller.updateSelectionUI();
             initNode = node;
         }
                 
         protected function clearSelection(newState:ControllerState):void {
-            if ( selectedNode != null ) {
-                controller.map.setHighlight(selectedNode, { selected: false });
-                if (!newState.isSelectionState()) { controller.setSelectedEntity(null); }
-                selectedNode = null;
+            if ( selectCount ) {
+                layer.setHighlight(firstSelected, { selected: false });
+                selection = [];
+                if (!newState.isSelectionState()) { controller.updateSelectionUI(); }
             }
         }
         
         override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
                        if (event.type==MouseEvent.MOUSE_MOVE) { return this; }
+                       var paint:MapPaint = getMapPaint(DisplayObject(event.target));
+
+                       if (event.type==MouseEvent.MOUSE_DOWN && event.ctrlKey && !event.altKey && entity && entity!=firstSelected && paint==layer) {
+                               return new SelectedMultiple([firstSelected,entity],layer);
+                       } else if (event.type==MouseEvent.MOUSE_DOWN && event.shiftKey && !entity && !layer.isBackground) {
+                               return new DrawQuadrilateral(firstSelected as Node);
+                       } else if ( event.type == MouseEvent.MOUSE_UP && entity==firstSelected ) {
+                               return this;
+                       }
                        var cs:ControllerState = sharedMouseEvents(event, entity);
                        return cs ? cs : this;
         }
@@ -41,26 +52,31 @@ package net.systemeD.potlatch2.controller {
                        switch (event.keyCode) {
                                case Keyboard.BACKSPACE:        return deletePOI();
                                case Keyboard.DELETE:           return deletePOI();
-                               case 82:                                        repeatTags(selectedNode); return this;  // 'R'
+                case 82:  /* R */           { if (! event.shiftKey) repeatTags(firstSelected); 
+                                              else                  repeatRelations(firstSelected);
+                                              return this; }
                        }
                        var cs:ControllerState = sharedKeyboardEvents(event);
                        return cs ? cs : this;
                }
-               
+
                public function deletePOI():ControllerState {
-                       controller.connection.unregisterPOI(selectedNode);
-                       selectedNode.remove(MainUndoStack.getGlobalStack().addAction);
+                       firstSelected.connection.unregisterPOI(firstSelected as Node);
+                       firstSelected.remove(MainUndoStack.getGlobalStack().addAction);
                        return new NoSelection();
                }
 
         override public function enterState():void {
             selectNode(initNode);
-                       Globals.vars.root.addDebug("**** -> "+this);
+                       layer.setPurgable(selection,false);
         }
         override public function exitState(newState:ControllerState):void {
-                       controller.clipboards['node']=selectedNode.getTagsCopy();
+            if(firstSelected.hasTags()) {
+              controller.clipboards['node']=firstSelected.getTagsCopy();
+            }
+            copyRelations(firstSelected);
+                       layer.setPurgable(selection,true);
             clearSelection(newState);
-                       Globals.vars.root.addDebug("**** <- "+this);
         }
 
         override public function toString():String {