Fix #8032 - speed up add remove of errors from tree
[roobuilder] / src / Builder4 / WindowLeftProps.vala
index 249eda5..16720bc 100644 (file)
@@ -33,6 +33,7 @@ public class Xcls_LeftProps : Object
        public JsRender.JsRender file;
        public JsRender.Node node;
        public signal void show_editor (JsRender.JsRender file, JsRender.Node node, JsRender.NodeProp prop);
+       public Gee.ArrayList<Gtk.Widget>? error_widgets;
 
        // ctor
        public Xcls_LeftProps()
@@ -45,6 +46,7 @@ public class Xcls_LeftProps : Object
                this.allow_edit = false;
                this.main_window = null;
                this.last_error_counter = -1;
+               this.error_widgets = null;
 
                // set gobject values
                this.el.homogeneous = false   ;
@@ -105,17 +107,19 @@ public class Xcls_LeftProps : Object
                        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 || node.oid != this.node.oid) {
+                   var node = file.lineToNode( (int)diag.range.start.line) ;
+                   if (node == null || this.node == null || node.oid != this.node.oid) {
                        continue;
                }
                var prop = node.lineToProp( (int)diag.range.start.line) ;
-               
+               if (prop == null) {
+                       continue;
+                       }
                var row = _this.selmodel.propToRow(prop);
                if (row < 0) {
                        continue;
@@ -124,10 +128,13 @@ public class Xcls_LeftProps : Object
                if (w == null) {
                        return;
                        }
-                               var ed = diag.category.down();
+       
+                       
+                       var ed = diag.category.down();
                        if (ed != "err" && w.has_css_class("node-err")) {
                                continue;
                        }
+                       this.error_widgets.add(w);              
                        if (ed == "err" && w.has_css_class("node-warn")) {
                                w.remove_css_class("node-warn");
                        }
@@ -243,31 +250,12 @@ public class Xcls_LeftProps : Object
                */
        }
        public void removeErrors () {
-               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")) {
+                       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")) {
@@ -277,9 +265,9 @@ public class Xcls_LeftProps : Object
                        if (child.has_css_class("node-depr")) {
                                child.remove_css_class("node-depr");
                        }
-                       
-               child = child.get_next_sibling(); 
                }
+               this.error_widgets  = null;
+               return;
                //GLib.debug("Rturning null");
             
        }
@@ -508,6 +496,7 @@ public class Xcls_LeftProps : Object
 
                        // set gobject values
                        var child_1 = new Xcls_Box7( _this );
+                       child_1.ref();
                        this.el.child = child_1.el;
                }
 
@@ -604,6 +593,7 @@ public class Xcls_LeftProps : Object
                        // set gobject values
                        this.el.has_frame = false;
                        var child_1 = new Xcls_Label9( _this );
+                       child_1.ref();
                        this.el.child = child_1.el;
 
                        //listeners
@@ -668,6 +658,7 @@ public class Xcls_LeftProps : Object
                        // set gobject values
                        this.el.has_frame = false;
                        var child_1 = new Xcls_Label11( _this );
+                       child_1.ref();
                        this.el.child = child_1.el;
 
                        //listeners
@@ -735,6 +726,7 @@ public class Xcls_LeftProps : Object
                        // set gobject values
                        this.el.has_frame = false;
                        var child_1 = new Xcls_Label13( _this );
+                       child_1.ref();
                        this.el.child = child_1.el;
 
                        //listeners
@@ -800,6 +792,7 @@ public class Xcls_LeftProps : Object
                        // set gobject values
                        this.el.has_frame = false;
                        var child_1 = new Xcls_Label15( _this );
+                       child_1.ref();
                        this.el.child = child_1.el;
 
                        //listeners
@@ -864,6 +857,7 @@ public class Xcls_LeftProps : Object
                        // set gobject values
                        this.el.has_frame = false;
                        var child_1 = new Xcls_Label17( _this );
