don't break when you ctrl-click the background
[potlatch2.git] / net / systemeD / potlatch2 / controller / SelectedPOINode.as
1 package net.systemeD.potlatch2.controller {
2         import flash.events.*;
3         import flash.ui.Keyboard;
4     import net.systemeD.potlatch2.EditController;
5     import net.systemeD.halcyon.connection.*;
6         import net.systemeD.halcyon.Globals;
7
8     public class SelectedPOINode extends ControllerState {
9         protected var initNode:Node;
10
11         public function SelectedPOINode(node:Node) {
12             initNode = node;
13         }
14  
15         protected function selectNode(node:Node):void {
16             if ( firstSelected is Node && Node(firstSelected)==node )
17                 return;
18
19             clearSelection(this);
20             controller.map.setHighlight(node, { selected: true });
21             selection = [node];
22             controller.updateSelectionUI();
23             initNode = node;
24         }
25                 
26         protected function clearSelection(newState:ControllerState):void {
27             if ( selectCount ) {
28                 controller.map.setHighlight(firstSelected, { selected: false });
29                 selection = [];
30                 if (!newState.isSelectionState()) { controller.updateSelectionUI(); }
31             }
32         }
33         
34         override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
35                         if (event.type==MouseEvent.MOUSE_MOVE) { return this; }
36                         if (event.type==MouseEvent.MOUSE_DOWN && event.ctrlKey && entity && entity!=firstSelected) {
37                                 return new SelectedMultiple([firstSelected,entity]);
38                         }
39                         var cs:ControllerState = sharedMouseEvents(event, entity);
40                         return cs ? cs : this;
41         }
42
43                 override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
44                         switch (event.keyCode) {
45                                 case Keyboard.BACKSPACE:        return deletePOI();
46                                 case Keyboard.DELETE:           return deletePOI();
47                                 case 82:                                        repeatTags(firstSelected); return this; // 'R'
48                         }
49                         var cs:ControllerState = sharedKeyboardEvents(event);
50                         return cs ? cs : this;
51                 }
52
53                 public function deletePOI():ControllerState {
54                         controller.connection.unregisterPOI(firstSelected as Node);
55                         firstSelected.remove(MainUndoStack.getGlobalStack().addAction);
56                         return new NoSelection();
57                 }
58
59         override public function enterState():void {
60             selectNode(initNode);
61                         controller.map.setPurgable(selection,false);
62                         Globals.vars.root.addDebug("**** -> "+this);
63         }
64         override public function exitState(newState:ControllerState):void {
65                         controller.clipboards['node']=firstSelected.getTagsCopy();
66                         controller.map.setPurgable(selection,true);
67             clearSelection(newState);
68                         Globals.vars.root.addDebug("**** <- "+this);
69         }
70
71         override public function toString():String {
72             return "SelectedPOINode";
73         }
74
75     }
76 }