Retain preferences even when .swf filename has changed
[potlatch2.git] / net / systemeD / potlatch2 / Toolbox.mxml
index 135629a..1826e26 100644 (file)
@@ -1,96 +1,91 @@
 <?xml version="1.0" encoding="utf-8"?>
 <mx:Panel
-       xmlns:mx="http://www.adobe.com/2006/mxml"
+    xmlns:fx="http://ns.adobe.com/mxml/2009"
+       xmlns:mx="library://ns.adobe.com/flex/mx"
+       xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:potlatch2="net.systemeD.potlatch2.*"
        height="76" width="129" layout="absolute"
        styleName="theToolBox">
 
-        <!-- the animation effect that controls the rotation of the reverse arrow.
-              We could get more fancy by using previous angle in angleFrom, and a longer duration, to give a nice animated effect -->
-        <mx:Rotate id="rotate" angleFrom="{angle-1}" angleTo="{angle}" target="{arrowBox}" originX="{arrowBox.width/2}" originY="{arrowBox.height/2}" duration="4"/>
-
-
                <mx:Image data="@Embed('../../../embedded/close_small.png')"
                        includeInLayout="false" id="toolboxClose" click="toggle();" 
                        y="-6" x="115" />
 
                <!-- Top row -->
 
-               <mx:Button icon="@Embed('../../../embedded/delete.svg')"
-                       click='doDelete();' 
+               <s:Button icon="@Embed('../../../embedded/delete.svg')"
+                       click='doDelete(event.ctrlKey,event.shiftKey);' 
                        enabled="{canDo('delete')}" 
                        alpha="{getAlpha('delete')}" 
                        toolTip="{deleteToolTipText()}" 
-                       width="28" height="28" textAlign="left" y="4" x="6" paddingLeft="6" paddingRight="0" />
-
-        <mx:HBox width="28" height="28" y="4" x="36" borderStyle="solid" cornerRadius="4" click="reverseClicked();" horizontalAlign="center" verticalAlign="middle">
-            <mx:ViewStack id="rotateButtonStack">
-                <mx:HBox id="arrowBoxWrapper"><!-- changing the viewstack back onto a rotated hbox causes positioning glitches, hence this wrapper -->
-                    <!-- I can totally recommend adding borderStyle="solid" to arrowBox when debugging -->
-                    <mx:HBox id="arrowBox" horizontalAlign="center" verticalAlign="middle" width="24" height="24">
-                        <mx:Image id="arrow" source="@Embed('../../../embedded/arrow.svg')"
-                            alpha="{getAlpha('reverseDirection')}"
-                            toolTip="Reverse direction (V)"
-                            width="22" height="22"/>
-                    </mx:HBox>
+                       width="28" height="28" y="4" x="6" />
+
+               <mx:HBox id="reverseButton" width="28" height="28" y="4" x="36" borderStyle="none"
+                          horizontalAlign="center" verticalAlign="middle" toolTip="Reverse direction (V)">
+            <mx:ViewStack id="rotateButtonStack" creationPolicy="all">
+                <mx:HBox id="arrowBoxWrapper">
+                                       <s:NavigatorContent width="28" height="28">
+                                               <s:Button id="arrow" icon="{Arrow}" width="28" height="28" alpha="{getAlpha('reverseDirection')}" click="reverseClicked();"/>
+                                       </s:NavigatorContent>
                 </mx:HBox>
                 <mx:HBox id="clockwiseBox" horizontalAlign="center" verticalAlign="middle">
-                    <mx:Image id="clockwise" source="@Embed('../../../embedded/clockwise.svg')"
+                    <s:Button id="clockwise" icon="@Embed('../../../embedded/clockwise.svg')"
                         alpha="{getAlpha('reverseDirection')}"
