Fix #7302 - Consolidate tree node adding
authorAlan <alan@roojs.com>
Thu, 7 Jul 2022 05:12:57 +0000 (13:12 +0800)
committerAlan <alan@roojs.com>
Thu, 7 Jul 2022 05:12:57 +0000 (13:12 +0800)
src/Builder4/GladeView.bjs
src/Builder4/GladeView.vala
src/Builder4/WindowLeftTree.bjs
src/Builder4/WindowLeftTree.vala

index 7d66ea3..2843f78 100644 (file)
@@ -15,6 +15,7 @@
        "* prop" : "image",
        "bool has_default" : true,
        "int icon_size" : 33,
+       "string icon_name" : "\"\"",
        "xtype" : "Image"
       }
      ],
          "string label" : "xxxcc",
          "xtype" : "Button"
         },
+        {
+         "$ xns" : "Gtk",
+         "string label" : "xxxcc",
+         "xtype" : "Button"
+        },
         {
          "$ xns" : "Gtk",
          "string label" : "xxxcc",
         }
        ],
        "xtype" : "ButtonBox"
+      },
+      {
+       "$ xns" : "Gtk",
+       "* prop" : "_menu",
+       "xtype" : "Menu"
+      },
+      {
+       "$ xns" : "Gtk",
+       "bool has_entry" : false,
+       "xtype" : "ComboBox"
+      },
+      {
+       "$ xns" : "Gtk",
+       "xtype" : "GLArea"
       }
      ],
      "xtype" : "Box"
index 273e2e0..f4ad1c3 100644 (file)
@@ -76,6 +76,7 @@ public class GladeView : Object
 
             // set gobject values
             this.el.has_default = true;
+            this.el.icon_name = "\"\"";
             this.el.halign = Gtk.Align.CENTER;
             this.el.icon_size = 33;
         }
@@ -104,6 +105,15 @@ public class GladeView : Object
             var child_0 = new Xcls_ButtonBox5( _this );
             child_0.ref();
             this.el.add(  child_0.el );
+            var child_1 = new Xcls_Menu9( _this );
+            child_1.ref();
+            this.el._menu = child_1.el;
+            var child_2 = new Xcls_ComboBox10( _this );
+            child_2.ref();
+            this.el.add(  child_2.el );
+            var child_3 = new Xcls_GLArea11( _this );
+            child_3.ref();
+            this.el.add(  child_3.el );
         }
 
         // user defined functions
@@ -131,6 +141,9 @@ public class GladeView : Object
             var child_1 = new Xcls_Button7( _this );
             child_1.ref();
             this.el.add(  child_1.el );
+            var child_2 = new Xcls_Button8( _this );
+            child_2.ref();
+            this.el.add(  child_2.el );
         }
 
         // user defined functions
@@ -181,6 +194,96 @@ public class GladeView : Object
         // user defined functions
     }
 
+    public class Xcls_Button8 : Object
+    {
+        public Gtk.Button el;
+        private GladeView  _this;
+
+
+            // my vars (def)
+
+        // ctor
+        public Xcls_Button8(GladeView _owner )
+        {
+            _this = _owner;
+            this.el = new Gtk.Button();
+
+            // my vars (dec)
+
+            // set gobject values
+            this.el.label = "xxxcc";
+        }
+
+        // user defined functions
+    }
+
+
+    public class Xcls_Menu9 : Object
+    {
+        public Gtk.Menu el;
+        private GladeView  _this;
+
+
+            // my vars (def)
+
+        // ctor
+        public Xcls_Menu9(GladeView _owner )
+        {
+            _this = _owner;
+            this.el = new Gtk.Menu();
+
+            // my vars (dec)
+
+            // set gobject values
+        }
+
+        // user defined functions
+    }
+
+    public class Xcls_ComboBox10 : Object
+    {
+        public Gtk.ComboBox el;
+        private GladeView  _this;
+
+
+            // my vars (def)
+
+        // ctor
+        public Xcls_ComboBox10(GladeView _owner )
+        {
+            _this = _owner;
+            this.el = new Gtk.ComboBox();
+
+            // my vars (dec)
+
+            // set gobject values
+            this.el.has_entry = false;
+        }
+
+        // user defined functions
+    }
+
+    public class Xcls_GLArea11 : Object
+    {
+        public Gtk.GLArea el;
+        private GladeView  _this;
+
+
+            // my vars (def)
+
+        // ctor
+        public Xcls_GLArea11(GladeView _owner )
+        {
+            _this = _owner;
+            this.el = new Gtk.GLArea();
+
+            // my vars (dec)
+
+            // set gobject values
+        }
+
+        // user defined functions
+    }
 
 
 }
