Add keyboard shortcuts to toolbox tooltips. The Delete Item adapts depending on what...
[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 entity:Entity;
66                 private var controller:EditController;
67
68                 public function init(controller:EditController):void {
69                         this.controller=controller;
70             /* check if the toolbox was explictly turned off in a previous session */
71             if( SharedObject.getLocal("user_state").data['toolbox_visible'] == false) {
72               this.visible = false;
73             }
74                 }
75
76                 override protected function createChildren():void {
77                         super.createChildren();
78                         super.titleBar.addEventListener(MouseEvent.MOUSE_DOWN,handleDown);
79                         super.titleBar.addEventListener(MouseEvent.MOUSE_UP,handleUp);
80                 }
81
82                 public function setEntity(entity:Entity):void {
83                         this.entity=entity;
84                         dispatchEvent(new Event("updateSkin"));
85                         dispatchEvent(new Event("updateAlpha"));
86                 }
87
88                 private function handleDown(e:Event):void {
89                         this.startDrag();
90                 }
91
92                 private function handleUp(e:Event):void {
93                         this.stopDrag();
94                 }
95                 
96                 public function toggle():void {
97                         this.visible=!this.visible;
98             var obj:SharedObject = SharedObject.getLocal("user_state");
99             obj.setProperty("toolbox_visible",this.visible);
100             obj.flush();
101                 }
102                 
103                 // --------------------------------------------------------------------------------
104                 // Enable/disable toolbox buttons
105                 // (ideally we'd use CSS to set alpha in disabled state, but Flex's CSS
106                 //  capabilities aren't up to it)
107                 
108         [Bindable(event="updateSkin")]
109                 public function canDo(op:String):Boolean {
110                         switch (op) {
111                                 case 'delete':                          return (entity is Way || entity is Node);
112                                 case 'reverseDirection':        return (entity is Way);
113                                 case 'quadrilateralise':        return (entity is Way && Way(entity).isArea());
114                                 case 'straighten':                      return (entity is Way && !Way(entity).isArea());
115                                 case 'circularise':                     return (entity is Way && Way(entity).isArea());
116                                 case 'split':                           return (entity is Node && controller.state is SelectedWayNode);
117                                 case 'parallelise':                     return (entity is Way);
118                         }
119                         return false;
120                 }
121
122         [Bindable(event="updateAlpha")]
123                 public function getAlpha(op:String):Number {
124                         if (canDo(op)) { return 1; }
125                         return 0.5;
126                 }
127
128         [Bindable(event="updateSkin")]
129         private function deleteToolTipText():String {
130             if (entity is Node) { return "Delete Node (Delete)"; }
131             if (entity is Way && Way(entity).isArea()) { return "Delete Area (Shift+Delete)"; }
132             if (entity is Way) { return "Delete Way (Shift+Delete)"; }
133             return "Delete Item"; // When nothing is selected
134         }
135
136                 // --------------------------------------------------------------------------------
137                 // Individual toolbox actions
138
139                 public function doDelete():void {
140                         if (entity is Node) { controller.connection.unregisterPOI(Node(entity)); }
141                         entity.remove(MainUndoStack.getGlobalStack().addAction);
142
143                         if (controller.state is SelectedWayNode) {
144                                 controller.setState(new SelectedWay(SelectedWayNode(controller.state).selectedWay));
145                         } else {
146                                 controller.setState(new NoSelection());
147                         }
148                 }
149
150         public function doReverseDirection():void {
151             if (entity is Way) { 
152                 Way(entity).reverseNodes(MainUndoStack.getGlobalStack().addAction);
153             }
154         }
155
156                 public function doQuadrilateralise():void {
157                         if (entity is Way) {
158                                 Quadrilateralise.quadrilateralise(Way(entity));
159                         }
160                 }
161
162                 public function doStraighten():void {
163                         if (entity is Way) {
164                                 Straighten.straighten(Way(entity),controller.map);
165                         }
166                 }
167
168                 public function doCircularise():void {
169                         if (entity is Way) {
170                                 Circularise.circularise(Way(entity),controller.map);
171                         }
172                 }
173
174                 public function doSplit():void {
175                         if (entity is Node && controller.state is SelectedWayNode) {
176                                 controller.setState(SelectedWayNode(controller.state).splitWay());
177                         }
178                 }
179                 
180                 public function doParallelise():void {
181                         if (entity is Way) {
182                                 controller.setState(new SelectedParallelWay(Way(entity)));
183                         }
184                 }
185
186
187     ]]>
188 </mx:Script>    
189 </mx:Panel>