Shift-R: paste relations from previously selected object, as per #3596.
[potlatch2.git] / net / systemeD / potlatch2 / controller / SelectedPOINode.as
index 536ce16..46d0b75 100644 (file)
@@ -1,80 +1,82 @@
 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 selectedNode:Node;
         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();
-            controller.setTagViewer(node);
-            controller.map.setHighlight(node, { selected: true });
-            selectedNode = node;
+            clearSelection(this);
+            layer.setHighlight(node, { selected: true });
+            selection = [node];
+            controller.updateSelectionUI();
             initNode = node;
         }
                 
-        protected function clearSelection():void {
-            if ( selectedNode != null ) {
-                controller.map.setHighlight(selectedNode, { selected: false });
-                controller.setTagViewer(null);
-                selectedNode = null;
+        protected function clearSelection(newState:ControllerState):void {
+            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 || event.type==MouseEvent.ROLL_OVER || event.type==MouseEvent.MOUSE_OUT) { return this; }
-            var focus:Entity = NoSelection.getTopLevelFocusEntity(entity);
-
-            if ( event.type == MouseEvent.MOUSE_UP ) {
-                               if ( entity is Way ) {
-                    return new SelectedWay(entity as Way);
-                               // ** do we need 'entity is Node && focus is Way' for POIs in ways?
-                } else if ( focus == null && map.dragstate!=map.DRAGGING ) {
-                    return new NoSelection();
-                               }
-            } else if ( event.type == MouseEvent.MOUSE_DOWN ) {
-                if ( focus is Node ) {
-                                       return new DragPOINode(entity as Node,event,false);
-                } else if ( entity is Node && focus is Way ) {
-                                       return new DragWayNode(focus as Way,entity as Node,event,false);
-                               }
-            }
+                       if (event.type==MouseEvent.MOUSE_MOVE) { return this; }
+                       var paint:MapPaint = getMapPaint(DisplayObject(event.target));
 
-            return this;
+                       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;
         }
 
                override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
                        switch (event.keyCode) {
                                case Keyboard.BACKSPACE:        return deletePOI();
                                case Keyboard.DELETE:           return deletePOI();
+                case 82:  /* R */           { if (! event.shiftKey) repeatTags(firstSelected); 
+                                              else                  repeatRelations(firstSelected);
+                                              return this; }
                        }
-                       return this;
+                       var cs:ControllerState = sharedKeyboardEvents(event);
+                       return cs ? cs : this;
                }
-               
+
                public function deletePOI():ControllerState {
-                       controller.connection.unregisterPOI(selectedNode);
-                       selectedNode.remove();
+                       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():void {
-            clearSelection();
-                       Globals.vars.root.addDebug("**** <- "+this);
+        override public function exitState(newState:ControllerState):void {
+            if(firstSelected.hasTags()) {
+              controller.clipboards['node']=firstSelected.getTagsCopy();
+            }
+            copyRelations(firstSelected);
+                       layer.setPurgable(selection,true);
+            clearSelection(newState);
         }
 
         override public function toString():String {