resources/RooUsage.txt
[app.Builder.js] / src / JsRender / NodeToVala.vala
index 7e8a7ed..1350c0d 100644 (file)
@@ -1,8 +1,8 @@
 /**
  * 
- * Code to convert node tree to Javascript...
+ * Code to convert node tree to Vala...
  * 
- * usage : x = (new JsRender.NodeToJs(node)).munge();
+ * usage : x = (new JsRender.NodeToVala(node)).munge();
  * 
  * 
  * 
@@ -62,11 +62,14 @@ public class JsRender.NodeToVala : Object {
                this.file = null;
                
                // initialize line data..
-               node.line = this.cur_line;
-               node.proplines = new Gee.HashMap<string,int>();
-               node.listenlines = Gee.HashMap<string,int>();
-               
-               
+               node.line_start = this.cur_line;
+               node.line_end  = this.cur_line;
+               node.lines = new Gee.ArrayList<int>();
+               node.line_map = new Gee.HashMap<int,string>();
+               if (parent == null) {
+                       node.node_lines = new Gee.ArrayList<int>();
+                       node.node_lines_map = new Gee.HashMap<int,Node>();
+                }
                
        }
 
@@ -188,29 +191,29 @@ public class JsRender.NodeToVala : Object {
        public void addLine(string str= "")
        {
                this.cur_line++;
+               //this.ret += "/*%d*/ ".printf(this.cur_line-1) + str + "\n";
                this.ret += str + "\n";
        }
        public void addMultiLine(string str= "")
        {
-               this.cur_line++;
+                
                this.cur_line += str.split("\n").length;
-               this.ret += str + "\n";
+               //this.ret +=  "/*%d*/ ".printf(l) + str + "\n";
+               this.ret +=   str + "\n";
        }
-       addMultiLine
+        
        
        public void globalVars()
        {
                if (this.depth > 0) {
                        return;
                }
-               // Global Vars..
+               // Global Vars..??? when did this get removed..?
                //this.ret += this.inpad + "public static " + this.xcls + "  " + this.node.xvala_id+ ";\n\n";
 
-               this.addLine("%sstatic %s _%s;".printf(this.inpad, this.xcls, this.node.xvala_id));
+               this.addLine(this.inpad + "static " + this.xcls + "  _" + this.node.xvala_id+ ";");
                this.addLine();
-               //this.ret += this.inpad + "static " + this.xcls + "  _" + this.node.xvala_id+ ";\n\n";
-                               
-                               
+                  
        }
 
        void classHeader()