+                       child_1.ref();
                        this.el.child = child_1.el;
 
                        //listeners
@@ -951,6 +945,7 @@ public class Xcls_LeftProps : Object
                        // set gobject values
                        this.el.has_frame = false;
                        var child_1 = new Xcls_Label20( _this );
+                       child_1.ref();
                        this.el.child = child_1.el;
 
                        //listeners
@@ -1013,6 +1008,7 @@ public class Xcls_LeftProps : Object
                        // set gobject values
                        this.el.has_frame = false;
                        var child_1 = new Xcls_Label22( _this );
+                       child_1.ref();
                        this.el.child = child_1.el;
 
                        //listeners
@@ -1076,6 +1072,7 @@ public class Xcls_LeftProps : Object
                        // set gobject values
                        this.el.has_frame = false;
                        var child_1 = new Xcls_Label24( _this );
+                       child_1.ref();
                        this.el.child = child_1.el;
 
                        //listeners
@@ -1161,6 +1158,7 @@ public class Xcls_LeftProps : Object
                        // set gobject values
                        this.el.has_frame = false;
                        var child_1 = new Xcls_Label27( _this );
+                       child_1.ref();
                        this.el.child = child_1.el;
 
                        //listeners
@@ -1224,6 +1222,7 @@ public class Xcls_LeftProps : Object
                        // set gobject values
                        this.el.has_frame = false;
                        var child_1 = new Xcls_Label29( _this );
+                       child_1.ref();
                        this.el.child = child_1.el;
 
                        //listeners
@@ -1285,6 +1284,7 @@ public class Xcls_LeftProps : Object
                        // set gobject values
                        this.el.has_frame = false;
                        var child_1 = new Xcls_Label31( _this );
+                       child_1.ref();
                        this.el.child = child_1.el;
 
                        //listeners
@@ -1368,6 +1368,7 @@ public class Xcls_LeftProps : Object
                        // set gobject values
                        this.el.has_frame = false;
                        var child_1 = new Xcls_Label34( _this );
+                       child_1.ref();
                        this.el.child = child_1.el;
 
                        //listeners
@@ -1431,6 +1432,7 @@ public class Xcls_LeftProps : Object
                        // set gobject values
                        this.el.has_frame = false;
                        var child_1 = new Xcls_Label36( _this );
+                       child_1.ref();
                        this.el.child = child_1.el;
 
                        //listeners
@@ -1495,6 +1497,7 @@ public class Xcls_LeftProps : Object
                        this.el.has_frame = false;
                        this.el.tooltip_markup = "Add a flexy include (for HTML templates)";
                        var child_1 = new Xcls_Label38( _this );
+                       child_1.ref();
                        this.el.child = child_1.el;
 
                        //listeners
@@ -1584,7 +1587,6 @@ public class Xcls_LeftProps : Object
 
 
                        // my vars (def)
-               public Gtk.CssProvider css;
                public Xcls_PopoverProperty popover;
 
                // ctor
@@ -1605,10 +1607,10 @@ public class Xcls_LeftProps : Object
                        this.el.vexpand = true;
                        this.el.show_row_separators = true;
                        new Xcls_deletemenu( _this );
-                       var child_3 = new Xcls_GestureClick44( _this );
+                       var child_3 = new Xcls_GestureClick45( _this );
                        child_3.ref();
                        this.el.add_controller(  child_3.el );
-                       var child_4 = new Xcls_GestureClick45( _this );
+                       var child_4 = new Xcls_GestureClick46( _this );
                        child_4.ref();
                        this.el.add_controller(  child_4.el );
                        new Xcls_keycol( _this );
@@ -1616,41 +1618,6 @@ public class Xcls_LeftProps : Object
                        new Xcls_valcol( _this );
                        this.el.append_column ( _this.valcol.el  );
                        new Xcls_ContextMenu( _this );
