File.js
[app.Builder.js] / Sample / Window.js
index 7d66a12..6622391 100644 (file)
@@ -8,6 +8,7 @@ GtkSource = imports.gi.GtkSource;
 WebKit = imports.gi.WebKit;
 Vte = imports.gi.Vte;
 GtkClutter = imports.gi.GtkClutter;
+Gdl = imports.gi.Gdl;
 console = imports.console;
 XObject = imports.XObject.XObject;
 Window=new XObject({
@@ -264,7 +265,7 @@ Window=new XObject({
                                                         html = html.replace('</head>', project.runhtml + '</head>');
                                                         
                                                        
-                                                        var     jsstr = JSON.stringify(js[0], null, 4);
+                                                        var     jsstr = JSON.(js[0], null, 4);
                                                        
                                                         var runbuilder = '<script type="text/javascript">' + "\n" + 
                                                             " Builder.render(" + jsstr + ");\n" +
@@ -1151,7 +1152,7 @@ Window=new XObject({
                                                                                             return;
                                                                                         }
                                                                                         print("LOAD");
-                                                                                        print(JSON.stringify(f.items, null,4));
+                                                                                        print(JSON.(f.items, null,4));
                                                                                         //console.dump(f.items);
                                                                                         this.load(f.items);
                                                                                         this.get('/LeftTree.view').el.expand_all();
@@ -1330,7 +1331,7 @@ Window=new XObject({
                                                                                     }
                                                                                     o[i] = c[i];
                                                                                 }
-                                                                                return JSON.stringify(o);
+                                                                                return JSON.(o);
                                                                             },
                                                                             singleNodeToJS : function (treepath) 
                                                                                     {
@@ -1381,7 +1382,7 @@ Window=new XObject({
                                                                                 
                                                                                 if (treepath === false) {
                                                                                     //dupe!!!
-                                                                                    return JSON.parse(JSON.stringify(ar));
+                                                                                    return JSON.parse(JSON.(ar));
                                                                                 }
                                                                                 
                                                                                 return ar;
@@ -1432,8 +1433,8 @@ Window=new XObject({
                                                                                      var el = tree.getActivePath();
                                                                                      print(el);
                                                                                      var js = model.toJS(el, false);
-                                                                                    // print(JSON.stringify(js[0], null,4));
-                                                                                     this.get('/DialogSaveTemplate').show(JSON.stringify(js[0], null,4));
+                                                                                    // print(JSON.(js[0], null,4));
+                                                                                     this.get('/DialogSaveTemplate').show(JSON.(js[0], null,4));
                                                                                      
                                                                                     
                                                                                 }
@@ -1467,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 ) {
@@ -1483,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;
@@ -1495,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,
@@ -1510,6 +1511,7 @@ Window=new XObject({
                                                                                 },
                                                                                 {
                                                                                     xtype: Gtk.ListStore,
+                                                                                    id : "combomodel",
                                                                                     pack : "set_model",
                                                                                     init : function() {
                                                                                         XObject.prototype.init.call(this);
@@ -1519,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() {
@@ -1543,8 +1546,7 @@ Window=new XObject({
                                                                                         });
                                                                                         
                                                                                         this.get('/LeftProjectTree.combo').setValue(ov);
-                                                                                    },
-                                                                                    id : "combomodel"
+                                                                                    }
                                                                                 }
                                                                             ]
                                                                         }
@@ -2416,7 +2418,7 @@ Window=new XObject({
                                                                         }
                                                                         
                                                                         
-                                                                        //print(JSON.stringify(ar));
+                                                                        //print(JSON.(ar));
                                                                         return ar;
                                                                         // convert the l
                                                                     },
@@ -2721,7 +2723,7 @@ Window=new XObject({
                                                                   //  console.log( '<b>' + p.name +'</b> ['+p.type+']');
                                                                         //GObject.TYPE_STRING,  // real key
                                                                         // GObject.TYPE_STRING, // real type
-                                                                        // GObject.TYPE_STRING, // docs ?
+                                                                        // GObject.TYPE_STRING, // docs ?this.el.set_value(iter, 0, p.name);et_value(iter, 0, p.name);
                                                                         // GObject.TYPE_STRING // func def?
                                                                         
                                                                     
@@ -2738,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);
@@ -2745,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,
@@ -3181,14 +3183,14 @@ Window=new XObject({
                                                                                         
                                                                                         
                                                                                         this.renderedData = data;
-                                                                                        var str = JSON.stringify(data) ;
+                                                                                        var str = JSON.(data) ;
                                                                                         
                                                                                         if (!this.ready) {
                                                                                             console.log('not loaded yet');
                                                                                         }
                                                                                         this.lastRedraw = new Date();
                                                                                     
-                                                                                        this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
+                                                                                        this.el.execute_script("Builder.render(" + JSON.(data) + ");");
                                                                                          print( "before render" +    this.lastRedraw);
                                                                                         print( "after render" +    (new Date()));
                                                                                         
@@ -3302,21 +3304,30 @@ Window=new XObject({
                                                                     */
                                                                     },
                                                                     viewAdd : function(item, par)
-                                                                            {
+                                                                    {
+                                                                    
                                                                         // does something similar to xobject..
-                                                                        item.pack = (typeof(item.pack) == 'undefined') ?  'add' : item.pack;
+                                                                        //item.pack = (typeof(item.pack) == 'undefined') ?  'add' : item.pack;
                                                                         
+                                                                        // pack is forced to 'false'
                                                                         if (item.pack===false || item.pack === 'false') {  // no ;
                                                                             return;
                                                                         }
+                                                                        
                                                                         print("CREATE: " + item['|xns'] + '.' + item['xtype']);
+                                                                        
+                                                                        
                                                                         var type = item['|xns'] + '.' + item['xtype'];
                                                                         
                                                                         if (item['|xns'] == 'GtkClutter') { // we can not add this yet!
                                                                             return false;
                                                                         }
+                                                                        
                                                                         var ns = imports.gi[item['|xns']];
-                                                                        var ctr = ns[item['xtype']];
+                                                                        var ctr = ns[item['xtype']]; // why are we using array here..?
+                                                                        
+                                                                    
+                                                                        
                                                                         var ctr_args = { };
                                                                         for(var k in item) {
                                                                             var kv = item[k];
@@ -3334,13 +3345,13 @@ Window=new XObject({
                                                                             ) {
                                                                                 continue;
                                                                             }
-                                                                    
+                                                                            // value is a function..
                                                                        if (k[0] == '|' && typeof(kv) == 'string') {
                                                                     
                                                                                if (kv.match(new RegExp('function'))) {
                                                                                        continue;
                                                                                     }
-                                                                                print("WASL " + k + '=' + kv);
+                                                                               print("WASL " + k + '=' + kv);
                                                                                try {
                                                                                        eval( 'kv = ' + kv);
                                                                                } catch(e) {    continue; }
@@ -3360,10 +3371,18 @@ Window=new XObject({
                                                                             ctr_args[k] = kv;
                                                                             
                                                                         } 
-                                                                        
+                                                                        var altctr =  XObject.baseXObject({ xtype:  ctr} );
+                                                                        var pack_m  = false;
+                                                                        if (!item.pack && altctr) {
+                                                                            // try XObject.
+                                                                            print("SETTING PACK TO XObjectBase method");
+                                                                            pack_m = altctr.prototype.pack;
+                                                                            
+                                                                            
+                                                                        }
                                                                         
                                                                         var el = new ctr(ctr_args);
-                                                                        
+                                                                        item.el = el;
                                                                         print("PACK" + item.pack);
                                                                         //console.dump(item.pack);
                                                                         
@@ -3371,26 +3390,27 @@ Window=new XObject({
                                                                         
                                                                         
                                                                         var args = [];
-                                                                        var pack_m  = false;
-                                                                        if (typeof(item.pack) == 'string') {
-                                                                             
-                                                                            item.pack.split(',').forEach(function(e, i) {
+                                                                        if (!pack_m) {
+                                                                            item.pack = (typeof(item.pack) == 'undefined') ?  'add' : item.pack;
+                                                                            if (typeof(item.pack) == 'string') {
+                                                                                 
+                                                                                item.pack.split(',').forEach(function(e, i) {
+                                                                                    
+                                                                                    if (e == 'false') { args.push( false); return; }
+                                                                                    if (e == 'true') {  args.push( true);  return; }
+                                                                                    if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
+                                                                                    args.push(e);
+                                                                                });
+                                                                                //print(args.join(","));
                                                                                 
-                                                                                if (e == 'false') { args.push( false); return; }
-                                                                                if (e == 'true') {  args.push( true);  return; }
-                                                                                if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
-                                                                                args.push(e);
-                                                                            });
-                                                                            //print(args.join(","));
-                                                                            
-                                                                            pack_m = args.shift();
-                                                                        } else {
-                                                                            pack_m = item.pack.shift();
-                                                                            args = item.pack;
+                                                                                pack_m = args.shift();
+                                                                            } else {
+                                                                                pack_m = item.pack.shift();
+                                                                                args = item.pack;
+                                                                            }
                                                                         }
-                                                                        
                                                                         // handle error.
-                                                                        if (pack_m && typeof(par[pack_m]) == 'undefined') {
+                                                                        if (typeof(pack_m) == 'string' && typeof(par[pack_m]) == 'undefined') {
                                                                             throw {
                                                                                     name: "ArgumentError", 
                                                                                     message : 'pack method not available : ' + par.id + " : " + par + '.' +  pack_m +
@@ -3405,17 +3425,21 @@ Window=new XObject({
                                                                         args.unshift(el);
                                                                         //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
                                                                         //Seed.print('args: ' + args.length);
-                                                                        if (pack_m) {
+                                                                        if (typeof(pack_m) == 'string') {
                                                                             par[pack_m].apply(par, args);
+                                                                        } else if (pack_m) {
+                                                                            pack_m.call(item, par, item);
                                                                         }
                                                                         
                                                                         var _this = this;
                                                                         item.items = item.items || [];
                                                                         item.items.forEach(function(ch,n) {
                                                                     
-                                                                              print ("type:" + type);
+                                                                             print ("type:" + type);
                                                                               
-                                                                               print ("ch.pack:" + ch.pack);
+                                                                             print ("ch.pack:" + ch.pack);
+                                                                               
+                                                                               
                                                                              if (type == 'Gtk.Table' && ch.pack == 'add') {
                                                                                 var c = n % item.n_columns;
                                                                                 var r = Math.floor(n/item.n_columns);
@@ -3443,7 +3467,7 @@ Window=new XObject({
                                                                             el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item  ], true));
                                                                             el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item  ], true));
                                                                             el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item  ], true ));
-                                                                      el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item  ], true ));
+                                                                            el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item  ], true ));
                                                                         } catch(e) {
                                                                             // ignore!
                                                                            }