don't break when you ctrl-click the background
[potlatch2.git] / net / systemeD / potlatch2 / controller / SelectedMultiple.as
1 package net.systemeD.potlatch2.controller {
2         import flash.events.*;
3         import flash.display.DisplayObject;
4         import flash.ui.Keyboard;
5         import net.systemeD.potlatch2.EditController;
6         import net.systemeD.halcyon.connection.*;
7         import net.systemeD.halcyon.MapPaint;
8         import net.systemeD.halcyon.WayUI;
9         import net.systemeD.halcyon.Globals;
10
11         public class SelectedMultiple extends ControllerState {
12                 protected var initSelection:Array;
13                 
14                 public function SelectedMultiple(sel:Array) {
15                         initSelection=sel.concat();
16                 }
17
18                 override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
19                         if (event.type==MouseEvent.MOUSE_MOVE || event.type==MouseEvent.ROLL_OVER || event.type==MouseEvent.MOUSE_OUT) { return this; }
20                         var focus:Entity = getTopLevelFocusEntity(entity);
21
22                         if ( event.type == MouseEvent.MOUSE_DOWN && entity && event.ctrlKey ) {
23                                 // modify selection
24                                 controller.map.setHighlight(entity, { selected: toggleSelection(entity) });
25                                 controller.updateSelectionUI();
26
27                                 if (selectCount>1) { return this; }
28                                 return controller.findStateForSelection(selection);
29                         }
30                         var cs:ControllerState = sharedMouseEvents(event, entity);
31                         return cs ? cs : this;
32                 }
33
34                 override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
35                         var cs:ControllerState = sharedKeyboardEvents(event);
36                         return cs ? cs : this;
37                 }
38
39                 override public function enterState():void {
40                         selection=initSelection.concat();
41                         for each (var entity:Entity in selection) {
42                                 controller.map.setHighlight(entity, { selected: true, hover: false });
43                         }
44                         controller.updateSelectionUI();
45                         controller.map.setPurgable(selection,false);
46                         Globals.vars.root.addDebug("**** -> "+this+" "+selection);
47                 }
48
49                 override public function exitState(newState:ControllerState):void {
50                         controller.map.setPurgable(selection,true);
51                         for each (var entity:Entity in selection) {
52                                 controller.map.setHighlight(entity, { selected: false, hover: false });
53                         }
54                         selection = [];
55                         if (!newState.isSelectionState()) { controller.updateSelectionUI(); }
56                         Globals.vars.root.addDebug("**** <- "+this);
57                 }
58
59                 override public function toString():String {
60                         return "SelectedMultiple";
61                 }
62
63         }
64 }