-
-                       // init method
-
-                       {
-                        
-                               this.css = new Gtk.CssProvider();
-                                
-                                       this.css.load_from_string("
-                       #leftprops-view { font-size: 12px;}
-                                
-                       #leftprops-view  dropdown button { 
-                                               min-height: 16px;                        
-                                               outline-offset : 0;
-                                       }
-                       #leftprops-view cell dropdown label  {
-                                       padding-top:0px;
-                                       padding-bottom:0px;
-                       }
-                       #leftprops-view cell   { 
-                                       padding-top:2px;
-                                       padding-bottom:2px;
-                                       }
-                       #leftprops-view cell label,  #leftprops-view cell editablelable {
-                                       padding-top:4px;
-                                       padding-bottom:4px;
-                       }");
-                        
-                                       Gtk.StyleContext.add_provider_for_display(
-                                       this.el.get_display(),
-                                       this.css,
-                                       Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
-                               );
-                                       
-                          
-                       }
                }
 
                // user defined functions
@@ -1665,13 +1632,13 @@ public class Xcls_LeftProps : Object
                                 
                        }
                        */
-                               GLib.debug("Get Widget At Row %d", (int)row);
+                               //GLib.debug("Get Widget At Row %d", (int)row);
                        var  child = this.el.get_first_child(); 
                        var line_no = -1; 
                        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) {
                                         
                                           
@@ -1689,12 +1656,12 @@ public class Xcls_LeftProps : Object
                                    }
                                    line_no++;
                                        if (line_no == row) {
-                                               GLib.debug("Returning widget %s", child.get_type().name());
+                                               //GLib.debug("Returning widget %s", child.get_type().name());
                                            return (Gtk.Widget)child;
                                    }
                                child = child.get_next_sibling(); 
                        }
-                               GLib.debug("Rturning null");
+                               //GLib.debug("Rturning null");
                        return null;
                
                 }
@@ -1792,97 +1759,51 @@ public class Xcls_LeftProps : Object
                        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.EditProps.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;
-                                               continue;
-                               }
-                               
-                                   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();
-                                       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),
-                                       
-                                       //      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 class Xcls_deletemenu : Object
@@ -1904,6 +1825,7 @@ public class Xcls_LeftProps : Object
 
                        // set gobject values
                        var child_1 = new Xcls_Box42( _this );
+                       child_1.ref();
                        this.el.child = child_1.el;
                }
 
@@ -1950,7 +1872,11 @@ public class Xcls_LeftProps : Object
                        // my vars (dec)
 
                        // set gobject values
+                       this.el.has_frame = false;
                        this.el.label = "Delete";
