Merge branch 'master' into history
[potlatch2.git] / net / systemeD / potlatch2 / EditController.as
index f70cc21..5cb00fb 100644 (file)
@@ -15,6 +15,7 @@ package net.systemeD.potlatch2 {
        import flash.ui.Keyboard;
        import flash.ui.Mouse;
        import flash.ui.MouseCursorData;
+       import flash.system.Capabilities;
        import flash.text.TextField;
     import mx.controls.TextArea;
 
@@ -29,7 +30,12 @@ package net.systemeD.potlatch2 {
         /** The current ControllerState */
         public var state:ControllerState;
         
+               /** Hash of when a key was pressed. A user can keyDown within a TextInput, press Enter (leaving
+                   the TextInput), and then keyup - resulting in the keypress being interpreted again. 
+                   We prevent this by tracking keyDowns within the TextInput and ignoring corresponding keyUps. */
                private var keys:Object={};
+
+               public var spaceHeld:Boolean=false;
                public var clipboards:Object={};
                public var cursorsEnabled:Boolean=true;
         private var maximised:Boolean=false;
@@ -68,11 +74,13 @@ package net.systemeD.potlatch2 {
                 map.addEventListener(MapEvent.MOVE, moveHandler);
             }
 
-                       createBitmapCursor("pen"     ,new pen());
-                       createBitmapCursor("pen_x"   ,new pen_x());
-                       createBitmapCursor("pen_o"   ,new pen_o());
-                       createBitmapCursor("pen_so"  ,new pen_so());
-                       createBitmapCursor("pen_plus",new pen_plus());
+                       if (supportsMouseCursors()) {
+                               createBitmapCursor("pen"     ,new pen());
+                               createBitmapCursor("pen_x"   ,new pen_x());
+                               createBitmapCursor("pen_o"   ,new pen_o());
+                               createBitmapCursor("pen_so"  ,new pen_so());
+                               createBitmapCursor("pen_plus",new pen_plus());
+                       }
         }
 
         public function setActive():void {
@@ -100,14 +108,19 @@ package net.systemeD.potlatch2 {
                }
         
         private function keyDownHandler(event:KeyboardEvent):void {
-                       if ((event.target is TextField) || (event.target is TextArea)) return;
-                       keys[event.keyCode]=true;
+                       if ((event.target is TextField) || (event.target is TextArea)) {
+                               keys[event.keyCode]=new Date().getTime();
+                               return;
+                       }
+                       delete keys[event.keyCode];
+                       if (event.keyCode==Keyboard.SPACE) spaceHeld=true;
                }
 
         private function keyUpHandler(event:KeyboardEvent):void {
-            if (!keys[event.keyCode]) return;
-            delete keys[event.keyCode];
-            if ((event.target is TextField) || (event.target is TextArea)) return;                             // not meant for us
+                       if ((event.target is TextField) || (event.target is TextArea)) return;
+                       if (event.keyCode==Keyboard.SPACE) spaceHeld=false;
+                       if (keys[event.keyCode] && new Date().getTime()-keys[event.keyCode]<300) return;
+                       delete keys[event.keyCode];
 
                        if (FunctionKeyManager.instance().handleKeypress(event.keyCode)) { return; }
             
@@ -116,11 +129,6 @@ package net.systemeD.potlatch2 {
             setState(newState);            
                }
 
-               /** Is the given key currently pressed? */
-               public function keyDown(key:Number):Boolean {
-                       return Boolean(keys[key]);
-               }
-
         private function mapMouseEvent(event:MouseEvent):void {
             if (isInteractionEvent(event)) map.stage.focus = map.parent;
             if (event.type==MouseEvent.MOUSE_UP && map.dragstate==map.DRAGGING) { return; }
@@ -188,7 +196,7 @@ package net.systemeD.potlatch2 {
 
                /** Set a mouse pointer. */
                public function setCursor(name:String=""):void {
-                       if (name && cursorsEnabled) { Mouse.cursor=name; }
+                       if (name && cursorsEnabled && supportsMouseCursors()) { Mouse.cursor=name; }
                        else { Mouse.cursor=flash.ui.MouseCursor.AUTO; }
                }
 
@@ -201,6 +209,12 @@ package net.systemeD.potlatch2 {
                        Mouse.registerCursor(name, cursorData);
                }
 
+               private function supportsMouseCursors():Boolean {
+                       var fpArray:Array=Capabilities.version.split(",");
+                       var fpVersion:Number=Number(fpArray[0].split(" ")[1])+Number(fpArray[1])/10;
+                       return (fpVersion>10.1);
+               }
+
         private function toggleSize():void {
             if (maximised) {
                 if (minimiseFunction) {