remove a huge load of pseudo-traces
[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
7     public class SelectedPOINode extends ControllerState {
8         protected var initNode:Node;
9
10         public function SelectedPOINode(node:Node) {
11             initNode = node;
12         }
13  
14         protected function selectNode(node:Node):void {
15             if ( firstSelected is Node && Node(firstSelected)==node )
16                 return;
17
18             clearSelection(this);
19             controller.map.setHighlight(node, { selected: true });
20             selection = [node];
21             controller.updateSelectionUI();
22             initNode = node;
23         }
24                 
25         protected function clearSelection(newState:ControllerState):void {
26             if ( selectCount ) {
27                 controller.map.setHighlight(firstSelected, { selected: false });
28                 selection = [];
29                 if (!newState.isSelectionState()) { controller.updateSelectionUI(); }
30             }
31         }
32         
33         override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
34                         if (event.type==MouseEvent.MOUSE_MOVE) { return this; }
35                         if (event.type==MouseEvent.MOUSE_DOWN && event.ctrlKey && entity && entity!=firstSelected) {
36                                 return new SelectedMultiple([firstSelected,entity]);
37                         }
38                         var cs:ControllerState = sharedMouseEvents(event, entity);
39                         return cs ? cs : this;
40         }
41
42                 override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
43                         switch (event.keyCode) {
44                                 case Keyboard.BACKSPACE:        return deletePOI();
45                                 case Keyboard.DELETE:           return deletePOI();
46                                 case 82:                                        repeatTags(firstSelected); return this; // 'R'
47                         }
48                         var cs:ControllerState = sharedKeyboardEvents(event);
49                         return cs ? cs : this;
50                 }
51
52                 public function deletePOI():ControllerState {
53                         controller.connection.unregisterPOI(firstSelected as Node);
54                         firstSelected.remove(MainUndoStack.getGlobalStack().addAction);
55                         return new NoSelection();
56                 }
57
58         override public function enterState():void {
59             selectNode(initNode);
60                         controller.map.setPurgable(selection,false);
61         }
62         override public function exitState(newState:ControllerState):void {
63             if(firstSelected.hasTags()) {
64               controller.clipboards['node']=firstSelected.getTagsCopy();
65             }
66                         controller.map.setPurgable(selection,true);
67             clearSelection(newState);
68         }
69
70         override public function toString():String {
71             return "SelectedPOINode";
72         }
73
74     }
75 }