@@ -218,13 +221,17 @@ public class JsRender.NodeToVala : Object {
                           
                // class header..
                // class xxx {   WrappedGtk  el; }
-               this.node.line = this.cur_line;
-               this.addLine(inpad + "public class " + this.xcls + " : Object \n" + this.inpad + "{");
+               this.node.line_start = this.cur_line;
+               
+               this.top.node.setNodeLine(this.cur_line, this.node);
+               
+               this.addLine(inpad + "public class " + this.xcls + " : Object");
+               this.addLine(this.inpad + "{");
                
                 
                this.addLine(this.pad + "public " + this.cls + " el;");
  
-               this.addLine(this.pad + "private " + this.top.xcls + "  _this;)";
+               this.addLine(this.pad + "private " + this.top.xcls + "  _this;");
                this.addLine();
                        
                        
@@ -237,7 +244,7 @@ public class JsRender.NodeToVala : Object {
                        return;
                }
                this.addLine(pad + "public static " + xcls + " singleton()");
-               this.addLine(this.pad + "{")
+               this.addLine(this.pad + "{");
                this.addLine(this.ipad +    "if (_" + this.node.xvala_id  + " == null) {");
                this.addLine(this.ipad +    "    _" + this.node.xvala_id + "= new "+ this.xcls + "();");  // what about args?
                this.addLine(this.ipad +    "}");
@@ -314,7 +321,7 @@ public class JsRender.NodeToVala : Object {
                        }
                                
                        if (vv[0] == "@") {
-                               this.node.proplines.set(k, this.cur_line);
+                               this.node.setLine(this.cur_line, "p", k);
                                this.addLine(this.pad + "public signal" + k.substring(1)  + " "  + iter.get_value() + ";");
                                
                                this.ignore(k);
@@ -338,8 +345,8 @@ public class JsRender.NodeToVala : Object {
                        }
                        
                        this.myvars.add(k);
-
-                       this.node.proplines.set(k, this.cur_line);
+                       this.node.setLine(this.cur_line, "p", k);
+                       
                        this.addLine(this.pad + "public " + 
                                (k[0] == '$' || k[0] == '#' ? k.substring(2) : k ) + ";");
                                
@@ -357,13 +364,13 @@ public class JsRender.NodeToVala : Object {
                }
                var iter = this.node.items.list_iterator();
                while (iter.next()) {
-               var ci = iter.get();
+                       var ci = iter.get();
                                
                        if (ci.xvala_id[0] != '+') {
                                continue; // skip generation of children?
                                
                        }
-                       this.node.proplines.set(k, this.cur_line);
+                        
                        this.addLine(this.pad + "public " + ci.xvala_xcls + " " + ci.xvala_id.substring(1) + ";");
                                           
                        
@@ -397,7 +404,7 @@ public class JsRender.NodeToVala : Object {
                if (this.depth < 1) {
                 
                        // top level - does not pass the top level element..
-                       this.addLine(this.pad + "public " + this.xcls + "(" +  cargs_str +")")
+                       this.addLine(this.pad + "public " + this.xcls + "(" +  cargs_str +")");
                        this.addLine(this.pad + "{");
                } else {
                                
@@ -413,7 +420,7 @@ public class JsRender.NodeToVala : Object {
         */
        void addUnderThis() 
        {
-                       // public static?
+               // public static?
                if (depth < 1) {
                        this.addLine( this.ipad + "_this = this;");
                        return;
@@ -456,7 +463,7 @@ public class JsRender.NodeToVala : Object {
                }
                */
                if (this.node.has("* ctor")) {
-                       this.node.proplines.set("* ctor", this.curline);
+                       this.node.setLine(this.cur_line, "p", "* ctor");
                        this.addLine(this.ipad + "this.el = " + this.node.get("* ctor")+ ";");
                        return;
                }
@@ -504,12 +511,13 @@ public class JsRender.NodeToVala : Object {
                                args += v;
 
                        }
-                       this.node.proplines.set("* xtype", this.curline);
+                       this.node.setLine(this.cur_line, "p", "* xtype");
+                       
                        this.addLine(this.ipad + "this.el = new " + cls + "( "+ string.joinv(", ",args) + " );") ;
                        return;
                        
                }
-               this.node.proplines.set("* xtype", this.curline);
+               this.node.setLine(this.cur_line, "p", "* xtype");;
                
                this.addLine(this.ipad + "this.el = new " + this.cls + "();");
 
@@ -563,12 +571,14 @@ public class JsRender.NodeToVala : Object {
                        return;
                }
                        // what are the properties of this class???
-               this.ret += "\n" + this.ipad + "// set gobject values\n";
+               this.addLine();
+               this.addLine(this.ipad + "// set gobject values");
+               
 
                var iter = cls.props.map_iterator();
                while (iter.next()) {
                        var p = iter.get_key();
-                       print("Check Write %s\n", p);
+                       //print("Check Write %s\n", p);
                        if (!this.node.has(p)) {
                                continue;
                        }
@@ -602,7 +612,7 @@ public class JsRender.NodeToVala : Object {
                        }
                        
                        
-                       this.ret += "%sthis.el.%s = %s;\n".printf(ipad,p,v); // // %s,  iter.get_value().type);
+                       this.addLine("%sthis.el.%s = %s;".printf(ipad,p,v)); // // %s,  iter.get_value().type);
                                        
                           // got a property..
                           
@@ -646,7 +656,7 @@ public class JsRender.NodeToVala : Object {
                        }
                        // create the element..
                        this.addLine(this.ipad + "var child_" + "%d".printf(i) + " = new " + ci.xvala_xcls +
-                       "( _this " + xargs + ");" ;
+                                       "( _this " + xargs + ");" );
                        
                        // this is only needed if it does not have an ID???
                        this.addLine(this.ipad + "child_" + "%d".printf(i) +".ref();"); // we need to reference increase unnamed children...
@@ -696,7 +706,8 @@ public class JsRender.NodeToVala : Object {
                this.addLine();
                this.addLine(ipad + "// init method");
                this.addLine();
-               this.node.proplines.set("init", this.curline);
+               this.node.setLine(this.cur_line, "p", "init");
+               
                this.addMultiLine(ipad + this.padMultiline(ipad, this.node.get("init")) );
 
         }
@@ -706,26 +717,27 @@ public class JsRender.NodeToVala : Object {
                        return;
                }
                                
+               this.addLine();
+               this.addLine(ipad + "//listeners");
                        
-                       
-               this.ret+= "\n" + ipad + "// listeners \n";
+                        
 
                var iter = this.node.listeners.map_iterator();
                while (iter.next()) {
                        var k = iter.get_key();
                        var v = iter.get_value();
-                                       this.ret+= this.ipad + "this.el." + k + ".connect( " + 
-                                       this.padMultiline(this.ipad,v) +");\n"; 
-                                       
-                               }
+                       
+                       this.node.setLine(this.cur_line, "l", k);
+                       this.addMultiLine(this.ipad + "this.el." + k + ".connect( " + 
+                                       this.padMultiline(this.ipad,v) +");"); 
+                               
+               }
        }    
-               void addEndCtor()
+       void addEndCtor()
        {
-                       
-                       
-                       
+                        
                        // end ctor..
-                       this.ret+= this.pad + "}\n";
+                       this.addLine(this.pad + "}");
        }
 
 
@@ -773,48 +785,53 @@ public class JsRender.NodeToVala : Object {
         
        void addUserMethods()
        {
-                       
-               this.ret+= "\n" + pad + "// user defined functions \n";  
+               this.addLine();
+               this.addLine(this.pad + "// user defined functions");
                        
                        // user defined functions...
                var iter = this.node.props.map_iterator();
                while(iter.next()) {
-                               var k = iter.get_key();
+                       var k = iter.get_key();
                        if (this.shouldIgnore(k)) {
                                continue;
                        }
                        // HOW TO DETERIME if its a method?            
-                               if (k[0] != '|') {
-                                               //strbuilder("\n" + pad + "// skip " + k + " - not pipe \n"); 
-                                               continue;
-                       }       
-                               // function in the format of {type} (args) { .... }
-                               var kk = k.substring(2);
-                               var vv = iter.get_value();
-                               this.ret += this.pad + "public " + kk + " " + this.padMultiline(this.pad, vv) + "\n";
+                       if (k[0] != '|') {
+                                       //strbuilder("\n" + pad + "// skip " + k + " - not pipe \n"); 
+                                       continue;
+                       }
+                       
+                       // function in the format of {type} (args) { .... }
+                       var kk = k.substring(2);
+                       var vv = iter.get_value();
+                       this.node.setLine(this.cur_line, "p", k);
+                       this.addMultiLine(this.pad + "public " + kk + " " + this.padMultiline(this.pad, vv));;
                        
                                
-                       }
+               }
        }
 
        void iterChildren()
        {
+               this.node.line_end = this.cur_line;
+               this.node.sortLines();
+               
                        
-                       if (this.depth > 0) {
-                       this.ret+= this.inpad + "}\n";
-                       }
+               if (this.depth > 0) {
+                       this.addLine(this.inpad + "}");
+               }
                
                var iter = this.node.items.list_iterator();
-               var i = -1;
+                
                while (iter.next()) {
-                               this.ret += this.mungeChild(iter.get());
+                       this.addMultiLine(this.mungeChild(iter.get()));
                }
                         
-                       if (this.depth < 1) {
-                               this.ret+= this.inpad + "}\n";
-                       }
-                       
+               if (this.depth < 1) {
+                       this.addLine(this.inpad + "}");
                }
+                       
+       }
 
        string padMultiline(string pad, string str)
        {