+                       var child_1 = new Xcls_Label44( _this );
+                       child_1.ref();
+                       this.el.child = child_1.el;
 
                        //listeners
                        this.el.clicked.connect( ( ) => {
@@ -1965,10 +1891,33 @@ public class Xcls_LeftProps : Object
 
                // user defined functions
        }
+       public class Xcls_Label44 : Object
+       {
+               public Gtk.Label el;
+               private Xcls_LeftProps  _this;
+
+
+                       // my vars (def)
+
+               // ctor
+               public Xcls_Label44(Xcls_LeftProps _owner )
+               {
+                       _this = _owner;
+                       this.el = new Gtk.Label( "Delete Property / Method" );
+
+                       // my vars (dec)
+
+                       // set gobject values
+                       this.el.halign = Gtk.Align.START;
+               }
+
+               // user defined functions
+       }
 
 
 
-       public class Xcls_GestureClick44 : Object
+
+       public class Xcls_GestureClick45 : Object
        {
                public Gtk.GestureClick el;
                private Xcls_LeftProps  _this;
@@ -1977,7 +1926,7 @@ public class Xcls_LeftProps : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_GestureClick44(Xcls_LeftProps _owner )
+               public Xcls_GestureClick45(Xcls_LeftProps _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.GestureClick();
@@ -2025,7 +1974,7 @@ public class Xcls_LeftProps : Object
                // user defined functions
        }
 
-       public class Xcls_GestureClick45 : Object
+       public class Xcls_GestureClick46 : Object
        {
                public Gtk.GestureClick el;
                private Xcls_LeftProps  _this;
@@ -2034,7 +1983,7 @@ public class Xcls_LeftProps : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_GestureClick45(Xcls_LeftProps _owner )
+               public Xcls_GestureClick46(Xcls_LeftProps _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.GestureClick();
@@ -2177,7 +2126,7 @@ public class Xcls_LeftProps : Object
                {
                        _this = _owner;
                        _this.keycol = this;
-                       var child_1 = new Xcls_SignalListItemFactory49( _this );
+                       var child_1 = new Xcls_SignalListItemFactory50( _this );
                        child_1.ref();
                        this.el = new Gtk.ColumnViewColumn( "Property", child_1.el );
 
@@ -2191,7 +2140,7 @@ public class Xcls_LeftProps : Object
 
                // user defined functions
        }
-       public class Xcls_SignalListItemFactory49 : Object
+       public class Xcls_SignalListItemFactory50 : Object
        {
                public Gtk.SignalListItemFactory el;
                private Xcls_LeftProps  _this;
@@ -2200,7 +2149,7 @@ public class Xcls_LeftProps : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_SignalListItemFactory49(Xcls_LeftProps _owner )
+               public Xcls_SignalListItemFactory50(Xcls_LeftProps _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.SignalListItemFactory();
@@ -2262,7 +2211,7 @@ public class Xcls_LeftProps : Object
                {
                        _this = _owner;
                        _this.valcol = this;
-                       var child_1 = new Xcls_SignalListItemFactory51( _this );
+                       var child_1 = new Xcls_SignalListItemFactory52( _this );
                        child_1.ref();
                        this.el = new Gtk.ColumnViewColumn( "Value", child_1.el );
 
@@ -2276,7 +2225,7 @@ public class Xcls_LeftProps : Object
 
                // user defined functions
        }
-       public class Xcls_SignalListItemFactory51 : Object
+       public class Xcls_SignalListItemFactory52 : Object
        {
                public Gtk.SignalListItemFactory el;
                private Xcls_LeftProps  _this;
@@ -2286,7 +2235,7 @@ public class Xcls_LeftProps : Object
                public bool is_setting;
 
                // ctor
-               public Xcls_SignalListItemFactory51(Xcls_LeftProps _owner )
+               public Xcls_SignalListItemFactory52(Xcls_LeftProps _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.SignalListItemFactory();
@@ -2494,13 +2443,14 @@ public class Xcls_LeftProps : Object
                        // my vars (dec)
 
                        // set gobject values
-                       var child_1 = new Xcls_Box53( _this );
+                       var child_1 = new Xcls_Box54( _this );
+                       child_1.ref();
                        this.el.child = child_1.el;
                }
 
                // user defined functions
        }
-       public class Xcls_Box53 : Object
+       public class Xcls_Box54 : Object
        {
                public Gtk.Box el;
                private Xcls_LeftProps  _this;
@@ -2509,7 +2459,7 @@ public class Xcls_LeftProps : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_Box53(Xcls_LeftProps _owner )
+               public Xcls_Box54(Xcls_LeftProps _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
@@ -2517,14 +2467,14 @@ public class Xcls_LeftProps : Object
                        // my vars (dec)
 
                        // set gobject values
-                       var child_1 = new Xcls_Button54( _this );
+                       var child_1 = new Xcls_Button55( _this );
                        child_1.ref();
                        this.el.append( child_1.el );
                }
 
                // user defined functions
        }
-       public class Xcls_Button54 : Object
+       public class Xcls_Button55 : Object
        {
                public Gtk.Button el;
                private Xcls_LeftProps  _this;
@@ -2533,7 +2483,7 @@ public class Xcls_LeftProps : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_Button54(Xcls_LeftProps _owner )
+               public Xcls_Button55(Xcls_LeftProps _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.Button();