Fix #8062 - fix new file node selection issue
[roobuilder] / src / Builder4 / WindowLeftTree.vala
index 443b713..70b5349 100644 (file)
@@ -14,18 +14,20 @@ public class Xcls_WindowLeftTree : Object
        }
        public Xcls_viewwin viewwin;
        public Xcls_view view;
+       public Xcls_keystate keystate;
        public Xcls_drop drop;
        public Xcls_selmodel selmodel;
        public Xcls_model model;
        public Xcls_maincol maincol;
-       public Xcls_keystate keystate;
        public Xcls_LeftTreeMenu LeftTreeMenu;
 
                // my vars (def)
        public signal bool before_node_change ();
-       public Xcls_MainWindow main_window;
+       public Xcls_MainWindow? main_window;
+       public int last_error_counter;
        public signal void changed ();
        public signal void node_selected (JsRender.Node? node);
+       public Gee.ArrayList<Gtk.Widget>? error_widgets;
 
        // ctor
        public Xcls_WindowLeftTree()
@@ -35,11 +37,13 @@ public class Xcls_WindowLeftTree : Object
 
                // my vars (dec)
                this.main_window = null;
+               this.last_error_counter = -1;
+               this.error_widgets = null;
 
                // set gobject values
                this.el.hexpand = true;
                this.el.vexpand = true;
-               var child_1 = new Xcls_ListView2( _this );
+               var child_1 = new Xcls_ListView1( _this );
                child_1.ref();
                this.el.append( child_1.el );
                new Xcls_viewwin( _this );
@@ -47,11 +51,129 @@ public class Xcls_WindowLeftTree : Object
        }
 
        // user defined functions
+       public void updateErrors () {
+               var file = this.getActiveFile();
+               if (file == null) {
+                       return;
+               }
+               
+               var ar = file.getErrors();
+               if (ar == null || ar.size < 1) {
+                       if (this.last_error_counter != file.error_counter) {
+                               this.removeErrors();
+                       }
+               
+                       this.last_error_counter = file.error_counter ;
+       
+                       return;
+               }
+               if (this.last_error_counter == file.error_counter) {
+                       return;
+               }
+               this.removeErrors();
+               this.error_widgets = new Gee.ArrayList<Gtk.Widget>();
+               foreach(var diag in ar) { 
+               
+                        
+       //        print("get inter\n");
+                   var node= file.lineToNode( (int)diag.range.start.line) ;
+                   if (node == null) {
+                       continue;
+               }
+               var row = _this.model.nodeToRow(node);
+               if (row < 0) {
+                       continue;
+                       }
+               var w = this.view.getWidgetAtRow(row);
+               if (w == null) {
+                       return;
+                       }
+                       this.error_widgets.add(w);
+                       // always show errors.
+                       var ed = diag.category.down();
+                       if (ed != "err" && w.has_css_class("node-err")) {
+                               continue;
+                       }
+                       if (ed == "err" && w.has_css_class("node-warn")) {
+                               w.remove_css_class("node-warn");
+                       }
+                       if (ed == "err" && w.has_css_class("node-depr")) {
+                               w.remove_css_class("node-depr");
+                       }
+                       if (!w.has_css_class("node-"+ ed)) {
+                               w.add_css_class("node-" + ed);
+                       }
+                       
+               }
+               
+       }
        public void onresize () {
         
                 
                //GLib.debug("Got allocation width of scrolled view %d", allocation.width );
        //      _this.maincol.el.set_max_width( _this.viewwin.el.get_width()  - 32 );
+       }
+       public void removeErrors () {
+               if (this.error_widgets == null || this.error_widgets.size < 1) {
+                       return;
+               }
+               foreach(var child in this.error_widgets) {
+               
+                       if (child.has_css_class("node-err")) {
+                               child.remove_css_class("node-err");
+                       }
+                       if (child.has_css_class("node-warn")) {
+                               child.remove_css_class("node-warn");
+                       }
+                       
+                       if (child.has_css_class("node-depr")) {
+                               child.remove_css_class("node-depr");
+                       }
+               }
+               this.error_widgets  = null;
+               return;
+               
+               /*
+               var  child = this.view.el.get_first_child(); 
+        
+               var reading_header = true;
+        
+               while (child != null) {
+                       //GLib.debug("Got %s", child.get_type().name());
+                  
+                  if (reading_header) {
+                               
+       
+                               if (child.get_type().name() != "GtkColumnListView") {
+                                  
+                                       child = child.get_next_sibling();
+                                       continue;
+                               }
+                               // should be columnlistview
+                               child = child.get_first_child(); 
+                        
+                        
+                               
+                               reading_header = false;
+                                continue;
+                   }
+                   
+                       if (child.has_css_class("node-err")) {
+                               child.remove_css_class("node-err");
+                       }
+                       if (child.has_css_class("node-warn")) {
+                               child.remove_css_class("node-warn");
+                       }
+                       
+                       if (child.has_css_class("node-depr")) {
+                               child.remove_css_class("node-depr");
+                       }
+                       
+               child = child.get_next_sibling(); 
+               }
+               //GLib.debug("Rturning null");
+               */
+            
        }
        public JsRender.Node? getActiveElement () { // return path to actie node.
        
@@ -62,8 +184,9 @@ public class Xcls_WindowLeftTree : Object
        }
        public JsRender.JsRender getActiveFile () {
            return this.main_window.windowstate.file;
+           
        }
