update toolbox icons depending on what's selected (and add the useful W keypress)
authorRichard Fairhurst <richard@systemed.net>
Sun, 6 Jun 2010 18:21:13 +0000 (18:21 +0000)
committerRichard Fairhurst <richard@systemed.net>
Sun, 6 Jun 2010 18:21:13 +0000 (18:21 +0000)
TODO.txt
net/systemeD/halcyon/MapEvent.as
net/systemeD/potlatch2/Toolbox.as
net/systemeD/potlatch2/controller/ControllerState.as
potlatch2.mxml

index cc8d728c9d998b3d765ef9eff7fe688d791c69fb..90b99a30c1b8f552fba285ff950685bd29be0467 100644 (file)
--- a/TODO.txt
+++ b/TODO.txt
@@ -57,7 +57,6 @@ Potlatch 2: main outstanding issues
 * Background imagery layers should match those of p1
 * Dialog for adding custom imagery url
 * Draggin a node under the toolbox and then mouseuping doesn't get passed to the map, so you end up with a node "stuck" to the pointer
-* Toolbox icons should be deactivated when not in correct state
 
 == Miscellaneous data model ==
 
index 9492b2eb61738b6edbaa9ec2839b95b393c358f4..078554a47a2ceed3b8bf7e4a134cb0cc03cfc752 100644 (file)
@@ -7,7 +7,6 @@ package net.systemeD.halcyon {
                public static const DOWNLOAD:String = "download";
                public static const RESIZE:String = "resize";
                public static const MOVE:String = "move";
-               public static const CLICK:String = "click";
                public static const NUDGE_BACKGROUND:String = "nudge_background";
 
                public var params:Object;
index d4de447bc5beee866f7aa85e8877214a29a060b3..5f9a2aa94e330c20f10ff58afad758756c04d2e9 100644 (file)
@@ -14,7 +14,6 @@ package net.systemeD.potlatch2 {
                ** Should have a close box, and be able to be activated from the top bar
                ** Should be automatically positioned at bottom-right of canvas on init
                ** Should float above tagViewer, not beneath it
-               ** Icons should be disabled depending on what's selected (setEntity can do this)
                ** Remove annoying Illustrator cruft from SVG icons!
                ** Tooltips
 
@@ -41,6 +40,8 @@ package net.systemeD.potlatch2 {
 
                public function setEntity(entity:Entity):void {
                        this.entity=entity;
+                       dispatchEvent(new Event("updateSkin"));
+                       dispatchEvent(new Event("updateAlpha"));
                }
 
                private function handleDown(e:Event):void {
@@ -50,6 +51,32 @@ package net.systemeD.potlatch2 {
                private function handleUp(e:Event):void {
                        this.stopDrag();
                }
+               
+               // --------------------------------------------------------------------------------
+               // Enable/disable toolbox buttons
+               // (ideally we'd use CSS to set alpha in disabled state, but Flex's CSS
+               //  capabilities aren't up to it)
+               
+        [Bindable(event="updateSkin")]
+               public function canDo(op:String):Boolean {
+                       switch (op) {
+                               case 'delete':                          return (entity is Way || entity is Node);
+                               case 'reverseDirection':        return (entity is Way);
+                               case 'quadrilateralise':        return (entity is Way && Way(entity).isArea());
+                               case 'straighten':                      return (entity is Way && !Way(entity).isArea());
+                               case 'circularise':                     return (entity is Way && Way(entity).isArea());
+                               case 'split':                           return (entity is Node && controller.state is SelectedWayNode);
+                               case 'parallelise':                     return (entity is Way);
+                       }
+                       return false;
+               }
+
+        [Bindable(event="updateAlpha")]
+               public function getAlpha(op:String):Number {
+                       if (canDo(op)) { return 1; }
+                       return 0.5;
+               }
+        
 
                // --------------------------------------------------------------------------------
                // Individual toolbox actions
@@ -64,7 +91,7 @@ package net.systemeD.potlatch2 {
                                controller.setState(new NoSelection());
                        }
                }
-        
+
         public function doReverseDirection():void {
             if (entity is Way) { 
                 Way(entity).reverseNodes(MainUndoStack.getGlobalStack().addAction);
@@ -88,7 +115,7 @@ package net.systemeD.potlatch2 {
                                Circularise.circularise(Way(entity),controller.map);
                        }
                }
-               
+
                public function doSplit():void {
                        if (entity is Node && controller.state is SelectedWayNode) {
                                controller.setState(SelectedWayNode(controller.state).splitWay());
index 840508cb62a464e7d65a30300b921b049b149802..67f6572893f152cc2afb1642abeb13dee31d46a9 100644 (file)
@@ -48,6 +48,7 @@ package net.systemeD.potlatch2.controller {
                protected function sharedKeyboardEvents(event:KeyboardEvent):ControllerState {
                        switch (event.keyCode) {
                                case 68:        controller.map.paint.alpha=1.3-controller.map.paint.alpha; return null; // D
+                               case 87:        if (selectedWay) { return new SelectedWay(selectedWay); }; return null; // W
                                case 90:        MainUndoStack.getGlobalStack().undo(); return null;                                             // Z
                        }
                        return null;
index 530661a7806d7d5a60dff1d207863630d2e6974a..d4b257cad2fcf295701ae6801a05dcc7722ef46f 100755 (executable)
 
                <mx:Button icon="@Embed('embedded/delete.svg')"
                                click='toolbox.doDelete();' 
+                               enabled="{toolbox.canDo('delete')}" 
+                               alpha="{toolbox.getAlpha('delete')}" 
                                width="28" height="28" textAlign="left" paddingLeft="6" paddingRight="0" />
                <mx:Button icon="@Embed('embedded/direction.svg')" 
                 click='toolbox.doReverseDirection();'
+                               enabled="{toolbox.canDo('reverseDirection')}" 
+                               alpha="{toolbox.getAlpha('reverseDirection')}" 
                                width="28" height="28" textAlign="left" paddingLeft="8" paddingRight="0" />
                <mx:Button icon="@Embed('embedded/cut.svg')" 
                 click='toolbox.doSplit();'
+                               enabled="{toolbox.canDo('split')}" 
+                               alpha="{toolbox.getAlpha('split')}" 
                                width="28" height="28" textAlign="left" paddingLeft="8" paddingRight="0" />
                <mx:Button icon="@Embed('embedded/straighten.svg')" 
                                click='toolbox.doStraighten();' 
+                               enabled="{toolbox.canDo('straighten')}" 
+                               alpha="{toolbox.getAlpha('straighten')}" 
                                width="28" height="28" textAlign="left" paddingLeft="5" paddingRight="0" />
                <mx:Button icon="@Embed('embedded/circle.svg')" 
                                click='toolbox.doCircularise();' 
+                               enabled="{toolbox.canDo('circularise')}" 
+                               alpha="{toolbox.getAlpha('circularise')}" 
                                width="28" height="28" textAlign="left" paddingLeft="4" paddingRight="0" />
                <mx:Button icon="@Embed('embedded/quadrilateralise.svg')" 
                                click='toolbox.doQuadrilateralise();' 
+                               enabled="{toolbox.canDo('quadrilateralise')}" 
+                               alpha="{toolbox.getAlpha('quadrilateralise')}" 
                                width="28" height="28" textAlign="left" paddingLeft="6" paddingRight="0" />
                <mx:Button icon="@Embed('embedded/parallel.svg')" 
                                click='toolbox.doParallelise();' 
+                               enabled="{toolbox.canDo('parallelise')}" 
+                               alpha="{toolbox.getAlpha('parallelise')}" 
                                width="28" height="28" textAlign="left" paddingLeft="8" paddingRight="0" />
 
                </potlatch2:Toolbox>