Block keypresses when there's a dialogue on-screen
authorRichard Fairhurst <richard@systemeD.net>
Fri, 24 Mar 2017 16:18:27 +0000 (16:18 +0000)
committerRichard Fairhurst <richard@systemeD.net>
Fri, 24 Mar 2017 16:18:27 +0000 (16:18 +0000)
net/systemeD/potlatch2/FloatingMap.mxml
net/systemeD/potlatch2/TasksPalette.mxml
net/systemeD/potlatch2/Toolbox.mxml
net/systemeD/potlatch2/controller/ControllerState.as

index 32debad..d5b0e74 100644 (file)
@@ -38,6 +38,7 @@
        [Bindable] private var zoomLocked:Boolean=false;
        private var maxZoom:uint=50;
        private var crosshair:Sprite=new Sprite();
+       public var allowControllerKeyboardEvents:Boolean = true;
 
        /* FloatingMap still to do:
                - selection UI
index abb3ccb..d74dad0 100644 (file)
@@ -38,6 +38,7 @@
                private var controller:EditController;
                private var tasks:Array;                                // array of { lat:.., lon:.., text:.. }
                private var taskNumber:uint=0;
+               public var allowControllerKeyboardEvents:Boolean = true;
 
                public function init(controller:EditController):void {
                        this.controller=controller;
index 05ca0bd..eb7e891 100644 (file)
         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
+               public var allowControllerKeyboardEvents:Boolean = true;
 
        [Bindable] [Embed(source="../../../embedded/merge.svg"       )] private var mergeIcon:Class;
        [Bindable] [Embed(source="../../../embedded/multipolygon.svg")] private var multipolygonIcon:Class;
index 7d6d6b2..3a7f5dd 100644 (file)
@@ -17,6 +17,8 @@ package net.systemeD.potlatch2.controller {
        import mx.controls.Alert;
        import mx.events.CloseEvent;
        import mx.core.FlexGlobals;
+       import mx.core.IChildList;
+       import mx.core.UIComponent;
        
     /** Represents a particular state of the controller, such as "dragging a way" or "nothing selected". Key methods are 
     * processKeyboardEvent and processMouseEvent which take some action, and return a new state for the controller. 
@@ -81,6 +83,7 @@ package net.systemeD.potlatch2.controller {
 
                /** Default behaviour for the current state that should be called if state-specific action has been taken care of or ruled out. */
                protected function sharedKeyboardEvents(event:KeyboardEvent):ControllerState {
+                       if (popupsAreOpen()) { return null; }
                        var editableLayer:MapPaint=controller.map.editableLayer;                                                                // shorthand for this method
                        if (event.keyCode>=112 && event.keyCode<=126 && event.shiftKey) { memoriseTags(event.keyCode); return null; }
                        switch (event.keyCode) {
@@ -103,6 +106,17 @@ package net.systemeD.potlatch2.controller {
                        return null;
                }
 
+               protected function popupsAreOpen():Boolean {
+                       var rawChildren:IChildList = FlexGlobals.topLevelApplication.systemManager.rawChildren;
+                       for (var i: int = 0; i < rawChildren.numChildren; i++) {
+                               var currRawChild:DisplayObject = rawChildren.getChildAt(i);
+                               if ((currRawChild is UIComponent) && UIComponent(currRawChild).isPopUp && UIComponent(currRawChild).visible) {
+                                       if (!('allowControllerKeyboardEvents' in currRawChild)) { return true; }
+                               }
+                       }
+                       return false;
+               }
+
                /** Default behaviour for the current state that should be called if state-specific action has been taken care of or ruled out. */
                protected function sharedMouseEvents(event:MouseEvent, entity:Entity):ControllerState {
                        var paint:MapPaint = getMapPaint(DisplayObject(event.target));