Retain preferences even when .swf filename has changed
[potlatch2.git] / net / systemeD / potlatch2 / Toolbox.mxml
index 7b26585..1826e26 100644 (file)
@@ -1,6 +1,8 @@
 <?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">
 
                <!-- 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:Button icon="@Embed('../../../embedded/direction.svg')" 
-                       click='doReverseDirection();'
-                       enabled="{canDo('reverseDirection')}" 
-                       alpha="{getAlpha('reverseDirection')}" 
-                       toolTip="Reverse direction (V)" 
-                       width="28" height="28" textAlign="left" y="4" x="36" paddingLeft="8" paddingRight="0" />
-               <mx:Button icon="@Embed('../../../embedded/cut.svg')" 
+                       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">
+                    <s:Button id="clockwise" icon="@Embed('../../../embedded/clockwise.svg')"
+                        alpha="{getAlpha('reverseDirection')}"
+                        width="28" height="28" click="reverseClicked();" />
+                </mx:HBox>
+                <mx:HBox id="antiClockwiseBox" horizontalAlign="center" verticalAlign="middle">
+                    <s:Button id="anticlockwise" icon="@Embed('../../../embedded/anti-clockwise.svg')"
+                        enabled="{canDo('reverseDirection')}"
+                        alpha="{getAlpha('reverseDirection')}"
+                        width="28" height="28" click="reverseClicked();" />
+                </mx:HBox>
+            </mx:ViewStack>
+        </mx:HBox>
+               <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" 
-                       width="28" height="28" textAlign="left" y="34" x="66" paddingLeft="6" paddingRight="0" />
-               <mx:Button icon="@Embed('../../../embedded/parallel.svg')" 
+                       toolTip="Make right-angled (Q)"
+                       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 {
+            if (controller.state is SelectedWay) {
+                var w:Way = Way(controller.state.firstSelected);
+                if (w) { // not entirely sure why this protection is necessary, but it appears so
+                    if (w.isArea()) {
+                        // so Way.clockwise appears to give wrong results. Patches welcome, I guess, but for now...
+                        w.clockwise? rotateButtonStack.selectedChild = antiClockwiseBox : rotateButtonStack.selectedChild = clockwiseBox;
+                    } else {
+                        rotateButtonStack.selectedChild = arrowBoxWrapper;
+                        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 {
-                       var changed:Boolean;
-                       var waylist:Array=controller.state.selectedWays;
-                       do {
-                               // ** FIXME - we should have one CompositeUndoableAction for the whole caboodle,
-                               // but that screws up the execution order and can make the merge not work
-                               var undo:CompositeUndoableAction = new CompositeUndoableAction("Merge ways");
-                               changed=tryMerge(waylist, undo);
-                               MainUndoStack.getGlobalStack().addAction(undo);
-                       } while (changed==true);
-                       controller.setState(controller.findStateForSelection(waylist));
-               }
-               
-               private function tryMerge(waylist:Array, undo:CompositeUndoableAction):Boolean {
-                       var way1:Way, way2:Way, del:uint;
-                       for (var i:uint=0; i<waylist.length; i++) {
-                               for (var j:uint=0; j<waylist.length; j++) {
-                                       if (waylist[i]!=waylist[j]) {
-
-                                               // Preserve positive IDs if we can
-                                               if (waylist[i].id < waylist[j].id && waylist[i].id >= 0) {
-                                                       way1=waylist[i]; way2=waylist[j]; del=j;
-                                               } else {
-                                                       way1=waylist[j]; way2=waylist[i]; del=i;
-                                               }
-
-                                               // Merge as appropriate
-                                               if (way1.getNode(0)==way2.getNode(0)) {
-                                                       waylist.splice(del,1);
-                                                       undo.push(new MergeWaysAction(way1,way2,0,0));
-                                                       return true;
-                                               } else if (way1.getNode(0)==way2.getLastNode()) { 
-                                                       waylist.splice(del,1);
-                                                       undo.push(new MergeWaysAction(way1,way2,0,way2.length-1));
-                                                       return true;
-                                               } else if (way1.getLastNode()==way2.getNode(0)) {
-                                                       waylist.splice(del,1);
-                                                       undo.push(new MergeWaysAction(way1,way2,way1.length-1,0));
-                                                       return true;
-                                               } else if (way1.getLastNode()==way2.getLastNode()) { 
-                                                       waylist.splice(del,1);
-                                                       undo.push(new MergeWaysAction(way1,way2,way1.length-1,way2.length-1));
-                                                       return true;
-                                               }
-                                       }
-                               }
+                       var multi:Object=controller.state.multipolygonMembers();
+                       if (multi.outer) {
+                               controller.setState(SelectedMultiple(controller.state).createMultipolygon());
+                       } else {
+                               controller.setState(SelectedMultiple(controller.state).mergeWays());
                        }
-                       return false;
                }
 
                public function doReverseDirection():void {
 
 
        ]]>
-</mx:Script>   
+</fx:Script>
 </mx:Panel>