a whole load more event listener fixes, plus the start of multiple selection
[potlatch2.git] / net / systemeD / potlatch2 / Toolbox.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2 <mx:Panel
3         xmlns:mx="http://www.adobe.com/2006/mxml"
4         xmlns:potlatch2="net.systemeD.potlatch2.*"
5         height="46" width="219" 
6         headerHeight="6" headerColors="[black, gray]" 
7         borderThicknessRight="0" borderThicknessLeft="0" borderThicknessBottom="0" 
8         paddingLeft="4" paddingTop="4" layout="absolute" >
9
10                 <mx:Image data="@Embed('../../../embedded/close_small.png')"
11                     includeInLayout="false" id="toolboxClose" click="toggle();" 
12                     y="-6" x="205" />
13
14         <mx:Button icon="@Embed('../../../embedded/delete.svg')"
15                         click='doDelete();' 
16                         enabled="{canDo('delete')}" 
17                         alpha="{getAlpha('delete')}" 
18                         toolTip="{deleteToolTipText()}" 
19                         width="28" height="28" textAlign="left" y="4" x="6" paddingLeft="6" paddingRight="0" />
20         <mx:Button icon="@Embed('../../../embedded/direction.svg')" 
21             click='doReverseDirection();'
22                         enabled="{canDo('reverseDirection')}" 
23                         alpha="{getAlpha('reverseDirection')}" 
24                         toolTip="Reverse direction (V)" 
25                         width="28" height="28" textAlign="left" y="4" x="36" paddingLeft="8" paddingRight="0" />
26         <mx:Button icon="@Embed('../../../embedded/cut.svg')" 
27                click='doSplit();'
28                         enabled="{canDo('split')}" 
29                         alpha="{getAlpha('split')}" 
30                         toolTip="Split way (X)" 
31                         width="28" height="28" textAlign="left" y="4" x="66" paddingLeft="8" paddingRight="0" />
32         <mx:Button icon="@Embed('../../../embedded/straighten.svg')" 
33                         click='doStraighten();' 
34                         enabled="{canDo('straighten')}" 
35                         alpha="{getAlpha('straighten')}" 
36                         toolTip="Straighten way" 
37                         width="28" height="28" textAlign="left" y="4" x="96" paddingLeft="5" paddingRight="0" />
38         <mx:Button icon="@Embed('../../../embedded/circle.svg')" 
39                         click='doCircularise();' 
40                         enabled="{canDo('circularise')}" 
41                         alpha="{getAlpha('circularise')}" 
42                         toolTip="Make circular" 
43                         width="28" height="28" textAlign="left" y="4" x="126" paddingLeft="4" paddingRight="0" />
44         <mx:Button icon="@Embed('../../../embedded/quadrilateralise.svg')" 
45                         click='doQuadrilateralise();' 
46                         enabled="{canDo('quadrilateralise')}" 
47                         alpha="{getAlpha('quadrilateralise')}" 
48                         toolTip="Make right-angled" 
49                         width="28" height="28" textAlign="left" y="4" x="156" paddingLeft="6" paddingRight="0" />
50         <mx:Button icon="@Embed('../../../embedded/parallel.svg')" 
51                         click='doParallelise();' 
52                         enabled="{canDo('parallelise')}" 
53                         alpha="{getAlpha('parallelise')}" 
54                         toolTip="Create parallel way (P)" 
55                         width="28" height="28" textAlign="left" y="4" x="186" paddingLeft="8" paddingRight="0" />
56
57         <mx:Script><![CDATA[
58
59                 import flash.events.Event;
60                 import flash.events.MouseEvent;
61                 import net.systemeD.halcyon.connection.*;
62             import net.systemeD.potlatch2.controller.*;
63             import net.systemeD.potlatch2.tools.*;
64
65                 private var controller:EditController;
66
67                 public function init(controller:EditController):void {
68                         this.controller=controller;
69             /* check if the toolbox was explictly turned off in a previous session */
70             if( SharedObject.getLocal("user_state").data['toolbox_visible'] == false) {
71               this.visible = false;
72             }
73                 }
74
75                 override protected function createChildren():void {
76                         super.createChildren();
77                         super.titleBar.addEventListener(MouseEvent.MOUSE_DOWN,handleDown);
78                         super.titleBar.addEventListener(MouseEvent.MOUSE_UP,handleUp);
79                 }
80
81                 public function updateSelectionUI():void {
82                         dispatchEvent(new Event("updateSkin"));
83                         dispatchEvent(new Event("updateAlpha"));
84                 }
85
86                 private function handleDown(e:Event):void {
87                         this.startDrag();
88                 }
89
90                 private function handleUp(e:Event):void {
91                         this.stopDrag();
92                 }
93                 
94                 public function toggle():void {
95                         this.visible=!this.visible;
96             var obj:SharedObject = SharedObject.getLocal("user_state");
97             obj.setProperty("toolbox_visible",this.visible);
98             obj.flush();
99                 }
100                 
101                 // --------------------------------------------------------------------------------
102                 // Enable/disable toolbox buttons
103                 // (ideally we'd use CSS to set alpha in disabled state, but Flex's CSS
104                 //  capabilities aren't up to it)
105                 
106         [Bindable(event="updateSkin")]
107                 public function canDo(op:String):Boolean {
108                         if (controller.state.selectCount==0) return false;
109
110                         var entity:Entity=controller.state.firstSelected;
111                         switch (op) {
112                                 case 'delete':                          return true;
113                                 case 'reverseDirection':        return (entity is Way);
114                                 case 'quadrilateralise':        return (entity is Way && Way(entity).isArea());
115                                 case 'straighten':                      return (entity is Way && !Way(entity).isArea());
116                                 case 'circularise':                     return (entity is Way && Way(entity).isArea());
117                                 case 'split':                           return (controller.state is SelectedWayNode);
118                                 case 'parallelise':                     return (entity is Way);
119                         }
120                         return false;
121                 }
122
123         [Bindable(event="updateAlpha")]
124                 public function getAlpha(op:String):Number {
125                         if (canDo(op)) { return 1; }
126                         return 0.5;
127                 }
128
129         [Bindable(event="updateSkin")]
130         private function deleteToolTipText():String {
131                         var entity:Entity=controller.state.firstSelected;
132             if (entity is Node) { return "Delete Node (Delete)"; }
133             if (entity is Way && Way(entity).isArea()) { return "Delete Area (Shift+Delete)"; }
134             if (entity is Way) { return "Delete Way (Shift+Delete)"; }
135             return "Delete Item"; // When nothing is selected
136         }
137
138                 // --------------------------------------------------------------------------------
139                 // Individual toolbox actions
140
141                 public function doDelete():void {
142             var undo:CompositeUndoableAction = new CompositeUndoableAction("Delete objects");
143                         for each (var entity:Entity in controller.state.selection) {
144                                 if (entity is Node) { controller.connection.unregisterPOI(Node(entity)); }
145                                 entity.remove(undo.push);
146                         }
147             MainUndoStack.getGlobalStack().addAction(undo);
148
149                         if (controller.state is SelectedWayNode) {
150                                 controller.setState(new SelectedWay(SelectedWayNode(controller.state).selectedWay));
151                         } else {
152                                 controller.setState(new NoSelection());
153                         }
154                 }
155
156         public function doReverseDirection():void {
157                         if (controller.state is SelectedWay) {
158                 Way(controller.state.firstSelected).reverseNodes(MainUndoStack.getGlobalStack().addAction);
159             }
160         }
161
162                 public function doQuadrilateralise():void {
163                         if (controller.state is SelectedWay) {
164                                 Quadrilateralise.quadrilateralise(Way(controller.state.firstSelected));
165                         }
166                 }
167
168                 public function doStraighten():void {
169                         if (controller.state is SelectedWay) {
170                                 Straighten.straighten(Way(controller.state.firstSelected),controller.map);
171                         }
172                 }
173
174                 public function doCircularise():void {
175                         if (controller.state is SelectedWay) {
176                                 Circularise.circularise(Way(controller.state.firstSelected),controller.map);
177                         }
178                 }
179
180                 public function doSplit():void {
181                         if (controller.state is SelectedWayNode) {
182                                 controller.setState(SelectedWayNode(controller.state).splitWay());
183                         }
184                 }
185                 
186                 public function doParallelise():void {
187                         if (controller.state is SelectedWay) {
188                                 controller.setState(new SelectedParallelWay(Way(controller.state.firstSelected)));
189                         }
190                 }
191
192
193     ]]>
194 </mx:Script>    
195 </mx:Panel>