sync
[app.Builder.js] / Builder / RightGtkView.js
index a9cc63a..609e079 100755 (executable)
@@ -68,22 +68,25 @@ RightGtkView = new XObject({
                     {
                         
                         id : 'view-vbox',
-                        xtype : Gtk.Viewport,
+                        xtype : Gtk.Fixed,
                         init : function () {
                             XObject.prototype.init.call(this); 
-                            this.el.set_hadjustment(this.parent.el.get_hadjustment());
-                            this.el.set_vadjustment(this.parent.el.get_vadjustment());
+                           // this.el.set_hadjustment(this.parent.el.get_hadjustment());
+                            //this.el.set_vadjustment(this.parent.el.get_vadjustment());
                                 
                         },
-                        packing : ['add' ],
+                        pack  : 'add_with_viewport' ,
                         items: [
                             {
                                 id : 'view',
+                                xtype : Gtk.VBox,
+                                /*
                                 xtype : function() {
                                     return new Gtk.Image.from_stock (Gtk.STOCK_HOME, 100) 
 
                                 },
-                                packing : ['add' ],
+                                */
+                                pack : 'put,10,10',
                                 ready : false,
                                 init : function() {
                                     XObject.prototype.init.call(this); 
@@ -288,7 +291,8 @@ RightGtkView = new XObject({
             */
         },
         
-        buildJS: function(data,withDebug) {
+        buildJS: function(data,withDebug) 
+        {
             var i = [ 'Gtk', 'Gdk', 'Pango', 'GLib', 'Gio', 'GObject', 'GtkSource', 'WebKit', 'Vte' ];
             var src = "";
             i.forEach(function(e) {
@@ -339,6 +343,23 @@ RightGtkView = new XObject({
             }
             this.withDebug = false;
             
+            if (this.renderedEl) {
+                this.get('view').el.remove(this.renderedEl);
+                this.renderedEl.destroy();
+                this.renderedEl = false;
+            }
+            
+            var tree =  this.get('/LeftTree.model').toJS()[0];
+            // in theory tree is actually window..
+            this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
+            this.get('view').el.set_size_request(
+                tree.default_width * 1 || 400, tree.default_height * 1 || 400
+            ) ;
+            
+            this.get('view').el.show_all();
+            
+            return;
+            
             
             var src = this.buildJS(data,withDebug);
             var x = new imports.sandbox.Context();
@@ -360,33 +381,9 @@ RightGtkView = new XObject({
             var r = new Gdk.Rectangle();
             var _top = x.get_global_object()._top;
             
-            //_top.el.set_screen(Gdk.Screen.get_default()); // just in case..
-            //_top.el.show_all();
-             var tp = new Gtk.OffscreenWindow();
-           
-            var _this = this;
-            tp.signal.expose_event.connect(function() {
-                
-                var pb = tp.get_pixmap();
-                print("GOT PIXMAP" + pb);
-                console.dump(pb.get_size());
-                _this.get('view').el.set_from_pixmap(pb, null);
-                
-                return true;
-                
-            });
-            
-            _top.el.remove(_top.items[0].el);
-             tp.add(_top.items[0].el);
-             
-             tp.show();
-            
-            
-            
-            
-            //tp.show_all();
-            return;
-            //var pb = tp.get_pixmap();
+            _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
+            _top.el.show_all();
+              
             
             if (_top.el.popup) {
                 _top.el.popup(null, null, null, null, 3, null);
@@ -510,8 +507,99 @@ RightGtkView = new XObject({
                
             
             
+        },
+        
+        buildView : function()
+        {
+            
+            
+        },
+        viewAdd : function(item, par)
+        {
+            // does something similar to xobject..
+            item.pack = (typeof(item.pack) == 'undefined') ?  'add' : item.pack;
+            
+            if (item.pack===false || item.pack === 'false') {  // no ;
+                return;
+            }
+            print("CREATE: " + item['|xns'] + '.' + item['xtype']);
+            var ns = imports.gi[item['|xns']];
+            var ctr = ns[item['xtype']];
+            var ctr_args = { };
+            for(var k in item) {
+                var kv = item[k];
+                if (typeof(kv) == 'object' || typeof(kv) == 'function') {
+                    continue;
+                }
+                if ( 
+                    k == 'pack' ||
+                    k == 'items' ||
+                    k == 'id' ||
+                    k == 'xtype' ||
+                    k == 'xdebug' ||
+                    k == 'xns' ||
+                    k == '|xns'
+                ) {
+                    continue;
+                }
+                ctr_args[k] = kv;
+                
+            } 
+            
+            
+            var el = new ctr(ctr_args);
+            
+            print("PACK");
+            console.dump(item.pack);
+            
+            
+            
+            
+            var args = [];
+            var pack_m  = false;
+            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(","));
+                
+                pack_m = args.shift();
+            } else {
+                pack_m = item.pack.shift();
+                args = item.pack;
+            }
+            
+            // handle error.
+            if (pack_m && typeof(par[pack_m]) == 'undefined') {
+                Seed.print('pack method not available : ' + item.xtype + '.' +  pack_m);
+                return;
+            }
+            
+            console.dump(args);
+            args.unshift(el);
+            //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
+            //Seed.print('args: ' + args.length);
+            if (pack_m) {
+                par[pack_m].apply(par, args);
+            }
+            
+            var _this = this;
+            item.items = item.items || [];
+            item.items.forEach(function(ch) {
+                _this.viewAdd(ch, el);
+            });
+            
+            return el;
+            
         }
         
+        
+        
     }