Fix #8062 - fix new file node selection issue
[roobuilder] / src / Builder4 / WindowLeftProps.vala
index 0a7f04d..1200d93 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");
             
        }
@@ -299,7 +287,7 @@ public class Xcls_LeftProps : Object
                
            }
            
-           GLib.debug("load leftprops\n");
+           GLib.debug("load leftprops");
        
            this.node = node;
            this.file = file;
@@ -309,6 +297,7 @@ public class Xcls_LeftProps : Object
                      
            //this.get('/RightEditor').el.hide();
            if (node ==null) {
+               GLib.debug("node is null return");
                return ;
            }
        
@@ -508,6 +497,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 +594,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 +659,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 +727,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 +793,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 +858,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 +946,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 +1009,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 +1073,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 +1159,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 +1223,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 +1285,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 +1369,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 +1433,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 +1498,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
@@ -1629,13 +1633,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) {
                                         
                                           
@@ -1653,12 +1657,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;
                
                 }
@@ -1710,6 +1714,9 @@ public class Xcls_LeftProps : Object
                                }
                                if (l.get_visible()) {
                                        _this.stop_editor();
+                                       if (prop.parent == null) {
+                                               return;
+                                       }
                                _this.show_editor(_this.file, prop.parent, prop);
                                
                                }
@@ -1822,6 +1829,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;
                }
 
@@ -1871,6 +1879,7 @@ public class Xcls_LeftProps : Object
                        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
@@ -2176,7 +2185,9 @@ public class Xcls_LeftProps : Object
                         var lb = (Gtk.Label) ((Gtk.ListItem)listitem).get_child();
                         var item = (JsRender.NodeProp) ((Gtk.ListItem)listitem).get_item();
                        
-                       
+                        if (item == null) {
+                               return;
+                       }
                        item.bind_property("to_display_name_prop",
                                            lb, "label",
                                           GLib.BindingFlags.SYNC_CREATE);
@@ -2344,6 +2355,15 @@ public class Xcls_LeftProps : Object
                                cb.hide();
                                
                                var prop = (JsRender.NodeProp) ((Gtk.ListItem)listitem).get_item();
+                               if (prop == null || _this.node == null ) {
+                                       GLib.error("something is wrong");
+                                        
+                               }
+                               if ( _this.node.fqn() == "") {
+                                       GLib.debug("node is missing fqn");
+                                       return;
+                               }
+                               
                                //GLib.debug("prop = %s", prop.get_type().name());
                                //GLib.debug("prop.val = %s", prop.val);
                                //GLib.debug("prop.key = %s", prop.to_display_name());
@@ -2353,8 +2373,11 @@ public class Xcls_LeftProps : Object
                            
                            var pal = _this.file.project.palete;
                                
-                           string[] opts;
-                           var has_opts = pal.typeOptions(_this.node.fqn(), prop.name, prop.rtype, out opts);
+                           string[] opts = {};
+                         
+                           var has_opts = prop.ptype.can_have_opt_list() ? 
+                               pal.typeOptions(_this.node.fqn(), prop.name, prop.rtype, out opts)
+                               : false;
                            
                            if (!has_opts && prop.ptype == JsRender.NodePropType.RAW) {
                                use_textarea = true;
@@ -2439,6 +2462,7 @@ public class Xcls_LeftProps : Object
 
                        // set gobject values
                        var child_1 = new Xcls_Box54( _this );
+                       child_1.ref();
                        this.el.child = child_1.el;
                }