-       public class Xcls_ListView2 : Object
+       public class Xcls_ListView1 : Object
        {
                public Gtk.ListView el;
                private Xcls_WindowLeftTree  _this;
@@ -72,10 +195,10 @@ public class Xcls_WindowLeftTree : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_ListView2(Xcls_WindowLeftTree _owner )
+               public Xcls_ListView1(Xcls_WindowLeftTree _owner )
                {
                        _this = _owner;
-                       var child_1 = new Xcls_SignalListItemFactory3( _this );
+                       var child_1 = new Xcls_SignalListItemFactory2( _this );
                        child_1.ref();
                        this.el = new Gtk.ListView( null, child_1.el );
 
@@ -86,7 +209,7 @@ public class Xcls_WindowLeftTree : Object
 
                // user defined functions
        }
-       public class Xcls_SignalListItemFactory3 : Object
+       public class Xcls_SignalListItemFactory2 : Object
        {
                public Gtk.SignalListItemFactory el;
                private Xcls_WindowLeftTree  _this;
@@ -95,7 +218,7 @@ public class Xcls_WindowLeftTree : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_SignalListItemFactory3(Xcls_WindowLeftTree _owner )
+               public Xcls_SignalListItemFactory2(Xcls_WindowLeftTree _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.SignalListItemFactory();
@@ -172,32 +295,32 @@ public class Xcls_WindowLeftTree : Object
                        this.el.name = "left-tree-view";
                        this.el.hexpand = false;
                        this.el.vexpand = true;
-                       var child_2 = new Xcls_GestureClick6( _this );
+                       var child_2 = new Xcls_GestureClick5( _this );
                        child_2.ref();
                        this.el.add_controller(  child_2.el );
-                       var child_3 = new Xcls_GestureClick7( _this );
+                       var child_3 = new Xcls_GestureClick6( _this );
                        child_3.ref();
                        this.el.add_controller(  child_3.el );
-                       var child_4 = new Xcls_DragSource8( _this );
+                       var child_4 = new Xcls_DragSource7( _this );
                        child_4.ref();
                        this.el.add_controller(  child_4.el );
-                       var child_5 = new Xcls_EventControllerKey9( _this );
+                       var child_5 = new Xcls_EventControllerKey8( _this );
                        child_5.ref();
                        this.el.add_controller(  child_5.el );
+                       new Xcls_keystate( _this );
+                       this.el.add_controller(  _this.keystate.el );
                        new Xcls_drop( _this );
                        this.el.add_controller(  _this.drop.el );
                        new Xcls_maincol( _this );
                        this.el.append_column ( _this.maincol.el  );
-                       var child_8 = new Xcls_ColumnViewColumn15( _this );
-                       child_8.ref();
-                       this.el.append_column ( child_8.el  );
-                       new Xcls_keystate( _this );
-                       this.el.add_controller(  _this.keystate.el );
+                       var child_9 = new Xcls_ColumnViewColumn15( _this );
+                       child_9.ref();
+                       this.el.append_column ( child_9.el  );
 
                        // init method
 
                        {
-                        
+                        /*
                          this.css = new Gtk.CssProvider();
                        //      try {
                                        this.css.load_from_string("
@@ -213,6 +336,31 @@ public class Xcls_WindowLeftTree : Object
                         border-top-style: solid;
                         border-top-color: #88a3bc;
                        }
+                       .node-err  {
+                        border-top-width: 5px;
+                        border-top-style: solid;
+                        border-top-color: red;
+                        border-bottom-width: 5px; 
+                        border-bottom-style: solid;
+                        border-bottom-color: red;
+                       }
+                       .node-warn  {
+                        border-top-width: 5px;
+                        border-top-style: solid;
+                        border-top-color: #ABF4EB;
+                        border-bottom-width: 5px; 
+                        border-bottom-style: solid;
+                        border-bottom-color: #ABF4EB;
+                       }
+                       .node-depr  {
+                        border-top-width: 5px;
+                        border-top-style: solid;
+                        border-top-color: #EEA9FF;
+                        border-bottom-width: 5px; 
+                        border-bottom-style: solid;
+                        border-bottom-color: #EEA9FF;
+                       }
+                       
                        #left-tree-view indent {
                        -gtk-icon-size : 2px;
                        }
@@ -226,7 +374,7 @@ public class Xcls_WindowLeftTree : Object
                                        this.css,
                                        Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
                                );
-                               
+                               */
                                  
                        }
                }
@@ -249,7 +397,7 @@ public class Xcls_WindowLeftTree : Object
                        var reading_header = true;
                         
                        while (child != null) {
-                                       GLib.debug("Got %s", child.get_type().name());
+                                       //GLib.debug("Got %s", child.get_type().name());
                           
                           if (reading_header) {
                                                
@@ -265,7 +413,7 @@ public class Xcls_WindowLeftTree : Object
                                         
                                                
                                                reading_header = false;
-                                                
+                                               continue;
                                    }
                                    
                                  
@@ -282,184 +430,102 @@ public class Xcls_WindowLeftTree : Object
                
                 }
                public int getColAt (double x,  double y) {
-               /*
-                       
-               from            https://discourse.gnome.org/t/gtk4-finding-a-row-data-on-gtkcolumnview/8465
-                         
-                       */
-                               //Gtk.Allocation alloc = { 0, 0, 0, 0 };
-                               //GLib.debug("Cehck %d, %d", x,y);
-                       var  child = this.el.get_first_child(); 
-                        
-                       var col = 0;
-                       var offx = 0;
-                       while (child != null) {
-                                       
-                                       if (child.get_type().name() == "GtkColumnViewRowWidget") {
-                                               child = child.get_first_child();
-                                               continue;
-                                       }
+                       /*
                                        
-                                       //child.get_allocation(out alloc);
-                                       if (x <  (child.get_width() + offx)) {
-                                               return col;
-                                       }
-                                       return 1;
-                                       //offx += child.get_width();
-                                       //col++;
-                                       //child = child.get_next_sibling();
+                       from            https://discourse.gnome.org/t/gtk4-finding-a-row-data-on-gtkcolumnview/8465
+                         
+                       */
+                       //Gtk.Allocation alloc = { 0, 0, 0, 0 };
+                       //GLib.debug("Cehck %d, %d", x,y);
+                   var  child = this.el.get_first_child(); 
+                        
+                       var col = 0;
+                       var offx = 0;
+                       while (child != null) {
+                               
+                               if (child.get_type().name() == "GtkColumnViewRowWidget") {
+                                       child = child.get_first_child();
+                                       continue;
                                }
-                            
-                                         
-                       return -1;
+                               
+                               //child.get_allocation(out alloc);
+                               if (x <  (child.get_width() + offx)) {
+                                       return col;
+                               }
+                               return 1;
+                               //offx += child.get_width();
+                               //col++;
+                               //child = child.get_next_sibling();
+                       }
+                            
+                                 
+                   return -1;
                
                 }
-               public int getRowAt (double x,  double in_y, out string pos) {
-               
+               public int getRowAt (double x,  double  y, out string pos) {
                
+                       pos = "";
+                       var w = this.el.pick(x, y, Gtk.PickFlags.DEFAULT);
+                       //GLib.debug("got widget %s", w == null ? "nothing" : w.get_type().name());
+                       if (w == null) {
+                               return -1;
+                       }
+                       
+                       var row= w.get_ancestor(GLib.Type.from_name("GtkColumnViewRowWidget"));
+                       if (row == null) {
+                               return -1;
+                       }
+                       
+                       //GLib.debug("got colview %s", row == null ? "nothing" : row.get_type().name());
                         
-               
-               /*
-                       
-               from            https://discourse.gnome.org/t/gtk4-finding-a-row-data-on-gtkcolumnview/8465
-                       var colview = gesture.widget;
-                       var line_no = check_list_widget(colview, x,y);
-                        if (line_no > -1) {
-                               var item = colview.model.get_item(line_no);
-                                
-                       }
-                       */
-                                
-                               
-                               //GLib.debug("offset = %d  y = %d", (int) voff, (int) in_y);
-                       var y = in_y + _this.viewwin.el.vadjustment.value; 
-                       var  child = this.el.get_first_child(); 
-                       //Gtk.Allocation alloc = { 0, 0, 0, 0 };
-                       var line_no = -1; 
-                       var reading_header = true;
-                       var real_y = 0;
-                       var header_height  = 0;
-                       pos = "none";
-                       var h = 0;
-                       while (child != null) {
-                                       //GLib.debug("Got %s", child.get_type().name());
-                           if (reading_header) {
-                                               
-               
-                                               if (child.get_type().name() != "GtkColumnListView") {
-                                               h += child.get_height();
-                                                       child = child.get_next_sibling();
-                                                       continue;
-                                               }
-                                               // should be columnlistview
-                                               child = child.get_first_child(); 
-                                           GLib.debug("header height=%d", h);
-                                               header_height =  h;
-                                               
-                                               reading_header = false;
-                                               
-                               }
-                               
-                                   if (child.get_type().name() != "GtkColumnViewRowWidget") {
-                                   child = child.get_next_sibling();
-                                   continue;
-                                   }
-                                   
-                                       if (y < header_height) {
-                                       return -1;
-                               }
-                                   
-                                   line_no++;
-                                       var hh = child.get_height();
-                                       //child.get_allocation(out alloc);
-                                       //GLib.debug("got cell xy = %d,%d  w,h= %d,%d", alloc.x, alloc.y, alloc.width, alloc.height);
-                                       //GLib.debug("row %d y= %d %s", line_no, (int) (header_height + alloc.y),
-                                       
-                                       //      child.visible ? "VIS" : "hidden");
-               
-                                   if (y >  (header_height + real_y) && y <= (header_height +  real_y + hh) ) {
-                                       if (y > ( header_height + real_y + (hh * 0.8))) {
-                                               pos = "below";
-                                       } else if (y > ( header_height + real_y + (hh * 0.2))) {
-                                               pos = "over";
-                                       } else {
-                                               pos = "above";
-                                               }
-                                        GLib.debug("getRowAt return : %d, %s", line_no, pos);
-                                           return line_no;
-                                   }
-                
-               
-                                   if (real_y + hh > y) {
-                                       return -1;
-                               }
-                               real_y += hh;
-                               child = child.get_next_sibling(); 
-                       }
-                       return -1;
-               
+                       var rn = 0;
+                       var cr = row;
+                        
+                       while (cr.get_prev_sibling() != null) {
+                               rn++;
+                               cr = cr.get_prev_sibling();
+                       }
+                       
+                       //GLib.debug("row number is %d", rn);
+                       //GLib.debug("click %d, %d", (int)x, (int)y);
+                       // above or belw
+                       Graphene.Rect  bounds;
+                       row.compute_bounds(this.el, out bounds);
+                       //GLib.debug("click x=%d, y=%d, w=%d, h=%d", 
+                       //      (int)bounds.get_x(), (int)bounds.get_y(),
+                       //      (int)bounds.get_width(), (int)bounds.get_height()
+                       //      );
+                       var ypos = y - bounds.get_y();
+                       //GLib.debug("rel ypos = %d", (int)ypos);       
+                       var rpos = 100.0 * (ypos / bounds.get_height());
+                       //GLib.debug("rel pos = %d %%", (int)rpos);
+                       pos = "over";
+                       
+                       if (rpos > 80) {
+                               pos = "below";
+                       } else if (rpos < 20) {
+                               pos = "above";
+                       } 
+                       return rn;
                 }
-               public Gtk.Widget? getWidgetAt (double x,  double in_y) {
-               /*
-                       
-               from            https://discourse.gnome.org/t/gtk4-finding-a-row-data-on-gtkcolumnview/8465
-                       var colview = gesture.widget;
-                       var line_no = check_list_widget(colview, x,y);
-                        if (line_no > -1) {
-                               var item = colview.model.get_item(line_no);
-                                
-                       }
-                       */
-                       var y = in_y + _this.viewwin.el.vadjustment.value; 
-                       var  child = this.el.get_first_child(); 
-                       //Gtk.Allocation alloc = { 0, 0, 0, 0 };
-                       var line_no = -1; 
-                       var reading_header = true;
-                       var curr_y = 0;
-                       var header_height  = 0;
-                       var h = 0;
-                       while (child != null) {
-                                       //GLib.debug("Got %s", child.get_type().name());
-                               if (reading_header) {
-                                               
-               
-                                               if (child.get_type().name() != "GtkColumnListView") {
-                                               h += child.get_height();
-                                                       child = child.get_next_sibling();
-                                                       continue;
-                                               }
-                                               // should be columnlistview
-                                               child = child.get_first_child(); 
-                                           GLib.debug("header height=%d", h);
-                                               header_height =  h;
-                                               
-                                               reading_header = false;
-                                               
-                               }
-                                   line_no++;
+               public Gtk.Widget? getWidgetAt (double x,  double  y) {
                
-                                       if (y < header_height) {
-                                       return null;
-                               }
-               
-                                       var hh = child.get_height();
-                                       //GLib.debug("got cell xy = %d,%d  w,h= %d,%d", alloc.x, alloc.y, alloc.width, alloc.height);
-               
-                                   if (y > curr_y && y <= header_height + hh + curr_y ) {
-                                           return (Gtk.Widget)child;
-                                   }
-                                   curr_y +=  hh ;
-               
-                                   if (curr_y > y) {
-                                       return null;
-                               }
-                               child = child.get_next_sibling(); 
-                       }
-                       return null;
+                       var w = this.el.pick(x, y, Gtk.PickFlags.DEFAULT);
+                       //GLib.debug("got widget %s", w == null ? "nothing" : w.get_type().name());
+                       if (w == null) {
+                               return null;
+                       }
+                       
+                       var row= w.get_ancestor(GLib.Type.from_name("GtkColumnViewRowWidget"));
+                       if (row == null) {
+                               return null;
+                       }
+                       return row;
+                
                
                 }
        }
-       public class Xcls_GestureClick6 : Object
+       public class Xcls_GestureClick5 : Object
        {
                public Gtk.GestureClick el;
                private Xcls_WindowLeftTree  _this;
@@ -468,7 +534,7 @@ public class Xcls_WindowLeftTree : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_GestureClick6(Xcls_WindowLeftTree _owner )
+               public Xcls_GestureClick5(Xcls_WindowLeftTree _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.GestureClick();
@@ -545,7 +611,7 @@ public class Xcls_WindowLeftTree : Object
                // user defined functions
        }
 
-       public class Xcls_GestureClick7 : Object
+       public class Xcls_GestureClick6 : Object
        {
                public Gtk.GestureClick el;
                private Xcls_WindowLeftTree  _this;
@@ -554,7 +620,7 @@ public class Xcls_WindowLeftTree : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_GestureClick7(Xcls_WindowLeftTree _owner )
+               public Xcls_GestureClick6(Xcls_WindowLeftTree _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.GestureClick();
@@ -587,6 +653,8 @@ public class Xcls_WindowLeftTree : Object
                                GLib.warning("No node found at row %d", row);
                                return;
                                }
+                               
+                               
                                _this.model.selectNode(node);
                             
                             
@@ -614,7 +682,7 @@ public class Xcls_WindowLeftTree : Object
                // user defined functions
        }
 
-       public class Xcls_DragSource8 : Object
+       public class Xcls_DragSource7 : Object
        {
                public Gtk.DragSource el;
                private Xcls_WindowLeftTree  _this;
@@ -623,7 +691,7 @@ public class Xcls_WindowLeftTree : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_DragSource8(Xcls_WindowLeftTree _owner )
+               public Xcls_DragSource7(Xcls_WindowLeftTree _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.DragSource();
@@ -704,7 +772,7 @@ public class Xcls_WindowLeftTree : Object
                // user defined functions
        }
 
-       public class Xcls_EventControllerKey9 : Object
+       public class Xcls_EventControllerKey8 : Object
        {
                public Gtk.EventControllerKey el;
                private Xcls_WindowLeftTree  _this;
@@ -713,7 +781,7 @@ public class Xcls_WindowLeftTree : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_EventControllerKey9(Xcls_WindowLeftTree _owner )
+               public Xcls_EventControllerKey8(Xcls_WindowLeftTree _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.EventControllerKey();
@@ -740,6 +808,50 @@ public class Xcls_WindowLeftTree : Object
                // user defined functions
        }
 
+       public class Xcls_keystate : Object
+       {
+               public Gtk.EventControllerKey el;
+               private Xcls_WindowLeftTree  _this;
+
+
+                       // my vars (def)
+               public int is_shift;
+
+               // ctor
+               public Xcls_keystate(Xcls_WindowLeftTree _owner )
+               {
+                       _this = _owner;
+                       _this.keystate = this;
+                       this.el = new Gtk.EventControllerKey();
+
+                       // my vars (dec)
+                       this.is_shift = 0;
+
+                       // set gobject values
+
+                       //listeners
+                       this.el.key_released.connect( (keyval, keycode, state) => {
+                               GLib.debug("key release %d, %d, %d" , (int) keyval, (int)  keycode, state);
+                               if (keyval == Gdk.Key.Shift_L || keyval == Gdk.Key.Shift_R) {
+                                       this.is_shift = 0;
+                               }
+                               //GLib.debug("set state %d , shift = %d", (int)this.el.get_current_event_state(), Gdk.ModifierType.SHIFT_MASK);
+                       
+                       
+                        
+                       });
+                       this.el.key_pressed.connect( (keyval, keycode, state) => {
+                       
+                               if (keyval == Gdk.Key.Shift_L || keyval == Gdk.Key.Shift_R) {
+                                       this.is_shift = 1;
+                               }
+                               return true;
+                       });
+               }
+
+               // user defined functions
+       }
+
        public class Xcls_drop : Object
        {
                public Gtk.DropTarget el;
@@ -956,7 +1068,7 @@ public class Xcls_WindowLeftTree : Object
                         
                                var is_shift = _this.keystate.is_shift > 0;
                                
-                               GLib.debug("shift is    %s", _this.keystate.is_shift > 0 ? "SHIFT" : "-");
+                               //GLib.debug("shift is    %s", _this.keystate.is_shift > 0 ? "SHIFT" : "-");
                                string pos; // over / before / after..
                        
                            //GLib.debug("got drag motion");
@@ -967,7 +1079,7 @@ public class Xcls_WindowLeftTree : Object
                                try {
                                        cont.get_value(ref v);
                                } catch (GLib.Error e) {
-                                   GLib.debug("failed to get drag value");
+                                  // GLib.debug("failed to get drag value");
                                        return Gdk.DragAction.COPY;      
                                
                                }
@@ -989,7 +1101,7 @@ public class Xcls_WindowLeftTree : Object
                             foreach(var dp in drop_on_to) {
                                str += dp;
                                }
-                               GLib.debug("droplist: %s", string.joinv(", ", str));
+                               //GLib.debug("droplist: %s", string.joinv(", ", str));
                             
                             
                            // if there are not items in the tree.. the we have to set isOver to true for anything..
@@ -1007,13 +1119,14 @@ public class Xcls_WindowLeftTree : Object
                            }
                            
                            
-                               GLib.debug("check is over");
+                       
                                 
                            // if path of source and dest are inside each other..
                            // need to add source info to drag?
                            // the fail();
                                var row = _this.view.getRowAt(x,y, out pos);
-                               
+                               //GLib.debug("check is over %d, %d, %s", (int)x,(int)y, pos);
+                       
                                if (row < 0) {
                                        this.addHighlight(null, "");    
                                        return Gdk.DragAction.COPY;
@@ -1022,20 +1135,20 @@ public class Xcls_WindowLeftTree : Object
                                
                                var node =  (JsRender.Node)tr.get_item();
                                
-                               GLib.debug("Drop over node: %s", node.fqn());
+                               //GLib.debug("Drop over node: %s", node.fqn());
                                
                        
                                if (pos == "above" || pos == "below") {
                                        if (node.parent == null) {
-                                               GLib.debug("no parent try center");
+                                               //GLib.debug("no parent try center");
                                                pos = "over";
                                        } else {
                                                 
                                                if (!drop_on_to.contains(node.parent.fqn())) {
-                                                       GLib.debug("drop on does not contain %s - try center" , node.parent.fqn());
+                                                       //GLib.debug("drop on does not contain %s - try center" , node.parent.fqn());
                                                        pos = "over";
                                                } else {
-                                                       GLib.debug("drop  contains %s - using %s" , node.parent.fqn(), pos);
+                                                       //GLib.debug("drop  contains %s - using %s" , node.parent.fqn(), pos);
                                                        if (_this.view.dragNode  != null && is_shift) {
                                                                if (node.parent.oid == _this.view.dragNode.oid || node.parent.has_parent(_this.view.dragNode)) {
                                                                        GLib.debug("shift drop not self not allowed");
@@ -1055,13 +1168,13 @@ public class Xcls_WindowLeftTree : Object
                                }
                                if (pos == "over") {
                                        if (!drop_on_to.contains(node.fqn())) {
-                                               GLib.debug("drop on does not contain %s - try center" , node.fqn());
+                                               //GLib.debug("drop on does not contain %s - try center" , node.fqn());
                                                this.addHighlight(null, ""); 
                                                return is_shift ?  Gdk.DragAction.MOVE :  Gdk.DragAction.COPY;          
                                        }
                                        if (_this.view.dragNode  != null && is_shift) {
                                                if (node.oid == _this.view.dragNode.oid || node.has_parent(_this.view.dragNode)) {
-                                                       GLib.debug("shift drop not self not allowed");
+                                                       //GLib.debug("shift drop not self not allowed");
                                                        this.addHighlight(null, "");
                                                        return Gdk.DragAction.COPY;     
                                                }
@@ -1081,11 +1194,14 @@ public class Xcls_WindowLeftTree : Object
                        });
                        this.el.drop.connect( (v, x, y) => {
                                
+                               // must get the pos before we clear the hightlihg.
+                               var pos = "";
+                               var row = _this.view.getRowAt(x,y, out pos);
                                this.addHighlight(null,"");
                         
                                var is_shift = _this.keystate.is_shift > 0;
                         
-                               var pos = "";
+                       
                                // -- get position..
                                if (this.lastDragString != v.get_string() || this.lastDragNode == null) {
                                        // still dragging same node
@@ -1097,7 +1213,10 @@ public class Xcls_WindowLeftTree : Object
                                     
                               
                            var dropNode = new JsRender.Node(); 
-                               dropNode.loadFromJsonString(v.get_string(), 1);
+                               dropNode.loadFromJsonString(v.get_string(), 2);
+                               GLib.debug("dropped node %s", dropNode.toJsonString());
+                               
+                               
                                var drop_on_to = _this.main_window.windowstate.file.palete().getDropList(dropNode.fqn());
                           
                            // if there are not items in the tree.. the we have to set isOver to true for anything..
@@ -1109,23 +1228,25 @@ public class Xcls_WindowLeftTree : Object
                                                return false;   
                                        }
                                        // add new node to top..
-                                       
+                                       GLib.debug("adding to top");
                                        
                                         var m = (GLib.ListStore) _this.model.el.model;
                                _this.main_window.windowstate.file.tree = dropNode;  
-                           
+                               dropNode.updated_count++;
                           
                                        m.append(dropNode);
                                        _this.model.selectNode(dropNode);       
                                        _this.changed();
+                                       _this.node_selected(dropNode);
                                        return true; // no need to highlight?
                             
                            }
                        
                        
                        
-                               var row = _this.view.getRowAt(x,y, out pos);
+                       
                                if (row < 0) {
+                                       GLib.debug("could not get row %d,%d, %s", (int)x,(int)y,pos);
                                        return   false; //Gdk.DragAction.COPY;
                                }
                                var tr = (Gtk.TreeListRow)_this.view.el.model.get_object(row);
@@ -1167,13 +1288,13 @@ public class Xcls_WindowLeftTree : Object
                                
                                switch(pos) {
                                        case "over":
-                                               node.appendChild(dropNode);
+                       
                                                if (is_shift && _this.view.dragNode != null) {
                                                        _this.model.selectNode(null); 
                                                        _this.view.dragNode.remove();
                                                }
-                                                       
-                                               
+                                               node.appendChild(dropNode);                     
+                                               dropNode.updated_count++;
                                                _this.model.selectNode(dropNode); 
                                                
                                                _this.changed();                                                
@@ -1182,12 +1303,13 @@ public class Xcls_WindowLeftTree : Object
                                        case "above":
                                                GLib.debug("Above - insertBefore");
                                        
-                                               node.parent.insertBefore(dropNode, node);
+                       
                                                if (is_shift && _this.view.dragNode != null) {
                                                        _this.model.selectNode(null);                   
                                                        _this.view.dragNode.remove();
                                                }
-                               
+                                               node.parent.insertBefore(dropNode, node);                       
+                                               dropNode.updated_count++;
                                                _this.model.selectNode(dropNode);                       
                                                _this.changed();
                                                return true;
@@ -1201,6 +1323,7 @@ public class Xcls_WindowLeftTree : Object
                                
                                                
                                                node.parent.insertAfter(dropNode, node);
+                                               dropNode.updated_count++;
                                                _this.model.selectNode(dropNode);       
                                                _this.changed();
                                                // select it
@@ -1223,7 +1346,7 @@ public class Xcls_WindowLeftTree : Object
                public void addHighlight (Gtk.Widget? w, string hl) {
                        if (this.highlightWidget != null) {
                                var ww  = this.highlightWidget;
-                               GLib.debug("clear drag from previous highlight");
+                               //GLib.debug("clear drag from previous highlight");
                                if (ww.has_css_class("drag-below")) {
                                         ww.remove_css_class("drag-below");
                                }
@@ -1235,7 +1358,7 @@ public class Xcls_WindowLeftTree : Object
                                }
                        }
                        if (w != null) {
-                               GLib.debug("add drag=%s to widget", hl);        
+                               //GLib.debug("add drag=%s to widget", hl);      
                                if (!w.has_css_class("drag-" + hl)) {
                                        w.add_css_class("drag-" + hl);
                                }
@@ -1263,6 +1386,7 @@ public class Xcls_WindowLeftTree : Object
                        // my vars (dec)
 
                        // set gobject values
+                       this.el.can_unselect = true;
 
                        //listeners
                        this.el.selection_changed.connect( (position, n_items) => {
@@ -1317,7 +1441,7 @@ public class Xcls_WindowLeftTree : Object
                                    // why dup_?
                                    
                        
-                                   GLib.debug ("calling left_tree.node_selected");
+                                   GLib.debug ("calling left_tree.node_selected %s", snode.toJsonString());
                                    _this.node_selected(snode);
                                   
                                     
@@ -1334,8 +1458,11 @@ public class Xcls_WindowLeftTree : Object
                public JsRender.Node? getSelectedNode () {
                  if (this.el.selected_item == null) {
                                return null;
-                 }                             
+                 }     
+                  
+                 
                   var tr = (Gtk.TreeListRow)this.el.selected_item;
+                 
                   return (JsRender.Node)tr.get_item();
                         
                }
@@ -1382,7 +1509,7 @@ public class Xcls_WindowLeftTree : Object
                    _this.main_window.windowstate.leftTreeNodeSelected(null);
                    // needed???
                    _this.main_window.windowstate.file = f;
-                   
+                   _this.last_error_counter = -1;
                   
                    if (f.tree == null) {
                            try {
@@ -1394,36 +1521,35 @@ public class Xcls_WindowLeftTree : Object
                    // if it's still null?
                    if (f.tree == null) {
                                _this.main_window.windowstate.showAddObject(_this.view.el, null);
-                   
+                       _this.updateErrors();
                        return;
                    }
                        m.append(f.tree);
-                       // expand???
-               
-               /*
-                   if (f.tree.readItems().size < 1) {
-                       // single item..
-                       
-                       //this.get('/Window.leftvpaned').el.set_position(80);
-                       // select first...
-                       _this.view.el.set_cursor( 
-                           new  Gtk.TreePath.from_string("0"), null, false);
-                       
-                       
-                   } else {
-                         //this.get('/Window.leftvpaned').el.set_position(200);
-                   }
-                 */  
-                   
-                   
-               
-                   //_this.maincol.el.set_max_width(_this.viewwin.el.get_allocated_width() - 32);
+                       _this.updateErrors();
                 
                    _this.selmodel.el.set_selected(Gtk.INVALID_LIST_POSITION);
                   
                    return;
                 
                            
+               }
+               public int nodeToRow (JsRender.Node node) 
+               {
+                
+                       var s = _this.view.el.model as Gtk.SingleSelection;
+                       for (var i = 0; i < s.n_items; i++) {
+                               //GLib.debug("check node %s", s.get_item(i).get_type().name());
+                               var lr = s.get_item(i) as Gtk.TreeListRow;
+                               //GLib.debug("check node %s", lr.get_item().get_type().name());
+                               var nn = (lr.get_item() as JsRender.Node);
+                               if (nn != null && nn.oid == node.oid) {
+                                       return i;
+                                       
+                               }
+                       }
+                       return -1;                      
+                       
+               
                }
                public void deleteSelected () {
                
@@ -1437,10 +1563,16 @@ public class Xcls_WindowLeftTree : Object
                             return;
                     }
                    _this.selmodel.el.unselect_all();
-                   
-                   node.remove();
-                       GLib.debug("delete Selected - done");
-                   _this.changed();
+                   if (node.parent != null) {
+                               node.remove();
+                               GLib.debug("delete Selected - done");
+                               _this.changed();
+                               return;
+                       }
+                       this.updateModel(null);
+                       _this.main_window.windowstate.file.tree = null;
+                       _this.changed();
+                       _this.node_selected(null);
                /*    
                    print("DELETE SELECTED?");
                    //_this.view.blockChanges = true;
@@ -1507,22 +1639,20 @@ public class Xcls_WindowLeftTree : Object
                        _this.selmodel.el.set_model(this.el);
                        return this.el;
                }
-               public void selectNode (JsRender.Node node) 
+               public void selectNode (JsRender.Node node) 
                {
-                       var row = -1;
-                       var s = (Gtk.SingleSelection)_this.view.el.model;
-                       for (var i = 0; i < s.n_items; i++) {
-                               //GLib.debug("check node %s", s.get_item(i).get_type().name());
-                               var lr = (Gtk.TreeListRow)s.get_item(i);
-                               GLib.debug("check node %s", lr.get_item().get_type().name());
-                               if (((JsRender.Node)lr.get_item()).oid == node.oid) {
-                                       row  = i;
-                                       break;
-                               }
+                       var s = _this.view.el.model as Gtk.SingleSelection;
+                       if (node == null) {
+                               s.selected=Gtk.INVALID_LIST_POSITION;
+                               return;
                        }
+                       var row = this.nodeToRow(node);
+               
+                        
                        if (row < 0) {
                                // select none?
                                GLib.debug("Could not find node");
+                               s.selected=Gtk.INVALID_LIST_POSITION;
                                return;
                        }
                        GLib.debug("Select %d", row);
@@ -1606,7 +1736,7 @@ public class Xcls_WindowLeftTree : Object
                                
                        });
                        this.el.bind.connect( (listitem) => {
-                                GLib.debug("listitme is is %s", ((Gtk.ListItem)listitem).get_type().name());
+                               // GLib.debug("listitme is is %s", ((Gtk.ListItem)listitem).get_type().name());
                                
                                //var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
                                var expand = (Gtk.TreeExpander)  ((Gtk.ListItem)listitem).get_child();
@@ -1620,8 +1750,10 @@ public class Xcls_WindowLeftTree : Object
                                
                                var lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();
                                var node = (JsRender.Node) lr.get_item();
-                               
-                          GLib.debug("node is %s", node.get_type().name());
+                               if (node == null || node.fqn() == "") {
+                                       return;
+                               }
+                          //GLib.debug("node is %s", node.get_type().name());
                        // was item (1) in old layout
                        
                                
@@ -1653,8 +1785,8 @@ public class Xcls_WindowLeftTree : Object
                            expand.set_hide_expander( !node.hasChildren() );
                                expand.set_list_row(lr);
                                
-                               node.bind_property("iconFilename",
-                                           img, "file",
+                               node.bind_property("iconResourceName",
+                                           img, "resource",
                                           GLib.BindingFlags.SYNC_CREATE);
                                
                                node.bind_property("nodeTitleProp",
@@ -1749,50 +1881,6 @@ public class Xcls_WindowLeftTree : Object
        }
 
 
-       public class Xcls_keystate : Object
-       {
-               public Gtk.EventControllerKey el;
-               private Xcls_WindowLeftTree  _this;
-
-
-                       // my vars (def)
-               public int is_shift;
-
-               // ctor
-               public Xcls_keystate(Xcls_WindowLeftTree _owner )
-               {
-                       _this = _owner;
-                       _this.keystate = this;
-                       this.el = new Gtk.EventControllerKey();
-
-                       // my vars (dec)
-                       this.is_shift = 0;
-
-                       // set gobject values
-
-                       //listeners
-                       this.el.key_released.connect( (keyval, keycode, state) => {
-                               GLib.debug("key release %d, %d, %d" , (int) keyval, (int)  keycode, state);
-                               if (keyval == Gdk.Key.Shift_L || keyval == Gdk.Key.Shift_R) {
-                                       this.is_shift = 0;
-                               }
-                               //GLib.debug("set state %d , shift = %d", (int)this.el.get_current_event_state(), Gdk.ModifierType.SHIFT_MASK);
-                       
-                       
-                        
-                       });
-                       this.el.key_pressed.connect( (keyval, keycode, state) => {
-                       
-                               if (keyval == Gdk.Key.Shift_L || keyval == Gdk.Key.Shift_R) {
-                                       this.is_shift = 1;
-                               }
-                               return true;
-                       });
-               }
-
-               // user defined functions
-       }
-
 
        public class Xcls_LeftTreeMenu : Object
        {
@@ -1812,13 +1900,14 @@ public class Xcls_WindowLeftTree : Object
                        // my vars (dec)
 
                        // set gobject values
-                       var child_1 = new Xcls_Box19( _this );
+                       var child_1 = new Xcls_Box18( _this );
+                       child_1.ref();
                        this.el.child = child_1.el;
                }
 
                // user defined functions
        }
-       public class Xcls_Box19 : Object
+       public class Xcls_Box18 : Object
        {
                public Gtk.Box el;
                private Xcls_WindowLeftTree  _this;
@@ -1827,7 +1916,7 @@ public class Xcls_WindowLeftTree : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_Box19(Xcls_WindowLeftTree _owner )
+               public Xcls_Box18(Xcls_WindowLeftTree _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
@@ -1835,20 +1924,20 @@ public class Xcls_WindowLeftTree : Object
                        // my vars (dec)
 
                        // set gobject values
-                       var child_1 = new Xcls_Button20( _this );
+                       var child_1 = new Xcls_Button19( _this );
                        child_1.ref();
                        this.el.append( child_1.el );
-                       var child_2 = new Xcls_Button21( _this );
+                       var child_2 = new Xcls_Button20( _this );
                        child_2.ref();
                        this.el.append( child_2.el );
-                       var child_3 = new Xcls_Button22( _this );
+                       var child_3 = new Xcls_Button21( _this );
                        child_3.ref();
                        this.el.append( child_3.el );
                }
 
                // user defined functions
        }
-       public class Xcls_Button20 : Object
+       public class Xcls_Button19 : Object
        {
                public Gtk.Button el;
                private Xcls_WindowLeftTree  _this;
@@ -1857,7 +1946,7 @@ public class Xcls_WindowLeftTree : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_Button20(Xcls_WindowLeftTree _owner )
+               public Xcls_Button19(Xcls_WindowLeftTree _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.Button();
@@ -1865,6 +1954,7 @@ public class Xcls_WindowLeftTree : Object
                        // my vars (dec)
 
                        // set gobject values
+                       this.el.has_frame = false;
                        this.el.label = "Delete Element";
 
                        //listeners
@@ -1878,7 +1968,7 @@ public class Xcls_WindowLeftTree : Object
                // user defined functions
        }
 
-       public class Xcls_Button21 : Object
+       public class Xcls_Button20 : Object
        {
                public Gtk.Button el;
                private Xcls_WindowLeftTree  _this;
@@ -1887,7 +1977,7 @@ public class Xcls_WindowLeftTree : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_Button21(Xcls_WindowLeftTree _owner )
+               public Xcls_Button20(Xcls_WindowLeftTree _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.Button();
@@ -1895,6 +1985,7 @@ public class Xcls_WindowLeftTree : Object
                        // my vars (dec)
 
                        // set gobject values
+                       this.el.has_frame = false;
                        this.el.label = "Save as Template";
 
                        //listeners
@@ -1913,7 +2004,7 @@ public class Xcls_WindowLeftTree : Object
                // user defined functions
        }
 
-       public class Xcls_Button22 : Object
+       public class Xcls_Button21 : Object
        {
                public Gtk.Button el;
                private Xcls_WindowLeftTree  _this;
@@ -1922,7 +2013,7 @@ public class Xcls_WindowLeftTree : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_Button22(Xcls_WindowLeftTree _owner )
+               public Xcls_Button21(Xcls_WindowLeftTree _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.Button();
@@ -1930,6 +2021,7 @@ public class Xcls_WindowLeftTree : Object
                        // my vars (dec)
 
                        // set gobject values
+                       this.el.has_frame = false;
                        this.el.label = "Save as Module";
 
                        //listeners