Shift-R: paste relations from previously selected object, as per #3596.
[potlatch2.git] / net / systemeD / potlatch2 / controller / SelectedPOINode.as
1 package net.systemeD.potlatch2.controller {
2         import flash.events.*;
3         import flash.display.*;
4         import flash.ui.Keyboard;
5     import net.systemeD.potlatch2.EditController;
6     import net.systemeD.halcyon.connection.*;
7     import net.systemeD.halcyon.MapPaint;
8
9     public class SelectedPOINode extends ControllerState {
10         protected var initNode:Node;
11
12         public function SelectedPOINode(node:Node, layer:MapPaint=null) {
13                         if (layer) this.layer=layer;
14             initNode = node;
15         }
16  
17         protected function selectNode(node:Node):void {
18             if ( firstSelected is Node && Node(firstSelected)==node )
19                 return;
20
21             clearSelection(this);
22             layer.setHighlight(node, { selected: true });
23             selection = [node];
24             controller.updateSelectionUI();
25             initNode = node;
26         }
27                 
28         protected function clearSelection(newState:ControllerState):void {
29             if ( selectCount ) {
30                 layer.setHighlight(firstSelected, { selected: false });
31                 selection = [];
32                 if (!newState.isSelectionState()) { controller.updateSelectionUI(); }
33             }
34         }
35         
36         override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
37                         if (event.type==MouseEvent.MOUSE_MOVE) { return this; }
38                         var paint:MapPaint = getMapPaint(DisplayObject(event.target));
39
40                         if (event.type==MouseEvent.MOUSE_DOWN && event.ctrlKey && !event.altKey && entity && entity!=firstSelected && paint==layer) {
41                                 return new SelectedMultiple([firstSelected,entity],layer);
42                         } else if (event.type==MouseEvent.MOUSE_DOWN && event.shiftKey && !entity && !layer.isBackground) {
43                                 return new DrawQuadrilateral(firstSelected as Node);
44                         } else if ( event.type == MouseEvent.MOUSE_UP && entity==firstSelected ) {
45                                 return this;
46                         }
47                         var cs:ControllerState = sharedMouseEvents(event, entity);
48                         return cs ? cs : this;
49         }
50
51                 override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
52                         switch (event.keyCode) {
53                                 case Keyboard.BACKSPACE:        return deletePOI();
54                                 case Keyboard.DELETE:           return deletePOI();
55                 case 82:  /* R */           { if (! event.shiftKey) repeatTags(firstSelected); 
56                                               else                  repeatRelations(firstSelected);
57                                               return this; }
58                         }
59                         var cs:ControllerState = sharedKeyboardEvents(event);
60                         return cs ? cs : this;
61                 }
62
63                 public function deletePOI():ControllerState {
64                         firstSelected.connection.unregisterPOI(firstSelected as Node);
65                         firstSelected.remove(MainUndoStack.getGlobalStack().addAction);
66                         return new NoSelection();
67                 }
68
69         override public function enterState():void {
70             selectNode(initNode);
71                         layer.setPurgable(selection,false);
72         }
73         override public function exitState(newState:ControllerState):void {
74             if(firstSelected.hasTags()) {
75               controller.clipboards['node']=firstSelected.getTagsCopy();
76             }
77             copyRelations(firstSelected);
78                         layer.setPurgable(selection,true);
79             clearSelection(newState);
80         }
81
82         override public function toString():String {
83             return "SelectedPOINode";
84         }
85
86     }
87 }