Revision: 3797
          http://vexi.svn.sourceforge.net/vexi/?rev=3797&view=rev
Author:   jeffbuhrt
Date:     2010-02-10 02:59:37 +0000 (Wed, 10 Feb 2010)

Log Message:
-----------
sort demo menu items

Modified Paths:
--------------
    trunk/widgets/org.vexi.demo/src/org/vexi/demo/demomenus.t

Modified: trunk/widgets/org.vexi.demo/src/org/vexi/demo/demomenus.t
===================================================================
--- trunk/widgets/org.vexi.demo/src/org/vexi/demo/demomenus.t   2010-02-10 
01:10:02 UTC (rev 3796)
+++ trunk/widgets/org.vexi.demo/src/org/vexi/demo/demomenus.t   2010-02-10 
02:59:37 UTC (rev 3797)
@@ -52,21 +52,43 @@
             <wi:menuitem text="Credits" enabled="false" />
         </wi:menu>
         
+        // sort by category, text
+        thisbox.sortfn = function(arg1, arg2) {
+            if (arg1.category > arg2.category) return -1;
+            else if (arg2.category > arg1.category) return 1;
+            else if (arg1.text > arg2.text) return -1;
+            else if (arg2.text > arg1.text) return 1;
+            else return 0;
+        }
+
+        // load and sort menu items from the 'feature' subdirectory
+        var features = .feature;
+        var sortedFeatures = [];
         var submenus = {};
-        
-        var features = .feature;
-        
+        var i = 0;
         for (var key in features) {
             // in case we encounter .svn
             if (key.charAt(0) == '.') continue;
-            var m = .demoitem(vexi.box);
-            m.load = features[key];
+
+            sortedFeatures[i] = .demoitem(vexi.box);
+            sortedFeatures[i].load = features[key];
             var n = features[key]..name;
-            m.text = n ? n : key;
-            var s = features[key]..category;
-            if (s == "Test Cases")
-               m.testcase = true;
-            if (!s) s = "Default";
+            sortedFeatures[i].text = n ? n : key;
+
+            var cat = features[key]..category;
+            if (cat == "Test Cases")
+                sortedFeatures[i].testcase = true;
+            if (!cat) 
+                cat = "Default";
+            sortedFeatures[i].category = cat;
+            i++;
+        }
+            
+        sortedFeatures.sort(thisbox.sortfn);
+        
+        for(var i = 0; sortedFeatures.length > i; i++) {
+            var m = sortedFeatures[i];
+            var s = m.category;
             if (!submenus[s]) {
                 submenus[s] = wi.submenu(vexi.box);
                 submenus[s].text = s;
@@ -75,5 +97,10 @@
             submenus[s][0] = m;
         }
         
-    </wi:toolbar>
+        // not reference again, good style given demomenus lives until the 
demo is closed
+        features = null;
+        sortedFeatures = null;
+        submenus = null;
+
+        </wi:toolbar>
 </vexi>


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to