index 7b1ed40..140242b 100644 (file)
           "        _this.main_window.windowstate.file.palete().on_child_added(parentNode,node);",
           "            ",
           "          ",
-          "        ",
+          "        this.iterSetValues(n_iter, node);",
           "        // add the node...",
-          "        ",
-          "        this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1  );",
-          "        var o =   GLib.Value(typeof(Object));",
-          "        o.set_object((Object)node);",
-          "        ",
-          "        this.el.set_value(n_iter, 2, o);",
-          "        ",
-          "        ",
+          "         ",
           "        ",
           "        ",
           "\t\t// load children - if it has any..",
           "}",
           ""
          ],
+         "| void iterSetValues" : [
+          "(Gtk.TreeIter iter, JsRender.Node node)   {",
+          "\tvar ic = Gtk.IconTheme.get_default();",
+          "    Gdk.Pixbuf pix;",
+          "    ",
+          "    var o =   GLib.Value(typeof(Object));",
+          "    o.set_object((Object)node);",
+          "    var clsname = node.fqn();",
+          "    ",
+          "    var clsb = clsname.split(\".\");",
+          "    var sub = clsb.length > 1 ? clsb[1].down()  : \"\";",
+          "    ",
+          "   ",
+          "    var fn = \"/usr/share/glade/pixmaps/hicolor/16x16/actions/widget-gtk-\" + sub + \".png\";",
+          "    if (FileUtils.test (fn, FileTest.IS_REGULAR)) {",
+          "        pix = new Gdk.Pixbuf.from_file (fn);",
+          "    } else {",
+          "    \tpix = ic.load_icon(\"emblem-new\", 16,0);",
+          "    }",
+          "    ",
+          "    this.el.set(",
+          "    \t\titer, ",
+          "    \t\t0, node.nodeTitle(),",
+          "            1, node.nodeTip(), ",
+          "            -1",
+          "    );",
+          "    this.el.set_value(iter, 2,o);",
+          "    this.el.set_value(iter, 3,pix);    ",
+          "",
+          "    ",
+          "",
+          "}"
+         ],
          "| void load" : [
           "(Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter) ",
           "{",
           "    Gtk.TreeIter citer;",
           "    //this.insert(citer,iter,0);",
-          "    var ic = Gtk.IconTheme.get_default();",
-          "    var pixdef = ic.load_icon(\"emblem-new\", 16,0);",
+          "   ",
           "    ",
           "    for(var i =0 ; i < tr.size; i++) {",
           "        if (iter != null) {",
           "        } else {",
           "            this.el.append(out citer,null);",
           "        }",
+          "        this.iterSetValues(citer, tr.get(i));",
           "        ",
-          "        this.el.set(citer, 0, tr.get(i).nodeTitle(),",
-          "                1, tr.get(i).nodeTip(), -1",
-          "        );",
-          "        var o =   GLib.Value(typeof(Object));",
-          "        o.set_object((Object)tr.get(i));",
-          "        ",
-          "        this.el.set_value(citer, 2, o);",
-          "        ",
-          "        var clsname = tr.get(i).fqn();",
-          "        ",
-          "        var clsb = clsname.split(\".\");",
-          "        var sub = clsb.length > 1 ? clsb[1].down()  : \"\";",
-          "        ",
-          "        var pix = pixdef;",
-          "        var fn = \"/usr/share/glade/pixmaps/hicolor/16x16/actions/widget-gtk-\" + sub + \".png\";",
-          "        if (FileUtils.test (fn, FileTest.IS_REGULAR)) {",
-          "\t        pix = new Gdk.Pixbuf.from_file (fn);",
-          "        }",
-          "        ",
-          "        ",
-          "        this.el.set_value(citer, 3,   pix );",
-          "        ",
-          "        ",
-          "        ",
-          "        ",
-          "        ",
+          " ",
+          "         ",
           "        if (tr.get(i).items.size > 0) {",
           "            this.load(tr.get(i).items, citer);",
           "        }",
          "items" : [
           {
            "$ xns" : "Gtk",
-           "* pack" : "pack_start,true",
+           "* pack" : "pack_start,false",
            "id" : "iconrender",
+           "int width" : 16,
            "xtype" : "CellRendererPixbuf"
           },
           {
index ebee1ee..34e8e6e 100644 (file)
@@ -1143,6 +1143,37 @@ public class Xcls_WindowLeftTree : Object
             
             return "";
                     
+        }
+        public void iterSetValues (Gtk.TreeIter iter, JsRender.Node node)   {
+               var ic = Gtk.IconTheme.get_default();
+            Gdk.Pixbuf pix;
+            
+            var o =   GLib.Value(typeof(Object));
+            o.set_object((Object)node);
+            var clsname = node.fqn();
+            
+            var clsb = clsname.split(".");
+            var sub = clsb.length > 1 ? clsb[1].down()  : "";
+            
+           
+            var fn = "/usr/share/glade/pixmaps/hicolor/16x16/actions/widget-gtk-" + sub + ".png";
+            if (FileUtils.test (fn, FileTest.IS_REGULAR)) {
+                pix = new Gdk.Pixbuf.from_file (fn);
+            } else {
+               pix = ic.load_icon("emblem-new", 16,0);
+            }
+            
+            this.el.set(
+                       iter, 
+                       0, node.nodeTitle(),
+                    1, node.nodeTip(), 
+                    -1
+            );
+            this.el.set_value(iter, 2,o);
+            this.el.set_value(iter, 3,pix);    
+        
+            
+        
         }
         public string treePathFromNode (JsRender.Node node) {
             // iterate through the tree and find the node
@@ -1340,16 +1371,9 @@ public class Xcls_WindowLeftTree : Object
                 _this.main_window.windowstate.file.palete().on_child_added(parentNode,node);
                     
                   
-                
+                this.iterSetValues(n_iter, node);
                 // add the node...
-                
-                this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1  );
-                var o =   GLib.Value(typeof(Object));
-                o.set_object((Object)node);
-                
-                this.el.set_value(n_iter, 2, o);
-                
-                
+                 
                 
                 
                        // load children - if it has any..
@@ -1472,8 +1496,7 @@ public class Xcls_WindowLeftTree : Object
         {
             Gtk.TreeIter citer;
             //this.insert(citer,iter,0);
-            var ic = Gtk.IconTheme.get_default();
-            var pixdef = ic.load_icon("emblem-new", 16,0);
+           
             
             for(var i =0 ; i < tr.size; i++) {
                 if (iter != null) {
@@ -1481,33 +1504,10 @@ public class Xcls_WindowLeftTree : Object
                 } else {
                     this.el.append(out citer,null);
                 }
+                this.iterSetValues(citer, tr.get(i));
                 
-                this.el.set(citer, 0, tr.get(i).nodeTitle(),
-                        1, tr.get(i).nodeTip(), -1
-                );
-                var o =   GLib.Value(typeof(Object));
-                o.set_object((Object)tr.get(i));
-                
-                this.el.set_value(citer, 2, o);
-                
-                var clsname = tr.get(i).fqn();
-                
-                var clsb = clsname.split(".");
-                var sub = clsb.length > 1 ? clsb[1].down()  : "";
-                
-                var pix = pixdef;
-                var fn = "/usr/share/glade/pixmaps/hicolor/16x16/actions/widget-gtk-" + sub + ".png";
-                if (FileUtils.test (fn, FileTest.IS_REGULAR)) {
-                       pix = new Gdk.Pixbuf.from_file (fn);
-                }
-                
-                
-                this.el.set_value(citer, 3,   pix );
-                
-                
-                
-                
-                
+         
+                 
                 if (tr.get(i).items.size > 0) {
                     this.load(tr.get(i).items, citer);
                 }
@@ -1550,7 +1550,7 @@ public class Xcls_WindowLeftTree : Object
             this.el.title = "test";
             var child_0 = new Xcls_iconrender( _this );
             child_0.ref();
-            this.el.pack_start (  child_0.el , true );
+            this.el.pack_start (  child_0.el , false );
             var child_1 = new Xcls_renderer( _this );
             child_1.ref();
             this.el.pack_start (  child_1.el , true );
@@ -1581,6 +1581,7 @@ public class Xcls_WindowLeftTree : Object
             // my vars (dec)
 
             // set gobject values
+            this.el.width = 16;
         }
 
         // user defined functions