Fix #8089 - phase 1 - code ast navigation
[roobuilder] / src / JsRender / NodeToVala.vala
index bd74fe1..6490629 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,22 +406,35 @@ 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")) {
-                               // must ref new objects..
-                               this.addLine("%s%s.ref();".printf(ipad, childname));
-                       }
+                       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 + (this.this_el == "this.el." ? ".el" : "");
+                                                       break;
+                                                       
+                                               case "tab":
+                                                       nb_tab = childname + (this.this_el == "this.el." ? ".el" : "");
+                                                       break;
+                                                       
+                                               case "menu":
+                                                       nb_menu = childname + (this.this_el == "this.el." ? ".el" : ""); 
+                                                       break;
+                                       }
+                                       continue;
+                               }
                        
                                // fixme special packing!??!?!
                                if (child.get_prop("* prop").val.contains("[]")) {
-                                       // currently these 'child props
-                                       // used for label[]  on Notebook
-                                       // used for button[]  on Dialog?
-                                       // columns[] ?
+                                       // currently this is not used?
+                                       // and it will not add ref..
                                         
                                        this.packChild(child, childname, 0, 0, child.get_prop("* prop").val);  /// fixme - this is a bit speciall...
                                        continue;
@@ -420,9 +450,7 @@ public abstract class JsRender.NodeToVala : NodeWriter {
                                
                                continue;
                        } 
-                        if (!child.has("id") && this.this_el == "this.el.") {
-                               this.addLine(this.ipad +  childname +".ref();"); 
-                        } 
+                        
                        this.packChild(child, childname, cols, colpos);
                        
                        if (child.has("colspan")) {
@@ -436,10 +464,35 @@ 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 != "") {
+                       var nb = (this.this_el == "this.el." ? "notebook.el" : "notebook");
+                       
+                       if (nb_tab == "" && this.node.has("tab_label")) {
+                               nb_tab = "new Gtk.Label(this.tab_label)";
+                       }
+                
+                       if (nb_menu == "" && nb_tab == "") {
+                               this.addLine(@"$(ipad)$(nb).append_page( $(nb_child)  );");
+                               return;
+                       }
+                       if (nb_menu == "") {
+                               this.addLine(@"$(ipad)$(nb).append_page( $(nb_child) , $(nb_tab) );");
+                               return;
+                       }
+                       this.addLine(@"$(ipad)$(nb).append_page_menu( $(nb_child) , $(nb_tab), $(nb_menu) );");
+               
+               }
+               
        }
+       /**
+               var childname = new Xcls_.... (....)
+               
        
+       */
        protected string addPropSet(Node child, string child_name) 
-       {
+       {       
         
                
                var xargs = "";
@@ -468,6 +521,9 @@ public abstract class JsRender.NodeToVala : NodeWriter {
                        }
                }
                */
+               if (child.fqn() == "Gtk.NotebookPage") {
+                       xargs +=" , this";
+               }
                
                this.addLine(this.ipad + @"$(prefix)new $cls( _this $xargs);" );
                 
@@ -529,7 +585,7 @@ public abstract class JsRender.NodeToVala : NodeWriter {
                
                
                switch (this.node.fqn()) {
-                       
+                        
                                
                
                        case "Gtk.Fixed":
@@ -552,6 +608,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)\");");