flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [5/6] git commit: [flex-utilities] [refs/heads/develop] - add Input task
Date Wed, 11 Dec 2013 20:58:05 GMT
add Input task


Project: http://git-wip-us.apache.org/repos/asf/flex-utilities/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-utilities/commit/d7933af2
Tree: http://git-wip-us.apache.org/repos/asf/flex-utilities/tree/d7933af2
Diff: http://git-wip-us.apache.org/repos/asf/flex-utilities/diff/d7933af2

Branch: refs/heads/develop
Commit: d7933af2723fa2b0f4f1e45adec1c2a848c6d3c7
Parents: 0c642f5
Author: Alex Harui <aharui@apache.org>
Authored: Wed Dec 11 12:54:48 2013 -0800
Committer: Alex Harui <aharui@apache.org>
Committed: Wed Dec 11 12:54:48 2013 -0800

----------------------------------------------------------------------
 ant_on_air/src/AntClasses.as                    |  1 +
 .../src/org/apache/flex/ant/tags/Input.as       | 92 ++++++++++++++++++++
 ant_on_air/tests/AntTest.mxml                   |  9 ++
 ant_on_air/tests/test.xml                       |  8 ++
 4 files changed, 110 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/d7933af2/ant_on_air/src/AntClasses.as
----------------------------------------------------------------------
diff --git a/ant_on_air/src/AntClasses.as b/ant_on_air/src/AntClasses.as
index cd4a0f2..12e0c98 100644
--- a/ant_on_air/src/AntClasses.as
+++ b/ant_on_air/src/AntClasses.as
@@ -36,6 +36,7 @@ package
             import org.apache.flex.ant.tags.FileSetExclude; FileSetExclude;
             import org.apache.flex.ant.tags.FileSetInclude; FileSetInclude;
             import org.apache.flex.ant.tags.Get; Get;
+            import org.apache.flex.ant.tags.Input; Input;
             import org.apache.flex.ant.tags.IsSet; IsSet;
             import org.apache.flex.ant.tags.LoadProperties; LoadProperties;
             import org.apache.flex.ant.tags.Mkdir; Mkdir;

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/d7933af2/ant_on_air/src/org/apache/flex/ant/tags/Input.as
----------------------------------------------------------------------
diff --git a/ant_on_air/src/org/apache/flex/ant/tags/Input.as b/ant_on_air/src/org/apache/flex/ant/tags/Input.as
new file mode 100644
index 0000000..52210f2
--- /dev/null
+++ b/ant_on_air/src/org/apache/flex/ant/tags/Input.as
@@ -0,0 +1,92 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.ant.tags
+{
+    import flash.events.Event;
+    import flash.events.KeyboardEvent;
+    import flash.ui.Keyboard;
+    
+    import mx.core.IFlexModuleFactory;
+    
+    import org.apache.flex.ant.Ant;
+    import org.apache.flex.ant.tags.supportClasses.TaskHandler;
+    
+    [Mixin]
+    public class Input extends TaskHandler
+    {
+        public static function init(mf:IFlexModuleFactory):void
+        {
+            Ant.antTagProcessors["input"] = Input;
+        }
+
+        public function Input()
+        {
+            super();
+        }
+        
+        private var text:String;
+        private var validArgs:Array;
+        private var property:String;
+        private var defaultValue:String;
+        
+        override protected function processAttribute(name:String, value:String):void
+        {
+            if (name == "message")
+                text = value;
+            else if (name == "validargs")
+                validArgs = value.split("");
+            else if (name == "addproperty")
+                property = value;
+            else if (name == "defaultvalue")
+                defaultValue = value;
+            else
+                super.processAttribute(name, value);
+        }
+
+        override public function execute(callbackMode:Boolean):Boolean
+        {
+            super.execute(callbackMode);
+            if (text)
+                ant.output(ant.getValue(text, context));
+            if (validArgs)
+                ant.output("[" + validArgs + "]");
+            ant.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
+            return false;
+        }
+        
+        // consumer should re-dispatch keyboard events from ant instance
+        private function keyDownHandler(event:KeyboardEvent):void
+        {
+            var val:String;
+            
+            if (validArgs == null && event.keyCode == Keyboard.ENTER)
+                val = defaultValue;
+            else if (validArgs.indexOf(String.fromCharCode(event.charCode)) != -1)
+                val = String.fromCharCode(event.charCode);
+            
+            if (val != null)
+            {
+                ant.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
+                if (!context.hasOwnProperty(property))
+                    context[property] = val;
+                dispatchEvent(new Event(Event.COMPLETE));
+            }
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/d7933af2/ant_on_air/tests/AntTest.mxml
----------------------------------------------------------------------
diff --git a/ant_on_air/tests/AntTest.mxml b/ant_on_air/tests/AntTest.mxml
index 6d42812..670ccf4 100644
--- a/ant_on_air/tests/AntTest.mxml
+++ b/ant_on_air/tests/AntTest.mxml
@@ -50,6 +50,8 @@ limitations under the License.
                 ant = new Ant();
                 ant.output = output;
                 var context:Object = { targets: "test" };
+                if (exitwhendone)
+                    context["exitwhendone"] = true;
                 var file:File = File.applicationDirectory;
                 file = file.resolvePath("test.xml");
                 addEventListener(Event.ENTER_FRAME, enterFrameHandler);
@@ -57,6 +59,8 @@ limitations under the License.
                 {
                     ant.addEventListener(Event.COMPLETE, completeHandler);
                     ant.addEventListener(ProgressEvent.PROGRESS, progressEventHandler);
+                    // redispatch keyboard events off of ant so input task can see them
+                    systemManager.stage.addEventListener(KeyboardEvent.KEY_DOWN, ant_keyDownHandler);
                     pb.source = ant;
                 }
                 else
@@ -107,6 +111,11 @@ limitations under the License.
             {
                 ant.doCallback();
             }
+            
+            private function ant_keyDownHandler(event:KeyboardEvent):void
+            {
+                ant.dispatchEvent(event);
+            }
         ]]>
     </fx:Script>
     <s:layout>

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/d7933af2/ant_on_air/tests/test.xml
----------------------------------------------------------------------
diff --git a/ant_on_air/tests/test.xml b/ant_on_air/tests/test.xml
index 82a8089..413f911 100644
--- a/ant_on_air/tests/test.xml
+++ b/ant_on_air/tests/test.xml
@@ -170,6 +170,14 @@
                 <equals arg1="${replacedkey1}" arg2="somevalue1" />
             </condition>
         </fail>
+        <input message="Ok to delete temp directory?" unless="exitwhendone"
+            validargs="yn"
+            addproperty="oktodelete" />
+        <fail message="you were supposed to hit 'y'" >
+            <condition>
+                <equals arg1="n" arg2="${oktodelete}" />
+            </condition>
+        </fail>
         <delete dir="${basedir}/temp" />
         <available file="${basedir}/temp/org/apache/flex/ant/tags/Project.as" property="project.doesnt.exist.after.delete"
value="didn't get deleted" />
         <fail message="temp/copied.xml was not deleted">


Mime
View raw message