Revert "File.js"
[app.Builder.js] / Builder3 / Window.js
index 0143eda..c72c8cf 100644 (file)
@@ -1,4 +1,4 @@
-Gtk = imports.gi.Gtk;
+       Gtk = imports.gi.Gtk;
 Gdk = imports.gi.Gdk;
 Pango = imports.gi.Pango;
 GLib = imports.gi.GLib;
@@ -9,6 +9,9 @@ WebKit = imports.gi.WebKit;
 Vte = imports.gi.Vte;
 console = imports.console;
 XObject = imports.XObject.XObject;
+
+
 Window=new XObject({
     xtype: Gtk.Window,
     listeners : {
@@ -19,15 +22,15 @@ Window=new XObject({
            Gtk.main_quit();
         },
         show : function (self) {
-          
-        imports.ProjectManager.ProjectManager.loadConfig();
-          
-        print("HIDEWIN - calling MidPropTree hidewin")
-               this.get('/MidPropTree').hideWin();
-            this.get('/RightPalete').hide();
-            this.get('/BottomPane').el.hide();
-            //this.get('/Editor').el.show_all();
-        
+                       
+                 imports.ProjectManager.ProjectManager.loadConfig();
+                       
+                 print("HIDEWIN - calling MidPropTree hidewin")
+                         this.get('/MidPropTree').hideWin();
+                         this.get('/RightPalete').hide();
+                         this.get('/BottomPane').el.hide();
+                         //this.get('/Editor').el.show_all();
+                 
         }
     },
     border_width : 0,
@@ -35,24 +38,7 @@ Window=new XObject({
     default_width : 800,
     id : "Window",
     title : "Application Builder",
-    init : function() {
-         this.atoms = {
-               "STRING" : Gdk.atom_intern("STRING")
-       };
-       this.targetList = new Gtk.TargetList();
-       this.targetList.add( this.atoms["STRING"], 0, 0);
-       //imports.ProjectManager.ProjectManager.loadConfig();
-    Gtk.rc_parse_string(
-                "style \"gtkcombobox-style\" {\n" + 
-                "    GtkComboBox::appears-as-list = 1\n" +
-                "}\n"+
-                "class \"GtkComboBox\" style \"gtkcombobox-style\"\n");
-        XObject.prototype.init.call(this);
-        this.el.show_all();
-        
-       
-                  
-    },
     setTitle : function(str) {
         this.el.set_title(this.title + ' - ' + str);
     },
@@ -346,6 +332,10 @@ Window=new XObject({
                                             items : [
                                                 {
                                                     xtype: Gtk.Expander,
+                                                                                                       events : [
+                                                                                                               Gdk.EventMask.BUTTON_MOTION_MASK 
+                                                                                                       ],
+                                                                                                        
                                                     listeners : {
                                                         activate : function (self) {
                                                             // this does not actually expand it..
@@ -364,7 +354,7 @@ Window=new XObject({
                                                             }
                                                             return true;
                                                                  
-                                                        },
+                                                        } /*,
                                                         enter_notify_event : function (self, event) {
                                                             return true;
                                                              this.el.expanded = !this.el.expanded;
@@ -374,14 +364,12 @@ Window=new XObject({
                                                         
                                                         return true;
                                                         }
+                                                        */
                                                     },
                                                     id : "expander",
                                                     label : "Select Project or File",
                                                     pack : "pack_start,false,true",
-                                                    init : function() {
-                                                        XObject.prototype.init.call(this);
-                                                       this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK );
-                                                    },
+                                                  
                                                     onCollapse : function() {
                                                         
                                                         var nb = this.get('/LeftTopPanel.notebook');
@@ -394,6 +382,7 @@ Window=new XObject({
                                                        
                                                         var model = this.get('/LeftProjectTree.combomodel');
                                                         //  print ("loading Projects?")
+                                                                                                               //print(JSON.stringify(pm.projects, null,4));Seed.quit();
                                                         //console.dump(pm.projects);
                                                         model.loadData(pm.projects);
                                                          
@@ -410,11 +399,8 @@ Window=new XObject({
                                                     xtype: Gtk.Notebook,
                                                     id : "notebook",
                                                     pack : "pack_start,true,true",
-                                                    init : function() {
-                                                        XObject.prototype.init.call(this);
-                                                       this.el.set_current_page(0);
-                                                    
-                                                    },
+                                                                                                       current_page : 0,
+                                                     
                                                     show_border : false,
                                                     show_tabs : false,
                                                     items : [
@@ -461,12 +447,10 @@ Window=new XObject({
                                                                        case 'Gtk':
                                                                            return this.get('/RightGtkView');
                                                                }
+                                                                                                                               return false;
                                                             
                                                             },
-                                                            init : function() {
-                                                                XObject.prototype.init.call(this);
-                                                                this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
-                                                            },
+                                                            
                                                             renderView : function() {
                                                                 var render = this.getRenderer();
                                                                 var model = this.get('model');
@@ -498,7 +482,9 @@ Window=new XObject({
                                                                                 var res = {}; 
                                                                                 this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
                                                                                 
-                                                                                if (!this.get('/LeftTreeMenu').el)  { this.get('/LeftTreeMenu').init(); }
+                                                                                if (!this.get('/LeftTreeMenu').el)  {
+                                                                                                                                                                       this.get('/LeftTreeMenu').init();
+                                                                                                                                                               }
                                                                                 
                                                                                 this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
                                                                                 this.get('/LeftTreeMenu').el.show_all();
@@ -621,7 +607,7 @@ Window=new XObject({
                                                                                 Gdk.drag_status(ctx, 0, time);
                                                                                 return true;
                                                                             }
-                                                                              print(JSON.stringify(tg,null,4));
+                                                                            //  print(JSON.stringify(tg,null,4));
                                                                             //console.dump(tg);
                                                                             this.targetData = tg;    
                                                                             
@@ -636,7 +622,7 @@ Window=new XObject({
                                                                                 w.drag_get_data
                                                                                 (          /* will receive 'drag-data-received' signal */
                                                                                         ctx,        /* represents the current state of the DnD */
-                                                                                        this.get('/Window').atoms["STRING"],    /* the target type we want */
+                                                                                        imports.Builder3.Globals.atoms["STRING"],    /* the target type we want */
                                                                                         time            /* time stamp */
                                                                                 );
                                                                                 
@@ -780,7 +766,7 @@ Window=new XObject({
                                                                             },
                                                                             
                                                                     init : function() {
-                                                                               XObject.prototype.init.call(this);
+                                                                        XObject.prototype.init.call(this);
                                                                        var description = new Pango.FontDescription.c_new();
                                                                        description.set_size(8000);
                                                                        this.el.modify_font(description);
@@ -803,7 +789,7 @@ Window=new XObject({
                                                                                Gdk.DragAction.COPY   | Gdk.DragAction.MOVE           /* what to do with data after dropped */
                                                                        );
                                                                      
-                                                                       this.el.drag_source_set_target_list(this.get('/Window').targetList);
+                                                                       this.el.drag_source_set_target_list(imports.Builder3.Globals.targetList);
                                                                     
                                                                        this.el.drag_source_add_text_targets(); 
                                                                        this.el.drag_dest_set
@@ -814,7 +800,7 @@ Window=new XObject({
                                                                            Gdk.DragAction.COPY   | Gdk.DragAction.MOVE       /* what to do with data after dropped */
                                                                        );
                                                                     
-                                                                       this.el.drag_dest_set_target_list(  this.get('/Window').targetList);
+                                                                       this.el.drag_dest_set_target_list(  imports.Builder3.Globals.targetList);
                                                                        this.el.drag_dest_add_text_targets( );
                                                                     },
                                                                     selectNode : function(treepath_str) {
@@ -1076,14 +1062,14 @@ Window=new XObject({
                                                                                 
                                                                                 
                                                                             },
-                                                                            init : function() {
-                                                                                XObject.prototype.init.call(this);
-                                                                             this.el.set_column_types ( 3, [
+                                                                           columns : [
                                                                                         GObject.TYPE_STRING, // title 
                                                                                         GObject.TYPE_STRING, // tip
                                                                                         GObject.TYPE_STRING // source..
-                                                                                        ] );
-                                                                            },
+                                                                             ] ,
+                                                                                                                                                       
+                                                                                                                                                       
+                                                                           
                                                                             listAllTypes : function() {
                                                                                 var s = this.get('/LeftTree.view').selection;
                                                                                 print ("LIST ALL TYPES: " + s.count_selected_rows() );
@@ -1173,7 +1159,7 @@ Window=new XObject({
                                                                                     },
                                                                             loadFile : function(f) {
                                                                                 //console.dump(f);
-                                                                                print("LOADFILE");
+                                                                                  print("LOADFILE");
                                                                                         this.el.clear();
                                                                                         this.file = f;
                                                                                         
@@ -1258,7 +1244,7 @@ Window=new XObject({
                                                                                 s.get_selected( oret);
                                                                                 var node = this.nodeToJS(oret.iter,false);
                                                                                     //console.dump(node);
-                                                                                print(JSON.stringify(node, null,4)); 
+                                                                                //print(JSON.stringify(node, null,4)); 
                                                                                     
                                                                                     // needs to drop first, otherwise the target_data 
                                                                                         // treepath will be invalid.
@@ -1571,29 +1557,25 @@ Window=new XObject({
                                                                                     xtype: Gtk.ListStore,
                                                                                     id : "combomodel",
                                                                                     pack : "set_model",
-                                                                                    init : function() {
-                                                                                        XObject.prototype.init.call(this);
-                                                                                        this.el.set_column_types ( 2, [
-                                                                                            GObject.TYPE_STRING,  // real key
-                                                                                            GObject.TYPE_STRING // real type
-                                                                                            
-                                                                                            
-                                                                                        ] );
-                                                                                       // this.el.set_sort_column_id(1,Gtk.SortType.ASCENDING);
-                                                                                       var pm = imports.ProjectManager.ProjectManager;
-                                                                                       var _this = this;
-                                                                                       pm.on('changed', function() {
-                                                                                             print("caught changed hook on project manager - reloading data");
-                                                                                            _this.loadData(pm.projects);
+                                                                                                                                                                       
+                                                                                                                                                                       columns : [
+                                                                                                                                                                               GObject.TYPE_STRING,   
+                                                                                        GObject.TYPE_STRING
+                                                                                                                                                                       ],
+                                                                                                                                                                       
+                                                                                                                                                                       
                                                                                     
-                                                                                       });
-                                                                                    },
                                                                                     loadData : function(data) {
-                                                                                         var ov = this.get('/LeftProjectTree.combo').getValue();
+                                                                                                                                                                               //print("load data called");Seed.quit();
+                                                                                                                                                                               //print(data);Seed.quit();
+                                                                                                                                                                               
+                                                                                        var ov = this.get('/LeftProjectTree.combo').getValue();
                                                                                         this.el.clear();
                                                                                         var el = this.el;
                                                                                         var na = {};
-                                                                                        data.forEach(function(p) {
+                                                                                        
+                                                                                                                                                                               
+                                                                                                                                                                               data.forEach(function(p) {
                                                                                             
                                                                                             el.append(na);
                                                                                             //print(JSON.stringify(XObject.keys(na)));
@@ -1615,15 +1597,24 @@ Window=new XObject({
                                                                     xtype: Gtk.ScrolledWindow,
                                                                     pack : "add",
                                                                     shadow_type : Gtk.ShadowType.IN,
-                                                                    init : function() {
-                                                                        XObject.prototype.init.call(this);
-                                                                        this.el.set_policy  (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
-                                                                    },
+                                                                  
                                                                     items : [
                                                                         {
                                                                             xtype: Gtk.TreeView,
+                                                                           
                                                                             listeners : {
                                                                                 cursor_changed : function (self) {
+                                                                                    
+                                                                                    var model = this.get('/LeftProjectTree.model');
+                                                                                    
+
+                                                                                    
+                                                                                    if (model.loading) {
+                                                                                        
+                                                                                         
+                                                                                        return;
+                                                                                    }
+                                                                                    print("LOADING IS FALSE");
                                                                                     var ret = {};        
                                                                                     if (this.selection.count_selected_rows() < 1) {
                                                                                         //XN.get('Builder.LeftTree.model').
@@ -1631,8 +1622,7 @@ Window=new XObject({
                                                                                         
                                                                                         return;
                                                                                     }
-                                                                                    var model = this.get('/LeftProjectTree.model');
-                                                                                    //console.log('changed');
+                                                                                     //console.log('changed');
                                                                                     var s = this.selection;
                                                                                     s.get_selected(ret);
                                                                                     var value = ''+ ret.model.get_value(ret.iter, 2).value.get_string();
@@ -1675,47 +1665,57 @@ Window=new XObject({
                                                                                     xtype: Gtk.TreeStore,
                                                                                     pack : "set_model",
                                                                                     id : "model",
-                                                                                    init : function() {
-                                                                                        XObject.prototype.init.call(this);
-                                                                                      this.el.set_column_types ( 3, [
+                                                                                    loading : false,
+                                                                                                                                                                       columns :  [
                                                                                                         GObject.TYPE_STRING, // title 
                                                                                                         GObject.TYPE_STRING, // tip
                                                                                                         GObject.TYPE_STRING // id..
-                                                                                                        ] );
-                                                                                       
-                                                                                    },
+                                                                                                        ] ,
+                                                                                                                                                                        
+                                                                                    
                                                                                     loadProject : function(pr) {
                                                                                          print("LOAD PROJECT");
+                                                                                          var model = this.get('/LeftProjectTree.model');
+                                                                                         model.loading = true;
+                                                                                          
                                                                                         this.el.clear();
                                                                                          if (!pr) {
                                                                                              return;
                                                                                          }
-                                                                                         
+                                                                                      
                                                                                          this.get('/LeftProjectTree').project = pr;
+                                                                                       
                                                                                          this.load(pr.toTree());
+                                                                                    
                                                                                          this.get('/LeftProjectTree.view').el.expand_all();
+                                                                                         model.loading = false;
+                                                                                         
                                                                                     },
                                                                                     load : function(tr,iter) {
                                                                                       //  console.dump(tr);
-                                                                                                console.log('Project tree load: ' + tr.length);
-                                                                                                var cret = {};
-                                                                                                //this.insert(citer,iter,0);
-                                                                                                
-                                                                                                var _this = this;
-                                                                                                tr.forEach(function (r) {
-                                                                                                    if (!iter) {
-                                                                                                        _this.el.append(cret);   
-                                                                                                    } else {
-                                                                                                        _this.el.insert(cret,iter,-1);
-                                                                                                    }
-                                                                                                    _this.el.set_value(cret.iter, 0,  '' + r.getTitle() ); // title 
-                                                                                                    _this.el.set_value(cret.iter, 1, '' + r.getTitleTip()); // tip
-                                                                                                    _this.el.set_value(cret.iter, 2, '' + r.id ); //id
-                                                                                                    if (r.cn && r.cn.length) {
-                                                                                                        _this.load(r.cn, cret.iter);
-                                                                                                    }
-                                                                                                    
-                                                                                                });
+                                                                                        
+                                                                                       
+                                                                                        console.log('Project tree load: ' + tr.length);
+                                                                                        var cret = {};
+                                                                                        //this.insert(citer,iter,0);
+                                                                                        
+                                                                                        var _this = this;
+                                                                                        // recursive...
+                                                                                        tr.forEach(function (r) {
+                                                                                            if (!iter) {
+                                                                                                _this.el.append(cret);   
+                                                                                            } else {
+                                                                                                _this.el.insert(cret,iter,-1);
+                                                                                            }
+                                                                                            _this.el.set_value(cret.iter, 0,  '' + r.getTitle() ); // title 
+                                                                                            _this.el.set_value(cret.iter, 1, '' + r.getTitleTip()); // tip
+                                                                                            _this.el.set_value(cret.iter, 2, '' + r.id ); //id
+                                                                                            if (r.cn && r.cn.length) {
+                                                                                                _this.load(r.cn, cret.iter);
+                                                                                            }
+                                                                                            
+                                                                                        });
+                                                                                         
                                                                                     },
                                                                                     getValue : function(iter, col) {
                                                                                         var gval = ''+ this.el.get_value(iter, col).value.get_string();
@@ -2000,10 +2000,7 @@ Window=new XObject({
                                                     editing : false,
                                                     id : "LeftPanel",
                                                     pack : "add",
-                                                    init : function() {
-                                                        XObject.prototype.init.call(this);
-                                                       this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
-                                                    },
+                                                    
                                                     shadow_type : Gtk.ShadowType.IN,
                                                     items : [
                                                         {
@@ -2188,7 +2185,7 @@ Window=new XObject({
                                                                     
                                                                         this.el.set_value(ret.iter, 5, type + ' : ' + str);
                                                                         // update the tree...  
-                                                                        print("new data: "  + JSON.stringify(this.toJS() , null,4));
+                                                                        //print("new data: "  + JSON.stringify(this.toJS() , null,4));
                                                                         this.get('/LeftTree.model').setFromNode(false,this.toJS());
                                                                         this.get('/LeftTree.model').changed(doRefresh); 
                                                                                  
@@ -2267,9 +2264,7 @@ Window=new XObject({
                                                                         }
                                                                                                 
                                                                     },
-                                                                    init : function() {
-                                                                        XObject.prototype.init.call(this);
-                                                                    this.el.set_column_types ( 6, [
+                                                                                                                                       columns :  [
                                                                                                     GObject.TYPE_STRING,  // 0 real key
                                                                                                     GObject.TYPE_STRING, // 1 real value 
                                                                                                      GObject.TYPE_STRING,  // 2 visable key
@@ -2277,9 +2272,9 @@ Window=new XObject({
                                                                                                      GObject.TYPE_STRING, // 4 need to store type of!!!
                                                                                                       GObject.TYPE_STRING // 5 tooltip
                                                                                                   
-                                                                                                ]);
-                                                                    },
-                                                                    load : function(ar) {
+                                                                                                ],
+                                                                                                                                       
+                                                                     load : function(ar) {
                                                                     // might casue problesm..
                                                                         // this.get('/Editor.RightEditor').save();
                                                                     
@@ -3081,7 +3076,7 @@ Window=new XObject({
                                                                                                 w.drag_get_data
                                                                                                 (          /* will receive 'drag-data-received' signal */
                                                                                                         ctx,        /* represents the current state of the DnD */
-                                                                                                        this.get('/Window').atoms["STRING"],    /* the target type we want */
+                                                                                                        imports.Builder3.Globals.atoms["STRING"],    /* the target type we want */
                                                                                                         time            /* time stamp */
                                                                                                 );
                                                                                                                 
@@ -3175,7 +3170,7 @@ Window=new XObject({
                                                                                         );
                                                                                                                 
                                                                                        // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
-                                                                                        this.el.drag_dest_set_target_list(  this.get('/Window').targetList);
+                                                                                        this.el.drag_dest_set_target_list(  imports.Builder3.Globals.targetList);
                                                                                         
                                                                                         GLib.timeout_add_seconds(0, 1, function() {
                                                                                             //    print("run refresh?");
@@ -3797,7 +3792,7 @@ Window=new XObject({
                                                                                                                 );
                                                                                                                 
                                                                                                                // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
-                                                                                                                this.el.drag_dest_set_target_list( this.get('/Window').targetList);
+                                                                                                                this.el.drag_dest_set_target_list( imports.Builder3.Globals.targetList);
                                                                                                     },
                                                                                                     ready : false,
                                                                                                     getActiveNode : function(x,y)
@@ -3852,7 +3847,7 @@ Window=new XObject({
                                                                                                                 self.drag_get_data
                                                                                                                 (  /* will receive 'drag-data-received' signal */
                                                                                                                         ctx,        /* represents the current state of the this.gDnD */
-                                                                                                                        this.get('/Window').atoms["STRING"],    /* the target type we want */
+                                                                                                                        imports.Builder3.Globals.atoms["STRING"],    /* the target type we want */
                                                                                                                         time            /* time stamp */
                                                                                                                 );
                                                                                                                 
@@ -4027,7 +4022,7 @@ Window=new XObject({
                                         this.get('buttonbar').el.hide();
                                         this.get('viewbox').el.show();
                                         var ce = this.get('/Window.centereast').el;
-                                        print(JSON.stringify(XObject.keys(ce) ,null,4));
+                                        //print(JSON.stringify(XObject.keys(ce) ,null,4));
                                         ce.set_position(ce.get_allocated_width() - 150);
                                            
                                        // this.get('model').expanded();
@@ -4208,7 +4203,7 @@ Window=new XObject({
                                                                 );
                                                                 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
                                                                
-                                                                this.el.drag_source_set_target_list(  this.get('/Window').targetList);
+                                                                this.el.drag_source_set_target_list( imports.Builder3.Globals.targetList);
                                                                 this.el.drag_source_add_text_targets( ); 
                                                                 /*
                                                                 print("RP: TARGET:" + LeftTree.atoms["STRING"]);