sync
authorAlan Knowles <alan@akbkhome.com>
Fri, 17 Dec 2010 02:17:32 +0000 (10:17 +0800)
committerAlan Knowles <alan@akbkhome.com>
Fri, 17 Dec 2010 02:17:32 +0000 (10:17 +0800)
Builder/Provider/ProjectManager.js
Sample/Window.bjs
Sample/Window.js

index ccba8c8..c108fad 100755 (executable)
@@ -43,9 +43,7 @@ ProjectManager =  new Observable({
             dir.make_directory();
             return;
         }
-        
-        
-        
+      
         this.projects = [];
         var gdir = GLib.dir_open(this.dirname,0);
         while (true) {
@@ -53,7 +51,7 @@ ProjectManager =  new Observable({
             var fn = gdir.read_name();
             if (!fn) {
                 gdir.close();
-                return;
+                break;
             }
             if (!fn.match(/.json$/)) {
                 continue;
@@ -78,7 +76,17 @@ ProjectManager =  new Observable({
              
         }
    
+        this.projects.sort(function(a,b) {
+            if (a.getName() == b.getName()) {
+                return 0;
+            }
+            return a.getName() > b.getName() ? 1 : -1;
+            
+            
+        });
+   
         
+       
         
         
         
index 9876443..cb877e8 100644 (file)
                                                                             "pack": "pack_start,false,false",
                                                                             "items": [
                                                                                 {
-                                                                                    "|xns": "Gtk",
-                                                                                    "xtype": "ComboBox",
-                                                                                    "id": "combo",
-                                                                                    "|init": "function() {\n    XObject.prototype.init.call(this);\n    this.el.add_attribute(this.get('render').el , 'markup', 1 );  \n}\n",
-                                                                                    "|getValue": "function() {\n    var ix = this.el.get_active();\n    if (ix < 0 ) {\n        return false;\n    }\n    var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;\n    if (typeof(data[ix]) == 'undefined') {\n \treturn false; \n    }\n    return data[ix].fn;\n}",
-                                                                                    "|setValue": "function(fn)\n{\n    var el = this.el;\n    el.set_active(-1);\n    var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;\n    data.forEach(function(n, ix) {\n        if (fn == n.fn) {\n            el.set_active(ix);\n            return false;\n        }\n    });\n}\n",
                                                                                     "listeners": {
                                                                                         "changed": "function (self) {\n\tvar fn = this.getValue();\n\tvar pm  = imports.Builder.Provider.ProjectManager.ProjectManager;\n\tthis.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))\n}"
                                                                                     },
+                                                                                    "id": "combo",
+                                                                                    "xtype": "ComboBox",
+                                                                                    "|getValue": "function() {\n    var ix = this.el.get_active();\n    if (ix < 0 ) {\n        return false;\n    }\n    var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;\n    if (typeof(data[ix]) == 'undefined') {\n \treturn false; \n    }\n    return data[ix].fn;\n}",
+                                                                                    "|init": "function() {\n    XObject.prototype.init.call(this);\n    this.el.add_attribute(this.get('render').el , 'markup', 1 );  \n}\n",
+                                                                                    "|setValue": "function(fn)\n{\n    var el = this.el;\n    el.set_active(-1);\n    var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;\n    data.forEach(function(n, ix) {\n        if (fn == n.fn) {\n            el.set_active(ix);\n            return false;\n        }\n    });\n}\n",
+                                                                                    "|xns": "Gtk",
                                                                                     "items": [
                                                                                         {
                                                                                             "|xns": "Gtk",
                                                                                             "id": "render"
                                                                                         },
                                                                                         {
-                                                                                            "|xns": "Gtk",
-                                                                                            "xtype": "ListStore",
+                                                                                            "id": "combomodel",
                                                                                             "pack": "set_model",
-                                                                                            "|init": "function() {\n    XObject.prototype.init.call(this);\n  this.el.set_column_types ( 2, [\n        GObject.TYPE_STRING,  // real key\n        GObject.TYPE_STRING // real type\n        \n        \n    ] );\n   var pm = imports.Builder.Provider.ProjectManager.ProjectManager;\n   var _this = this;\n   pm.on('changed', function() {\n       print(\"caught changed hook on project manager - reloading data\");\n\t_this.loadData(pm.projects);\n\n   });\n}\n",
+                                                                                            "xtype": "ListStore",
+                                                                                            "|init": "function() {\n    XObject.prototype.init.call(this);\n  this.el.set_column_types ( 2, [\n        GObject.TYPE_STRING,  // real key\n        GObject.TYPE_STRING // real type\n        \n        \n    ] );\n   // this.el.set_sort_column_id(1,Gtk.SortType.ASCENDING);\n   var pm = imports.Builder.Provider.ProjectManager.ProjectManager;\n   var _this = this;\n   pm.on('changed', function() {\n       print(\"caught changed hook on project manager - reloading data\");\n\t_this.loadData(pm.projects);\n\n   });\n}\n",
                                                                                             "|loadData": "function(data) {\n     var ov = this.get('/LeftProjectTree.combo').getValue();\n    this.el.clear();\n    var iter = new Gtk.TreeIter();\n    var el = this.el;\n    data.forEach(function(p) {\n        \n        el.append(iter);\n        \n         \n        el.set_value(iter, 0, p.fn);\n        el.set_value(iter, 1, p.name);\n        \n    });\n    \n    this.get('/LeftProjectTree.combo').setValue(ov);\n}\n",
-                                                                                            "id": "combomodel"
+                                                                                            "|xns": "Gtk"
                                                                                         }
                                                                                     ]
                                                                                 }
                                                             "|xns": "Gtk"
                                                         },
                                                         {
-                                                            "|xns": "Gtk",
+                                                            "pack": false,
                                                             "xtype": "TreeViewColumn",
                                                             "|init": "function() {\n    this.el = new Gtk.TreeViewColumn();\n    this.parent.el.append_column(this.el);\n    \n    XObject.prototype.init.call(this);\n    this.el.add_attribute(this.items[0].el , 'markup', 4  );\n}\n",
-                                                            "pack": false,
+                                                            "|xns": "Gtk",
                                                             "items": [
                                                                 {
                                                                     "|xns": "Gtk",
index 4696e81..04aaf2c 100644 (file)
@@ -1468,11 +1468,14 @@ Window=new XObject({
                                                                     items : [
                                                                         {
                                                                             xtype: Gtk.ComboBox,
-                                                                            id : "combo",
-                                                                            init : function() {
-                                                                                XObject.prototype.init.call(this);
-                                                                                this.el.add_attribute(this.get('render').el , 'markup', 1 );  
+                                                                            listeners : {
+                                                                                changed : function (self) {
+                                                                                       var fn = this.getValue();
+                                                                                       var pm  = imports.Builder.Provider.ProjectManager.ProjectManager;
+                                                                                       this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
+                                                                                }
                                                                             },
+                                                                            id : "combo",
                                                                             getValue : function() {
                                                                                 var ix = this.el.get_active();
                                                                                 if (ix < 0 ) {
@@ -1484,6 +1487,10 @@ Window=new XObject({
                                                                                 }
                                                                                 return data[ix].fn;
                                                                             },
+                                                                            init : function() {
+                                                                                XObject.prototype.init.call(this);
+                                                                                this.el.add_attribute(this.get('render').el , 'markup', 1 );  
+                                                                            },
                                                                             setValue : function(fn)
                                                                             {
                                                                                 var el = this.el;
@@ -1496,13 +1503,6 @@ Window=new XObject({
                                                                                     }
                                                                                 });
                                                                             },
-                                                                            listeners : {
-                                                                                changed : function (self) {
-                                                                                       var fn = this.getValue();
-                                                                                       var pm  = imports.Builder.Provider.ProjectManager.ProjectManager;
-                                                                                       this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
-                                                                                }
-                                                                            },
                                                                             items : [
                                                                                 {
                                                                                     xtype: Gtk.CellRendererText,
@@ -1511,6 +1511,7 @@ Window=new XObject({
                                                                                 },
                                                                                 {
                                                                                     xtype: Gtk.ListStore,
+                                                                                    id : "combomodel",
                                                                                     pack : "set_model",
                                                                                     init : function() {
                                                                                         XObject.prototype.init.call(this);
@@ -1520,6 +1521,7 @@ Window=new XObject({
                                                                                             
                                                                                             
                                                                                         ] );
+                                                                                       // this.el.set_sort_column_id(1,Gtk.SortType.ASCENDING);
                                                                                        var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
                                                                                        var _this = this;
                                                                                        pm.on('changed', function() {
@@ -1544,8 +1546,7 @@ Window=new XObject({
                                                                                         });
                                                                                         
                                                                                         this.get('/LeftProjectTree.combo').setValue(ov);
-                                                                                    },
-                                                                                    id : "combomodel"
+                                                                                    }
                                                                                 }
                                                                             ]
                                                                         }
@@ -2739,6 +2740,7 @@ Window=new XObject({
                                                 },
                                                 {
                                                     xtype: Gtk.TreeViewColumn,
+                                                    pack : false,
                                                     init : function() {
                                                         this.el = new Gtk.TreeViewColumn();
                                                         this.parent.el.append_column(this.el);
@@ -2746,7 +2748,6 @@ Window=new XObject({
                                                         XObject.prototype.init.call(this);
                                                         this.el.add_attribute(this.items[0].el , 'markup', 4  );
                                                     },
-                                                    pack : false,
                                                     items : [
                                                         {
                                                             xtype: Gtk.CellRendererText,