Fix #8003 - undo code
[roobuilder] / src / Builder4 / WindowLeftTree.vala
index 6c61cf5..e486653 100644 (file)
@@ -14,16 +14,16 @@ 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);
@@ -51,9 +51,16 @@ 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.size < 1) {
-                       this.removeErrors();
+               if (ar == null || ar.size < 1) {
+                       if (this.last_error_counter != file.error_counter) {
+                               this.removeErrors();
+                       }
+               
                        this.last_error_counter = file.error_counter ;
        
                        return;
@@ -109,7 +116,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) {
                                
@@ -125,17 +132,17 @@ public class Xcls_WindowLeftTree : Object
                         
                                
                                reading_header = false;
-                                
+                                continue;
                    }
                    
-                       if (!child.has_css_class("node-err")) {
+                       if (child.has_css_class("node-err")) {
                                child.remove_css_class("node-err");
                        }
-                       if (!child.has_css_class("node-warn")) {
+                       if (child.has_css_class("node-warn")) {
                                child.remove_css_class("node-warn");
                        }
                        
-                       if (!child.has_css_class("node-depr")) {
+                       if (child.has_css_class("node-depr")) {
                                child.remove_css_class("node-depr");
                        }
                        
@@ -275,15 +282,15 @@ public class Xcls_WindowLeftTree : Object
                        var child_5 = new Xcls_EventControllerKey9( _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_ColumnViewColumn16( _this );
+                       child_9.ref();
+                       this.el.append_column ( child_9.el  );
 
                        // init method
 
@@ -365,7 +372,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) {
                                                
@@ -381,7 +388,7 @@ public class Xcls_WindowLeftTree : Object
                                         
                                                
                                                reading_header = false;
-                                                
+                                               continue;
                                    }
                                    
                                  
@@ -398,36 +405,36 @@ 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) {
@@ -447,7 +454,7 @@ public class Xcls_WindowLeftTree : Object
                        */
                                 
                                
-                               //GLib.debug("offset = %d  y = %d", (int) voff, (int) in_y);
+                               GLib.debug("get Widget At Row x = %d  y = %d", (int) x, (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 };
@@ -469,10 +476,11 @@ public class Xcls_WindowLeftTree : Object
                                                }
                                                // should be columnlistview
                                                child = child.get_first_child(); 
-                                           GLib.debug("header height=%d", h);
+                                           //GLib.debug("header height=%d", h);
                                                header_height =  h;
                                                
                                                reading_header = false;
+                                               continue;
                                                
                                }
                                
@@ -487,6 +495,13 @@ public class Xcls_WindowLeftTree : Object
                                    
                                    line_no++;
                                        var hh = child.get_height();
+                                       
+                                       if (child.has_css_class("node-err") || 
+                                               child.has_css_class("node-warn") || 
+                                               child.has_css_class("node-depr")) {
+                                               hh += 10;
+                                       
+                                       }
                                        //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),
@@ -550,7 +565,7 @@ public class Xcls_WindowLeftTree : Object
                                                header_height =  h;
                                                
                                                reading_header = false;
-                                               
+                                               continue;
                                }
                                    line_no++;
                
@@ -560,7 +575,12 @@ public class Xcls_WindowLeftTree : Object
                
                                        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 (child.has_css_class("node-err") || 
+                                               child.has_css_class("node-warn") || 
+                                               child.has_css_class("node-depr")) {
+                                               hh += 10;
+                                       
+                                       }       
                                    if (y > curr_y && y <= header_height + hh + curr_y ) {
                                            return (Gtk.Widget)child;
                                    }
@@ -703,6 +723,8 @@ public class Xcls_WindowLeftTree : Object
                                GLib.warning("No node found at row %d", row);
                                return;
                                }
+                               
+                               
                                _this.model.selectNode(node);
                             
                             
@@ -856,6 +878,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;
@@ -1229,7 +1295,7 @@ public class Xcls_WindowLeftTree : Object
                                        
                                         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);       