-                        toolTip="Reverse direction (V)"
-                        width="22" height="22" x="2" y="2"/>
+                        width="28" height="28" click="reverseClicked();" />
                 </mx:HBox>
                 <mx:HBox id="antiClockwiseBox" horizontalAlign="center" verticalAlign="middle">
-                    <mx:Image id="anticlockwise" source="@Embed('../../../embedded/anti-clockwise.svg')"
-                        click='doReverseDirection();'
+                    <s:Button id="anticlockwise" icon="@Embed('../../../embedded/anti-clockwise.svg')"
                         enabled="{canDo('reverseDirection')}"
                         alpha="{getAlpha('reverseDirection')}"
-                        toolTip="Reverse direction (V)"
-                        width="22" height="22" x="2" y="2"/>
+                        width="28" height="28" click="reverseClicked();" />
                 </mx:HBox>
             </mx:ViewStack>
         </mx:HBox>
-               <mx:Button icon="@Embed('../../../embedded/cut.svg')" 
+               <s:Button icon="@Embed('../../../embedded/cut.svg')"
+                       id="splitButton"
                        click='doSplit();'
                        enabled="{canDo('split')}" 
                        alpha="{getAlpha('split')}" 
                        toolTip="Split way (X)" 
-                       width="28" height="28" textAlign="left" y="4" x="66" paddingLeft="8" paddingRight="0" />
-               <mx:Button icon="@Embed('../../../embedded/merge.svg')" 
+                       width="28" height="28" y="4" x="66" />
+               <s:Button 
+                       id="mergeButton"
                        click='doMerge();'
-                       enabled="{canDo('merge')}" 
-                       alpha="{getAlpha('merge')}" 
                        toolTip="Merge ways" 
-                       width="28" height="28" textAlign="left" y="4" x="96" paddingLeft="3" paddingRight="0" />
+                       width="28" height="28" y="4" x="96" />
 
                <!-- Second row -->
 
-               <mx:Button icon="@Embed('../../../embedded/straighten.svg')" 
+               <s:Button icon="@Embed('../../../embedded/straighten.svg')"
+                       id="straightenButton"
                        click='doStraighten();' 
                        enabled="{canDo('straighten')}" 
                        alpha="{getAlpha('straighten')}" 
                        toolTip="Straighten way" 
-                       width="28" height="28" textAlign="left" y="34" x="6" paddingLeft="5" paddingRight="0" />
-               <mx:Button icon="@Embed('../../../embedded/circle.svg')" 
+                       width="28" height="28" y="34" x="6" />
+               <s:Button icon="@Embed('../../../embedded/circle.svg')"
+                       id="circulariseButton"
                        click='doCircularise();' 
                        enabled="{canDo('circularise')}" 
                        alpha="{getAlpha('circularise')}" 
                        toolTip="Make circular" 
-                       width="28" height="28" textAlign="left" y="34" x="36" paddingLeft="4" paddingRight="0" />
-               <mx:Button icon="@Embed('../../../embedded/quadrilateralise.svg')" 
+                       width="28" height="28" y="34" x="36" />
+               <s:Button icon="@Embed('../../../embedded/quadrilateralise.svg')"
+                       id="quadrilateraliseButton"
                        click='doQuadrilateralise();' 
                        enabled="{canDo('quadrilateralise')}" 
                        alpha="{getAlpha('quadrilateralise')}" 
                        toolTip="Make right-angled (Q)"
-                       width="28" height="28" textAlign="left" y="34" x="66" paddingLeft="6" paddingRight="0" />
-               <mx:Button icon="@Embed('../../../embedded/parallel.svg')" 
+                       width="28" height="28" y="34" x="66" />
+               <s:Button icon="@Embed('../../../embedded/parallel.svg')"
+                       id="parralleliseButton"
                        click='doParallelise();' 
                        enabled="{canDo('parallelise')}" 
                        alpha="{getAlpha('parallelise')}" 
                        toolTip="Create parallel way (P)" 
