resources/RooUsage.txt
[app.Builder.js] / src / Builder4 / WindowLeftTree.vala
index 441a499..983284b 100644 (file)
@@ -18,9 +18,9 @@ public class Xcls_WindowLeftTree : Object
     public Xcls_LeftTreeMenu LeftTreeMenu;
 
         // my vars (def)
-    public signal bool before_node_change (JsRender.Node? node);
+    public signal bool before_node_change ();
     public signal void changed ();
-    public signal void node_selected (JsRender.Node? node);
+    public signal void node_selected (JsRender.Node? node, string source);
     public Xcls_MainWindow main_window;
 
     // ctor
@@ -56,7 +56,7 @@ public class Xcls_WindowLeftTree : Object
          
     }
     public           JsRender.JsRender getActiveFile () {
-        return this.model.file;
+        return this.main_window.windowstate.file;
     }
     public           string getActivePath () {
         
@@ -77,9 +77,10 @@ public class Xcls_WindowLeftTree : Object
 
             // my vars (def)
         public string dragData;
-        public string[] dropList;
         public int drag_x;
+        public string[] dropList;
         public int drag_y;
+        public string lastEventSource;
         public bool drag_in_motion;
         public bool blockChanges;
 
@@ -91,9 +92,11 @@ public class Xcls_WindowLeftTree : Object
             this.el = new Gtk.TreeView();
 
             // my vars (dec)
+            this.lastEventSource = "";
             this.blockChanges = false;
 
             // set gobject values
+            this.el.expand = true;
             this.el.tooltip_column = 1;
             this.el.enable_tree_lines = true;
             this.el.headers_visible = false;
@@ -148,9 +151,12 @@ public class Xcls_WindowLeftTree : Object
             //listeners
             this.el.button_press_event.connect( ( ev) => {
                 //console.log("button press?");
-                if (! _this.before_node_change(null) ) {
+                this.lastEventSource = "tree";
+                if (! _this.before_node_change() ) {
+                
                    return true;
                 }
+                
             
                 
                 if (ev.type != Gdk.EventType.BUTTON_PRESS  || ev.button != 3) {
@@ -174,19 +180,63 @@ public class Xcls_WindowLeftTree : Object
                  //   print("click:" + res.path.to_string());
                   return true;
             });
+            this.el.drag_begin.connect( ( ctx)  => {
+               //print('SOURCE: drag-begin');
+                    
+                    
+                    //this.targetData = "";
+                    
+                    // find what is selected in our tree...
+                    
+                    var s = _this.view.el.get_selection();
+                    if (s.count_selected_rows() < 1) {
+                        return;
+                    }
+                    Gtk.TreeIter iter;
+                    Gtk.TreeModel mod;
+                    s.get_selected(out mod, out iter);
+            
+                    
+            
+                    // set some properties of the tree for use by the dropped element.
+                    GLib.Value value;
+                    _this.model.el.get_value(iter, 2, out value);
+                    var tp = mod.get_path(iter).to_string();
+                    var data = (JsRender.Node)(value.dup_object());
+                    var xname = data.fqn();
+                    print ("XNAME  IS " + xname+ "\n");
+                    this.dragData = tp;
+                    this.dropList = _this.main_window.windowstate.file.palete().getDropList(xname);
+                    
+                    print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n");
+                    
+            
+                    // make the drag icon a picture of the node that was selected
+                
+                    
+                // by default returns the path..
+                   var path = _this.model.el.get_path(iter);
+            
+                     
+                    var pix = this.el.create_row_drag_icon ( path);
+                    
+                    Gtk.drag_set_icon_surface (ctx, pix) ;
+                    
+                    return;
+            });
             this.el.cursor_changed.connect( ( ) => {
             
             
                  if (this.blockChanges) { // probably not needed.. 
                    return  ;
                  }
-                  if (!_this.before_node_change(null) ) {
+                  if (!_this.before_node_change( ) ) {
                     this.blockChanges = true;
                     this.el.get_selection().unselect_all();
                     this.blockChanges = false;
                     return;
                  }
-                 if (_this.model.file == null) {
+                 if (_this.main_window.windowstate.file == null) {
                      return;
                  } 
                  
@@ -195,7 +245,7 @@ public class Xcls_WindowLeftTree : Object
                 
                 
                 // -- it appears that the selection is not updated.
-                
+                  
                 GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {
                      
             
@@ -203,7 +253,7 @@ public class Xcls_WindowLeftTree : Object
             
                             print("selected rows < 1\n");
                             //??this.model.load( false);
-                            _this.node_selected(null);
+                            _this.node_selected(null, this.lastEventSource);
                             
                             return false ;
                         }
@@ -221,10 +271,10 @@ public class Xcls_WindowLeftTree : Object
                         _this.model.activePath = mod.get_path(iter).to_string();
                         
                         var node = (JsRender.Node)value.dup_object();
-                        _this.node_selected(node);
+                        _this.node_selected(node, this.lastEventSource);
                         while (Gtk.events_pending()) {
                             Gtk.main_iteration();
-                        }
+                       }
                         var cp = mod.get_path(iter);
                         Gtk.TreePath sp, ep;
                         this.el.get_visible_range(out sp, out ep);
@@ -248,50 +298,6 @@ public class Xcls_WindowLeftTree : Object
                 return  ;
                             
             });
-            this.el.drag_begin.connect( ( ctx)  => {
-               //print('SOURCE: drag-begin');
-                    
-                    
-                    //this.targetData = "";
-                    
-                    // find what is selected in our tree...
-                    
-                    var s = _this.view.el.get_selection();
-                    if (s.count_selected_rows() < 1) {
-                        return;
-                    }
-                    Gtk.TreeIter iter;
-                    Gtk.TreeModel mod;
-                    s.get_selected(out mod, out iter);
-            
-                    
-            
-                    // set some properties of the tree for use by the dropped element.
-                    GLib.Value value;
-                    _this.model.el.get_value(iter, 2, out value);
-                    var tp = mod.get_path(iter).to_string();
-                    var data = (JsRender.Node)(value.dup_object());
-                    var xname = data.fqn();
-                    print ("XNAME  IS " + xname+ "\n");
-                    this.dragData = tp;
-                    this.dropList = _this.model.file.palete().getDropList(xname);
-                    
-                    print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n");
-                    
-            
-                    // make the drag icon a picture of the node that was selected
-                
-                    
-                // by default returns the path..
-                   var path = _this.model.el.get_path(iter);
-            
-                     
-                    var pix = this.el.create_row_drag_icon ( path);
-                    
-                    Gtk.drag_set_icon_surface (ctx, pix) ;
-                    
-                    return;
-            });
             this.el.drag_end.connect( (drag_context) => {
                //Seed.print('LEFT-TREE: drag-end');
                     this.dragData = "";
@@ -577,7 +583,7 @@ public class Xcls_WindowLeftTree : Object
                      
                     // dropList --- need to gather this ... 
                     print("get dropList for : %s\n",dropNodeType);            
-                    var dropList = _this.model.file.palete().getDropList(dropNodeType);
+                    var dropList = _this.main_window.windowstate.file.palete().getDropList(dropNodeType);
                     
                     print("dropList: %s\n", string.joinv(" , ", dropList));
                     
@@ -824,7 +830,16 @@ public class Xcls_WindowLeftTree : Object
                  }
                      
         }
-        public           void selectNode (string treepath_str) {
+        public void setCursor (string treepath, string sourceEvent)   {
+               this.lastEventSource = sourceEvent;
+               //this.blockChanges = true; << block changes prevents loading of 'node data' and firing of node_selected..
+            this.el.set_cursor(new Gtk.TreePath.from_string(treepath), null, false); 
+            // fire node_selected..
+            //this.blockChanges = false;
+               this.lastEventSource = "";
+        }
+        public           void selectNode (string treepath_str, string source) {
+               this.lastEventSource = source;
             //this.selection.select_path(new  Gtk.TreePath.from_string( treepath_str));
              var tp = new Gtk.TreePath.from_string(treepath_str);
              
@@ -840,9 +855,7 @@ public class Xcls_WindowLeftTree : Object
 
             // my vars (def)
         public DialogTemplateSelect template_select;
-        public JsRender.JsRender? file;
         public string activePath;
-        public Project.Project? project;
 
         // ctor
         public Xcls_model(Xcls_WindowLeftTree _owner )
@@ -853,9 +866,7 @@ public class Xcls_WindowLeftTree : Object
 
             // my vars (dec)
             this.template_select = null;
-            this.file = null;
             this.activePath = "";
-            this.project = null;
 
             // set gobject values
 
@@ -890,34 +901,23 @@ public class Xcls_WindowLeftTree : Object
         public           void loadFile (JsRender.JsRender f) {
             //console.dump(f);
             this.el.clear();
-            this.file = f;
-            
             
-        //    if (!f) {
-        //        console.log('missing file');
-        //        return;
-        //    }
+            // needed???
+            _this.main_window.windowstate.file = f;
             
-            // load the file if not loaded..
+           
             if (f.tree == null) {
-                f.loadItems( );
+                   try {
+                       f.loadItems( );
+                } catch (Error e) {
+                       return;
+                }
             }
             // if it's still null?
             if (f.tree == null) {
                 return;
             }
-            
-            /// this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
-            
-            //if (f.items.length && typeof(f.items[0]) == 'string') {
-            
-                //this.get('/RightEditor').el.show();
-                //this.get('/RightEditor.view').load( f.items[0]);
-            //    return;
-            //}
-            //print("LOAD");
-            //print(JSON.stringify(f.items, null,4));
-            //console.dump(f.items);
+          
             var o = new Gee.ArrayList<JsRender.Node>();
             o.add(f.tree);
             this.load(o,null);
@@ -938,37 +938,7 @@ public class Xcls_WindowLeftTree : Object
             }
             
             return;
-            /*    
-            
-            //print("hide right editior");
-            //this.get('/RightEditor').el.hide();
-            //this.get('/Editor').el.hide();
-            //print("set current tree");
-            //this.currentTree = this.toJS(false, false)[0];
-            //console.dump(this.currentTree);
-            //this.currentTree = this.currentTree || { items: [] };
-            //_this.renderView();
-            //console.dump(this.map);
-            //var RightPalete     = imports.Builder.RightPalete.RightPalete;
-            
-            
-            var pm = this.get('/RightPalete.model');
-            // set up provider..
-            
-            this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
-            
-            if (!this.get('/RightPalete').provider) {
-                print ("********* PALETE PROVIDER MISSING?!!");
-            }
-            this.get('/LeftTree').renderView();
-            
-            pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
-            
-            
-                    
-            this.get('/Window.view-notebook').el.set_current_page(
-                this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
-                */
+         
                     
         }
         public    void updateSelected () {
@@ -1181,7 +1151,7 @@ public class Xcls_WindowLeftTree : Object
             var data = (JsRender.Node)(value.get_object());
             print("removing node from Render\n");
             if (data.parent == null) {
-                this.file.tree = null;
+               _this.main_window.windowstate.file.tree = null;
             } else {
                 data.remove();
             }
@@ -1256,9 +1226,9 @@ public class Xcls_WindowLeftTree : Object
                  
                      var new_node = ts.show(
                           _this.main_window, // (Gtk.Window) _this.el.get_toplevel (),
-                              this.file.palete(),
+                         _this.main_window.windowstate.file.palete(),
                             node,
-                            this.file.project);
+                            _this.main_window.windowstate.project);
                            
                      if (new_node == null) {
                          return; // do not add?
@@ -1273,7 +1243,7 @@ public class Xcls_WindowLeftTree : Object
                  if ( parent_str.length < 1) {
                       this.el.append(out n_iter, null); // drop at top level..
                       node.parent = null;
-                      this.file.tree = node;
+                      _this.main_window.windowstate.file.tree = node;
                       
                       
                 } else   if (pos  < 2) {
@@ -1335,7 +1305,7 @@ public class Xcls_WindowLeftTree : Object
                 // work out what kind of packing to use.. -- should be in 
                 if (!node.has("pack")   && parent_str.length > 1) {
                     
-                    this.file.palete().fillPack(node,parentNode);
+                    _this.main_window.windowstate.file.palete().fillPack(node,parentNode);
                     
                     
                 }
@@ -1545,7 +1515,7 @@ public class Xcls_WindowLeftTree : Object
             
                  DialogSaveTemplate.singleton().show(
                         (Gtk.Window) _this.el.get_toplevel (), 
-                        _this.model.file.palete(), 
+                        _this.main_window.windowstate.file.palete(), 
                         _this.getActiveElement()
                 );
                  
@@ -1580,7 +1550,7 @@ public class Xcls_WindowLeftTree : Object
                 var node = _this.getActiveElement();
                  var name = DialogSaveModule.singleton().show(
                         (Gtk.Window) _this.el.get_toplevel (), 
-                        _this.model.file.project, 
+                        _this.main_window.windowstate.project, 
                         node
                  );
                  if (name.length < 1) {
@@ -1612,7 +1582,7 @@ public class Xcls_WindowLeftTree : Object
                     _this.model.el.remove(ref citer);
                 }
                 _this.changed();
-                _this.node_selected(node);
+                _this.node_selected(node, "tree");
                  
                 
             });