This is an automated email from the ASF dual-hosted git repository.

aharui pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new e172956  search for class
e172956 is described below

commit e17295637abe289bc2c4ab1fc9374985337edbca
Author: Alex Harui <[email protected]>
AuthorDate: Tue Feb 6 00:20:43 2018 -0800

    search for class
---
 .../ASDoc/src/main/royale/ASDocMainView.mxml       | 62 ++++++++++++++++-
 .../ClassPickerHashAnchorStringItemRenderer.as     | 77 ++++++++++++++++++++++
 .../ASDoc/src/main/royale/models/ASDocModel.as     |  5 ++
 3 files changed, 143 insertions(+), 1 deletion(-)

diff --git a/examples/royale/ASDoc/src/main/royale/ASDocMainView.mxml 
b/examples/royale/ASDoc/src/main/royale/ASDocMainView.mxml
index 7fd291a..c565367 100644
--- a/examples/royale/ASDoc/src/main/royale/ASDocMainView.mxml
+++ b/examples/royale/ASDoc/src/main/royale/ASDocMainView.mxml
@@ -27,8 +27,11 @@ limitations under the License.
     <fx:Script>
         <![CDATA[
                        import models.ASDocModel;
+            import org.apache.royale.core.ClassFactory;
             import org.apache.royale.events.Event;
             import org.apache.royale.events.DetailEvent;
+            import org.apache.royale.html.List;
+            import org.apache.royale.utils.PointUtils;
                        
             private function packagesReadyHandler(event:Event):void
             {
@@ -73,6 +76,12 @@ limitations under the License.
             
             private function updateView():void
             {
+               if (popUpList)
+               {
+                       removeElement(popUpList);
+                       popUpList = null;
+                       searchTI.text = "";
+               }
                var hash:String = router.hash;
                if (hash.substr(0,2) == "#!")
                  hash = hash.substring(2);
@@ -130,6 +139,45 @@ limitations under the License.
                        document.getElementById(findMember).scrollIntoView();
                }
             }
+            
+            private var popUpList:List;
+            private var max_results:int = 200;
+            private var too_many:Array = [ "Too many search results" ];
+            
+            private function search():void
+            {
+               if (!popUpList)
+               {
+                       popUpList = new List();
+                       popUpList.itemRenderer = new 
ClassFactory(ClassPickerHashAnchorStringItemRenderer);
+                       popUpList.dataProvider = too_many;
+                       addElement(popUpList);
+                       COMPILE::JS
+                       {
+                               popUpList.positioner.style.position = 
"absolute";
+                               popUpList.positioner.style.backgroundColor = 
"#fff";
+                       }
+                       var pt:Point = new Point(searchTI.x, searchTI.y);
+                       pt.y += searchTI.height;
+                       //pt = PointUtils.localToGlobal(pt, titleGroup); // 
probably need this after we fix x,y
+                       popUpList.x = pt.x;
+                       popUpList.y = pt.y;
+                       popUpList.width = searchTI.width;
+                       popUpList.height = 200;
+               }
+               var arr:Array = (applicationModel as 
ASDocModel).allClasses.filter(filterClasses, this);
+               if (arr.length < max_results)
+                       popUpList.dataProvider = arr;
+                   else
+                       popUpList.dataProvider = too_many;
+            }
+            
+            private function filterClasses(item:String):Boolean
+            {
+               var regex:RegExp = new RegExp(searchTI.text);
+               return regex.test(item);
+            }
+            
                ]]>
     </fx:Script>
        <fx:Style>
@@ -286,6 +334,14 @@ limitations under the License.
             margin-top: 3px;
         }
         
+        .findClassLabel {
+               padding-right: 3px;
+        }
+        
+        .searchTI {
+               width: 300px;
+        }
+        
        </fx:Style>
        <fx:Declarations>
                <fx:Component className="AltBGRenderer">
@@ -306,9 +362,13 @@ limitations under the License.
     <rs:DocTagline />
     <js:Group width="100%" id="titleGroup" className="titleGroup">
         <js:beads>
-            <js:OneFlexibleChildHorizontalLayoutForOverflow 
flexibleChild="title" />
+            <js:OneFlexibleChildHorizontalLayoutForOverflow 
flexibleChild="spacer" />
         </js:beads>
         <js:Label text="Apache Royale ActionScript Library Reference" 
id="title" height="30" className="title"/>
+        <js:Spacer width="20" />
+        <js:Label text="Find a class" className="findClassLabel"/>
+        <js:TextInput id="searchTI" className="searchTI" change="search()" />
+        <js:Spacer id="spacer" />
         <js:CheckBox id="topLevel" text="Top-Level" click="showTopLevel()" />
         <js:CheckBox id="viewBeads" text="View Bead" click="showViewBeads()" />
     </js:Group>
diff --git 
a/examples/royale/ASDoc/src/main/royale/ClassPickerHashAnchorStringItemRenderer.as
 
b/examples/royale/ASDoc/src/main/royale/ClassPickerHashAnchorStringItemRenderer.as
new file mode 100644
index 0000000..64b4d45
--- /dev/null
+++ 
b/examples/royale/ASDoc/src/main/royale/ClassPickerHashAnchorStringItemRenderer.as
@@ -0,0 +1,77 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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
+{
+import  org.apache.royale.html.supportClasses.StringItemRenderer;
+
+       /**
+        *  The HashAnchorStringItemRenderer class displays data in string form 
using the data's toString()
+        *  function.  It assumes the data is an encoding of class, package or 
function name and
+        *  sets up the renderer so the controller logic will open the right 
document.  On JS, by
+        *  using anchor tags, it should allow the browser to dictate 
permalinks and allow
+        *  search engines to crawl the app.
+        *
+        *  @langversion 3.0
+        *  @playerversion Flash 10.2
+        *  @playerversion AIR 2.6
+        *  @productversion Royale 0.0
+        */
+       public class ClassPickerHashAnchorStringItemRenderer extends 
StringItemRenderer
+       {
+               /**
+                *  constructor.
+                *
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion Royale 0.0
+                */
+               public function ClassPickerHashAnchorStringItemRenderer()
+               {
+                       typeNames += " HashAnchorStringItemRenderer"
+               }
+
+               override public function set text(value:String):void
+               {
+            COMPILE::SWF
+            {
+                textField.text = value;
+            }
+            COMPILE::JS
+            {
+               var pkg:String = "";
+               var cname:String = value;
+               var href:String = value;
+               var c:int = href.lastIndexOf(".");
+               if (c != -1)
+               {
+                       pkg = href.substr(0, c);
+                       cname = href.substr(c+1);
+                       href = pkg + "/" + cname;
+               }
+               else
+               {
+                       href = "/" + cname;
+               } 
+                this.element.innerHTML = "<a href='#!" + href + "' 
class='HashAnchorAnchor'>" + value + "</a>";
+            }
+               }
+
+       }
+}
diff --git a/examples/royale/ASDoc/src/main/royale/models/ASDocModel.as 
b/examples/royale/ASDoc/src/main/royale/models/ASDocModel.as
index 0e1381b..0815385 100644
--- a/examples/royale/ASDoc/src/main/royale/models/ASDocModel.as
+++ b/examples/royale/ASDoc/src/main/royale/models/ASDocModel.as
@@ -79,6 +79,11 @@ package models
         
         private var masterData:Object;
         
+        public function get allClasses():Array
+        {
+               return masterData.classnames;
+        }
+        
         private function completeHandler(event:Event):void
         {
             app.service.removeEventListener("complete", completeHandler);

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to