Fix #8076 - gtknotebookpage fake wrapper
authorAlan Knowles <alan@roojs.com>
Sun, 10 Mar 2024 04:12:28 +0000 (12:12 +0800)
committerAlan Knowles <alan@roojs.com>
Sun, 10 Mar 2024 04:12:28 +0000 (12:12 +0800)
src/JsRender/Node.vala
src/JsRender/NodeToGlade.vala
src/JsRender/NodeToVala.vala
src/JsRender/NodeToValaWrapped.vala
src/Palete/Gtk.vala

index eea58d3..c14b659 100644 (file)
@@ -305,7 +305,7 @@ public class JsRender.Node : GLib.Object {
                
                for(var i= 0; i < this.propstore.get_n_items();i++) {
                        var p = (NodeProp) this.propstore.get_item(i);
-                       GLib.debug("prop %s lines %d -> %d", p.name, p.start_line, p.end_line);
+                       //GLib.debug("prop %s lines %d -> %d", p.name, p.start_line, p.end_line);
                        if (p.start_line > line) {
                                continue;
                        }
index 23ec814..e3b833d 100644 (file)
@@ -95,8 +95,10 @@ public class JsRender.NodeToGlade : Object {
                var gdata = Palete.Gir.factoryFqn(this.project, this.node.fqn());
                if (gdata == null || !gdata.inherits.contains("Gtk.Buildable")) {
                        switch(cls) {
-                               case "GtkColumnViewColumn": //exception to the rule..
-                                       break;
+                       //exception to the rule.. (must be buildable to work with glade?
+                               case "GtkColumnViewColumn": 
+                               case "GtkNotebookPage": 
+                               break;
                                default:
                                        return null;
                        }
@@ -204,7 +206,19 @@ public class JsRender.NodeToGlade : Object {
                var items = this.node.readItems();
                for (var i = 0; i < items.size; i++ ) {
                        var cn = items.get(i);
-                       var child  = this.create_element("child");
+                       
+                       var childname = "child";
+                       var pname = "";
+                       if (cn.has("* prop")) { // && cn.get_prop("* prop").val == "child") {
+                               childname = "property";
+                               pname = cn.get_prop("* prop").val;
+                       }
+                       
+                       var child  = this.create_element(childname);
+                       if (pname != "") {
+                               child->set_prop("name", pname);
+                       }
+                       
                        if ((cls == "GtkWindow" || cls == "GtkApplicationWindow") && cn.fqn() == "Gtk.HeaderBar") {
                                child->set_prop("type", "label");
                        }
index c80fd36..5791c99 100644 (file)
@@ -136,7 +136,7 @@ public abstract class JsRender.NodeToVala : NodeWriter {
  
        protected void addMyVars()
        {
-               GLib.debug("callinged addMhyVars");
+               GLib.debug("calling  addMyVars");
                
                this.addLine();
                this.addLine(this.ipad + "// my vars (def)");
@@ -181,8 +181,12 @@ public abstract class JsRender.NodeToVala : NodeWriter {
                                continue;
                        }
                        
+                       var isUser = prop.ptype == NodePropType.USER;
+                       if (this.node.fqn() == "Gtk.NotebookPage") {
+                               isUser= true;
+                       }
                        // is it a class property...
-                       if (cls != null && cls.props.has_key(prop.name) && prop.ptype != NodePropType.USER) {
+                       if (cls != null && cls.props.has_key(prop.name) && !isUser) {
                                continue;
                        }
                        
@@ -285,7 +289,12 @@ public abstract class JsRender.NodeToVala : NodeWriter {
                                v= v.down();
                        }
                        //FIXME -- check for raw string.. "string XXXX"
+                       var is_raw = prop.ptype == NodePropType.RAW;
                        
+                       // what's the type.. - if it's a string.. then we quote it..
+                       if (prop.rtype == "string" && !is_raw) {
+                                v = "\"" +  v.escape("") + "\"";
+                       }
                        // if it's a string...
                        
                        prop.start_line = this.cur_line;
@@ -305,6 +314,10 @@ public abstract class JsRender.NodeToVala : NodeWriter {
                        GLib.debug("Skipping wrapped properties - could not find class  %s" , this.node.fqn());
                        return;
                }
+               
+               if (this.node.fqn() == "Gtk.NotebookPage") {
+                       return;
+               }
                        // what are the properties of this class???
                this.addLine();
                this.addLine(this.ipad + "// set gobject values");
@@ -366,6 +379,7 @@ public abstract class JsRender.NodeToVala : NodeWriter {
        protected  void addChildren()
        {
                                //code
+               GLib.debug("addChildren %s, %d", this.node.fqn(), (int)this.node.readItems().size);
                if (this.node.readItems().size < 1) {
                        return;
                }
@@ -373,7 +387,10 @@ public abstract class JsRender.NodeToVala : NodeWriter {
                var cols = this.node.has("* columns") ? int.max(1, int.parse(this.node.get_prop("* columns").val)) : 1;
                var colpos = 0;
                
+               var nb_child = "";
+               var nb_tab = "";
+               var nb_menu = "";
+                       
                 
                foreach(var child in this.node.readItems()) {
                        
@@ -389,14 +406,30 @@ public abstract class JsRender.NodeToVala : NodeWriter {
                                continue;
                        }
                        // create the element..
+                         
                        
                        // this is only needed if it does not have an ID???
                        var childname = this.addPropSet(child, child.has("id") ? child.get_prop("id").val : "") ; 
                        if (!child.has("id") && this.this_el == "this.el.") {
                                this.addLine(this.ipad +  childname +".ref();"); 
-                       } 
+                       }
                        if (child.has("* prop")) {
-                        
+                               if (this.node.fqn() == "Gtk.NotebookPage") {
+                                       switch (child.get_prop("* prop").val) {
+                                               case "child":
+                                                       nb_child = childname;
+                                                       break;
+                                                       
+                                               case "tab":
+                                                       nb_tab = childname;
+                                                       break;
+                                                       
+                                               case "menu":
+                                                       nb_menu = childname;
+                                                       break;
+                                       }
+                                       continue;
+                               }
                        
                                // fixme special packing!??!?!
                                if (child.get_prop("* prop").val.contains("[]")) {
@@ -431,10 +464,33 @@ public abstract class JsRender.NodeToVala : NodeWriter {
                         
                                  
                }
+               
+               GLib.debug("got node %s with nb_child= %s", this.node.fqn() , nb_child);
+               if (this.node.fqn() == "Gtk.NotebookPage" && nb_child != "") {
+                       if (nb_tab == "" && this.node.has("tab_label")) {
+                               nb_tab = "new Gtk.Label(this.tab_label)";
+                       }
+                
+                       if (nb_menu == "" && nb_tab == "") {
+                               this.addLine(@"$(ipad)notebook.el.append_page( $(nb_child)  );");
+                               return;
+                       }
+                       if (nb_menu == "") {
+                               this.addLine(@"$(ipad)notebook.el.append_page( $(nb_child) , $(nb_tab) );");
+                               return;
+                       }
+                       this.addLine(@"$(ipad)notebook.el.append_page_menu( $(nb_child) , $(nb_tab), $(nb_menu) );");
+               
+               }
+               
        }
+       /**
+               var childname = new Xcls_.... (....)
+               
        
+       */
        protected string addPropSet(Node child, string child_name) 
-       {
+       {       
         
                
                var xargs = "";
@@ -463,6 +519,9 @@ public abstract class JsRender.NodeToVala : NodeWriter {
                        }
                }
                */
+               if (child.fqn() == "Gtk.NotebookPage") {
+                       xargs +=" , this";
+               }
                
                this.addLine(this.ipad + @"$(prefix)new $cls( _this $xargs);" );
                 
@@ -524,7 +583,7 @@ public abstract class JsRender.NodeToVala : NodeWriter {
                
                
                switch (this.node.fqn()) {
-                       
+                        
                                
                
                        case "Gtk.Fixed":
@@ -547,6 +606,9 @@ public abstract class JsRender.NodeToVala : NodeWriter {
                                return;
                                
                        case "Gtk.Notebook": // use label
+                               if (child.fqn() == "Gtk.NotebookPage") {
+                                       return;
+                               }
                                var label = child.has("notebook_label") ?  child.get_prop("notebook_label").val.escape() : "";
                                this.addLine(@"$(ipad)$(this_el)append_page( $(childname)$(el_name), new Gtk.Label(\"$(label)\");");
                                
index 451d9ef..b5b2e39 100644 (file)
@@ -174,7 +174,8 @@ public class JsRender.NodeToValaWrapped : NodeToVala {
                        //for (var ari =0; ari < ar.length; ari++) {
                                //      cargs +=  (ar[ari].trim().split(" ").pop();
                                  // }
-                       }
+               }
+               
        
                if (this.depth < 1) {
                 
@@ -188,6 +189,10 @@ public class JsRender.NodeToValaWrapped : NodeToVala {
                        var top = this.top as NodeToVala;
                        var tcls = top == null ? "???" : top.xcls;
                        // for sub classes = we passs the top level as _owner
+                       if (this.node.fqn() == "Gtk.NotebookPage") {
+                               cargs_str += ", " + this.node.parent.xvala_xcls + " notebook";
+                       }
+                       
                        this.addLine(this.pad + "public " + this.xcls + "(" +  tcls + " _owner " + cargs_str + ")");
                        this.addLine(this.pad + "{");
                }
@@ -224,8 +229,11 @@ public class JsRender.NodeToValaWrapped : NodeToVala {
                
                this.node.setLine(this.cur_line, "p", "* xtype");;
                
-               // is the wrapped element a struct?
-               
+
+               // Notebookpage is a fake element 
+               // used to hold label and child...
+                
+               // is the wrapped element a struct?             
                var ncls = Palete.Gir.factoryFqn((Project.Gtk) this.file.project, this.node.fqn());
                if (ncls != null && ncls.nodetype == "Struct") {
                        // we can use regular setters to apply the values.
@@ -239,6 +247,14 @@ public class JsRender.NodeToValaWrapped : NodeToVala {
                var args_str = "";
                switch(this.node.fqn()) {
                
+               
+                       // GTK4
+                       case "Gtk.NotebookPage":
+                               return;
+                               
+               
+               
+               
                // FIXME -- these are all GTK3 - can be removed when I get rid of them..
                        case "Gtk.ComboBox":
                                var is_entry = this.node.has("has_entry") && this.node.get_prop("has_entry").val.down() == "true";
index 4827b2b..ccc94c0 100644 (file)
@@ -683,6 +683,7 @@ namespace Palete {
                        
                        var w = this.getClass(cn);
                        if (w == null) {
+                               
                                return;
                        }
                        
@@ -780,6 +781,10 @@ namespace Palete {
                 // add_tick_callback ?
                 // append << core one to add stuff..
                 
+               if (in_rval == "Gtk.Notebook") {
+                       ret.add( "Gtk.NotebookPage" );
+               }
+                
                if (!with_props) {
                        
                        pr.child_list_cache.set(in_rval, ret);