-                       width="28" height="28" textAlign="left" y="34" x="96" paddingLeft="8" paddingRight="0" />
+                       width="28" height="28" y="34" x="96" />
 
-       <mx:Script><![CDATA[
+       <fx:Script><![CDATA[
 
                import flash.events.Event;
                import flash.events.MouseEvent;
                import net.systemeD.halcyon.connection.actions.*;
                import net.systemeD.potlatch2.controller.*;
                import net.systemeD.potlatch2.tools.*;
+               import embedded.*;      // for FXG icons
 
                private var controller:EditController;
 
         [Bindable]
         public var angle:int=0;
 
+        public var deleteNode:String = "Delete Node (Delete)";
+        public var deleteArea:String = "Delete Area (Shift+Delete)";
+        public var deleteWay:String = "Delete Way (Shift+Delete)";
+        public var deleteItem:String = "Delete Item"; // When nothing is selected
+
+       [Bindable] [Embed(source="../../../embedded/merge.svg"       )] private var mergeIcon:Class;
+       [Bindable] [Embed(source="../../../embedded/multipolygon.svg")] private var multipolygonIcon:Class;
+
                public function init(controller:EditController):void {
                        this.controller=controller;
                        /* check if the toolbox was explictly turned off in a previous session */
-                       if( SharedObject.getLocal("user_state").data['toolbox_visible'] == false) {
+                       if( SharedObject.getLocal("user_state","/").data['toolbox_visible'] == false) {
                          this.visible = false;
                        }
                }
                override protected function createChildren():void {
                        super.createChildren();
                        super.titleBar.addEventListener(MouseEvent.MOUSE_DOWN,handleDown);
-                       super.titleBar.addEventListener(MouseEvent.MOUSE_UP,handleUp);
                }
 
                public function updateSelectionUI():void {
                        dispatchEvent(new Event("updateSkin"));
                        dispatchEvent(new Event("updateAlpha"));
                        updateDirectionArrow();
+                       updateMergeIcon();
                }
 
                private function handleDown(e:Event):void {
                        this.startDrag();
+                       stage.addEventListener(MouseEvent.MOUSE_UP,handleUp);
                }
 
                private function handleUp(e:Event):void {
                        this.stopDrag();
+                       stage.removeEventListener(MouseEvent.MOUSE_UP,handleUp);
                }
                
                public function toggle():void {
                        this.visible=!this.visible;
-                       var obj:SharedObject = SharedObject.getLocal("user_state");
+                       var obj:SharedObject = SharedObject.getLocal("user_state","/");
                        obj.setProperty("toolbox_visible",this.visible);
                        obj.flush();
                }
                                case 'circularise':                     return controller.state.hasSelectedAreas();
                                case 'split':                           return (controller.state is SelectedWayNode);
                                case 'parallelise':                     return (controller.state is SelectedWay);
-                               case 'merge':                           return controller.state.hasAdjoiningWays();
                        }
                        return false;
                }
                [Bindable(event="updateSkin")]
                private function deleteToolTipText():String {
                        var entity:Entity=controller.state.firstSelected;
-                       if (entity is Node) { return "Delete Node (Delete)"; }
-                       if (entity is Way && Way(entity).isArea()) { return "Delete Area (Shift+Delete)"; }
-                       if (entity is Way) { return "Delete Way (Shift+Delete)"; }
-                       return "Delete Item"; // When nothing is selected
+                       if (entity is Node) { return deleteNode; }
+                       if (entity is Way && Way(entity).isArea()) { return deleteArea; }
+                       if (entity is Way) { return deleteWay; }
+                       return deleteItem; // When nothing is selected
                }
 
         private function updateDirectionArrow():void {
                         w.clockwise? rotateButtonStack.selectedChild = antiClockwiseBox : rotateButtonStack.selectedChild = clockwiseBox;
                     } else {
                         rotateButtonStack.selectedChild = arrowBoxWrapper;
-                        // reset and reposition back to the starting point relative to its parent
-                        rotate.end();
-                        angle = 0;
-                        rotate.play();
-                        arrowBox.x = 0;
-                        arrowBox.y = 0;
-
-                        // move
-                        rotate.end();
-                        angle = w.angle;
-                        rotate.play();
+                        arrow.iconDisplay.rotation=w.angle;
+                                               arrow.iconDisplay.smooth=true;
                     }
                 }
             }
         }
 