@@ -1289,7 +1355,7 @@ public class Xcls_WindowLeftTree : Object
                                                        _this.view.dragNode.remove();
                                                }
                                                        
-                                               
+                                               dropNode.updated_count++;
                                                _this.model.selectNode(dropNode); 
                                                
                                                _this.changed();                                                
@@ -1303,7 +1369,7 @@ public class Xcls_WindowLeftTree : Object
                                                        _this.model.selectNode(null);                   
                                                        _this.view.dragNode.remove();
                                                }
-                               
+                                               dropNode.updated_count++;
                                                _this.model.selectNode(dropNode);                       
                                                _this.changed();
                                                return true;
@@ -1317,6 +1383,7 @@ public class Xcls_WindowLeftTree : Object
                                
                                                
                                                node.parent.insertAfter(dropNode, node);
+                                               dropNode.updated_count++;
                                                _this.model.selectNode(dropNode);       
                                                _this.changed();
                                                // select it
@@ -1529,7 +1596,7 @@ public class Xcls_WindowLeftTree : Object
                        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());
+                               //GLib.debug("check node %s", lr.get_item().get_type().name());
                                if ((lr.get_item() as JsRender.Node).oid == node.oid) {
                                        return i;
                                        
@@ -1654,7 +1721,7 @@ public class Xcls_WindowLeftTree : Object
                {
                        _this = _owner;
                        _this.maincol = this;
-                       var child_1 = new Xcls_SignalListItemFactory14( _this );
+                       var child_1 = new Xcls_SignalListItemFactory15( _this );
                        child_1.ref();
                        this.el = new Gtk.ColumnViewColumn( "Property", child_1.el );
 
@@ -1668,7 +1735,7 @@ public class Xcls_WindowLeftTree : Object
 
                // user defined functions
        }
-       public class Xcls_SignalListItemFactory14 : Object
+       public class Xcls_SignalListItemFactory15 : Object
        {
                public Gtk.SignalListItemFactory el;
                private Xcls_WindowLeftTree  _this;
@@ -1677,7 +1744,7 @@ public class Xcls_WindowLeftTree : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_SignalListItemFactory14(Xcls_WindowLeftTree _owner )
+               public Xcls_SignalListItemFactory15(Xcls_WindowLeftTree _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.SignalListItemFactory();
@@ -1778,7 +1845,7 @@ public class Xcls_WindowLeftTree : Object
        }
 
 
-       public class Xcls_ColumnViewColumn15 : Object
+       public class Xcls_ColumnViewColumn16 : Object
        {
                public Gtk.ColumnViewColumn el;
                private Xcls_WindowLeftTree  _this;
@@ -1787,10 +1854,10 @@ public class Xcls_WindowLeftTree : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_ColumnViewColumn15(Xcls_WindowLeftTree _owner )
+               public Xcls_ColumnViewColumn16(Xcls_WindowLeftTree _owner )
                {
                        _this = _owner;
-                       var child_1 = new Xcls_SignalListItemFactory16( _this );
+                       var child_1 = new Xcls_SignalListItemFactory17( _this );
                        child_1.ref();
                        this.el = new Gtk.ColumnViewColumn( "Add", child_1.el );
 
@@ -1802,7 +1869,7 @@ public class Xcls_WindowLeftTree : Object
 
                // user defined functions
        }
-       public class Xcls_SignalListItemFactory16 : Object
+       public class Xcls_SignalListItemFactory17 : Object
        {
                public Gtk.SignalListItemFactory el;
                private Xcls_WindowLeftTree  _this;
@@ -1811,7 +1878,7 @@ public class Xcls_WindowLeftTree : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_SignalListItemFactory16(Xcls_WindowLeftTree _owner )
+               public Xcls_SignalListItemFactory17(Xcls_WindowLeftTree _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.SignalListItemFactory();
@@ -1855,50 +1922,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
        {