+               private function updateMergeIcon():void {
+                       var multi:Object=controller.state.multipolygonMembers();
+                       if (multi.outer) {
+                               mergeButton.setStyle("icon",multipolygonIcon);
+                               mergeButton.alpha=1;
+                               mergeButton.enabled=true;
+                       } else if (controller.state.hasAdjoiningWays()) {
+                               mergeButton.setStyle("icon",mergeIcon);
+                               mergeButton.alpha=1;
+                               mergeButton.enabled=true;
+                       } else {
+                               mergeButton.setStyle("icon",mergeIcon);
+                               mergeButton.alpha=0.5;
+                               mergeButton.enabled=false;
+                       }
+               }
+
         private function reverseClicked():void {
             if(canDo('reverseDirection')) {
                 doReverseDirection();
                // --------------------------------------------------------------------------------
                // Individual toolbox actions
 
-               public function doDelete():void {
+               public function doDelete(controlKey:Boolean,shiftKey:Boolean):void {
                        var undo:CompositeUndoableAction = new CompositeUndoableAction("Delete objects");
-                       for each (var entity:Entity in controller.state.selection) {
-                               if (entity is Node) { controller.connection.unregisterPOI(Node(entity)); }
-                               entity.remove(undo.push);
-                       }
-                       MainUndoStack.getGlobalStack().addAction(undo);
-
-                       if (controller.state is SelectedWayNode) {
-                               controller.setState(new SelectedWay(SelectedWayNode(controller.state).selectedWay));
-                       } else {
+                       if (controlKey) {
+                               // Temporary function to delete everything with non-accepting status
+                               var conn:Connection=controller.state.selection[0].connection;
+                               var o:Object=conn.getObjectsByBbox(controller.map.edge_l, controller.map.edge_r, controller.map.edge_t, controller.map.edge_b);
+                               for each (var way:Way in o.waysInside) {
+                                       if (way.status=='no' || (shiftKey && way.status=='partial')) { way.remove(undo.push); }
+                               }
+                               for each (var poi:Node in o.poisInside) {
+                                       if (poi.status=='no' || (shiftKey && way.status=='partial')) { poi.connection.unregisterPOI(poi); poi.remove(undo.push); }
+                               }
+                               MainUndoStack.getGlobalStack().addAction(undo);
                                controller.setState(new NoSelection());
+                               
+                       } else {
+                               // Standard delete function
+                               for each (var entity:Entity in controller.state.selection) {
+                                       if (entity is Node) { entity.connection.unregisterPOI(Node(entity)); }
+                                       entity.remove(undo.push);
+                               }
+                               MainUndoStack.getGlobalStack().addAction(undo);
+
+                               if (controller.state is SelectedWayNode) {
+                                       controller.setState(new SelectedWay(SelectedWayNode(controller.state).selectedWay));
+                               } else {
+                                       controller.setState(new NoSelection());
+                               }
                        }
                }
                
                public function doMerge():void {
-                       controller.setState(SelectedMultiple(controller.state).mergeWays());
+                       var multi:Object=controller.state.multipolygonMembers();
+                       if (multi.outer) {
+                               controller.setState(SelectedMultiple(controller.state).createMultipolygon());
+                       } else {
+                               controller.setState(SelectedMultiple(controller.state).mergeWays());
+                       }
                }
 
                public function doReverseDirection():void {
 
 
        ]]>
-</mx:Script>   
+</fx:Script>
 </mx:Panel>