resources/RooUsage.txt
[app.Builder.js] / src / JsRender / NodeToGtk.vala
index a741b17..613b363 100644 (file)
@@ -17,6 +17,8 @@
 * we could go on the theory that we send the whole tree to the 'plugin'
 * and that would do all the transformations before rendering..
 * -- this would make more sense...
+* -- otherwise we would call it on each element, and might get really confused
+* about scope etc..
 * 
 * 
 * 
@@ -34,14 +36,41 @@ public class JsRender.NodeToGtk : Object {
        Gee.HashMap<string,string> ar_props;
        public static int vcnt = 0; 
 
-       public NodeToGtk( Node node) 
+       public NodeToGtk( Node node , NodeToGtk? parent_obj = null
        {
                this.node = node;
                this.els = new Gee.ArrayList<string>(); 
                this.children = new Gee.ArrayList<NodeToGtk>(); 
                //this.skip = new Gee.ArrayList<string>();
                this.ar_props = new Gee.HashMap<string,string>();
-               this.parentObj = null;
+               this.parentObj = parent_obj;
+               
+               if (parent_obj == null) {
+                       // then serialize up the node,
+                       // send it to javascript for processsing,
+                       // then rebuild node from return value..
+                       try {
+                               var ret = Palete.Javascript.singleton().executeFile(
+                                               BuilderApplication.configDirectory() + "/resources/node_to_gtk.js",
+                                               "node_to_gtk",
+                                               node.toJsonString()
+                               );
+                               var new_node = new Node();
+                               var pa = new Json.Parser();
+                               pa.load_from_data(ret);
+                               var rnode = pa.get_root();
+                          
+                               
+                               new_node.loadFromJson(rnode.get_object(), 2);
+                               this.node = new_node;
+                               
+                       } catch (Palete.JavascriptError e) {
+                               print("Error: %s\n", e.message);
+                       }
+                       
+                       
+               }
+               
        }
        
        public Object? munge ( )
@@ -56,15 +85,15 @@ public class JsRender.NodeToGtk : Object {
        }
        public NodeToGtk? mungeChild(  Node cnode)
        {
-               var x = new  NodeToGtk(cnode);
-               x.parentObj = this;
+               var x = new  NodeToGtk(cnode, this);
+               
                return x.mungeNode();
                
        }
        
        public NodeToGtk? mungeNode()
        {
-
+               
                var parent = this.parentObj != null ? this.parentObj.wrapped_object : null;
                var cls = this.node.fqn().replace(".", "");
                var ns = this.node.fqn().split(".")[0];
@@ -77,7 +106,7 @@ public class JsRender.NodeToGtk : Object {
                        print("SKIP - gtype is invalid\n");
                        return null;
                }
-               // if it's a window... 
+               // if it's a window...  -- things we can not render....
 
                if (cls_gtype.is_a(typeof(global::Gtk.Window))) {
                        // what if it has none...
@@ -86,6 +115,13 @@ public class JsRender.NodeToGtk : Object {
                        }
                        return this.mungeChild(this.node.items.get(0));
                }
+               if (cls_gtype.is_a(typeof(global::Gtk.Popover))) {
+                       // what if it has none...
+                       if (this.node.items.size < 1) {
+                               return null;
+                       }
+                       return this.mungeChild(this.node.items.get(0));
+               }
 
                var ret = Object.new(cls_gtype);
                ret.ref(); //??? problematic?
@@ -132,13 +168,50 @@ public class JsRender.NodeToGtk : Object {
                                // print("Check: " +cls + "::(" + pviter.get_value().propertyof + ")" + pviter.get_key() + " " );
                        var k = pviter.get_key();
                        // skip items we have already handled..
-                       if  (!this.node.has(k)) {
+                       if  (!this.node.has(k)) {
                                continue;
                        }
                        // find out the type of the property...
                        var type = pviter.get_value().type;
                        type = Palete.Gir.fqtypeLookup(type, ns);
 
+                       var  ocl = (ObjectClass) cls_gtype.class_ref ();
+                       var ps = ocl.find_property(k);
+                       
+                       // attempt to read property type and enum...
+                       
+                       if (ps != null) {
+                               var vt = ps.value_type;
+                               if (vt.is_enum()) {
+                                       
+                                       var raw_val = this.node.get(k).strip();
+                                       var rv_s = raw_val.split(".");
+                                       if (rv_s.length > 0) {
+                                               raw_val = rv_s[rv_s.length-1];                                  
+                                               EnumClass ec = (EnumClass) vt.class_ref ();
+                                               var foundit = false;
+                                               for (var i =0;i< ec.n_values; i++) {
+                                                       var ev = ec.values[i].value_name;
+                                                       var ev_s= ev.split("_");
+                                                       if (raw_val == ev_s[ev_s.length-1]) {
+                                                               var sval = GLib.Value(typeof(int));
+                                                               sval.set_int(ec.values[i].value);
+                                                               ret.set_property(k, sval);
+                                                               foundit = true;
+                                                               break;
+                                                       }
+                                               }
+                                               if (foundit) {
+                                                       continue;
+                                               }
+                                                       
+                                       }
+                               }
+                       }
+
+
+                       
+
                        var val = this.toValue(this.node.get(k).strip(), type);
                        if (val == null) {
                                print("skip (failed to transform value %s type = %s from %s\n", 
@@ -207,13 +280,12 @@ public class JsRender.NodeToGtk : Object {
                        }
                        labels.add(this.children.get(i));
                }
-               for (var i = 0; i < bodies.size; i++) { 
+               for (var i = 0; i < bodies.size; i++) {
+                       var lbl = (i > (labels.size -1)) ? null : labels.get(i);
+
                        ((global::Gtk.Notebook)this.wrapped_object).append_page(
                                 (global::Gtk.Notebook) bodies.get(i).wrapped_object,
-                                (labels.size > i - 1) ? 
-                                       (global::Gtk.Notebook) labels.get(i).wrapped_object :
-                                       null
-                                       
+                                lbl != null ?  (global::Gtk.Notebook) lbl.wrapped_object : null
                        );
                        
                        
@@ -383,15 +455,18 @@ public class JsRender.NodeToGtk : Object {
                var ns = this.parentObj.node.fqn().split(".")[0];
                 
                var pack = this.node.props.get("* pack").split(",");
-
-       
+               
+               // this tries to use the parameter names from the '*pack' function as properties in child_set_property.
+           // for a grid it's trying to do left/top/width/height.
+           
+           
                if (cls_methods.has_key(pack[0])) {
                        var mparams = cls_methods.get(pack[0]).paramset.params;
                        for (var i = 1; i < mparams.size; i++ ) {
                                if (i > (pack.length -1)) {
                                        continue;
                                }
-                       
+                               Palete.Gir.checkParamOverride(mparams.get(i));
                                var k = mparams.get(i).name;
 
                                Value cur_val;
@@ -422,14 +497,17 @@ public class JsRender.NodeToGtk : Object {
 
        public GLib.Value? toValue(string val, string type) {
 
-               var gtkbuilder = new global::Gtk.Builder();
-
-               if (type == "utf8") {
+               
+               /*
+               if (type == "string") {
                        var qret = GLib.Value(typeof(string));
                        qret.set_string(val);
                        return qret;
                }
-               
+               * */
+               /*
+                * 
+          * var gtkbuilder = new global::Gtk.Builder();
                var prop_gtype = gtkbuilder.get_type_from_name(type);
                
 
@@ -437,33 +515,52 @@ public class JsRender.NodeToGtk : Object {
                         
                        return null;
                }
+               */
                
-               
-               var ret = GLib.Value(prop_gtype);
+                
 
 
                switch(type) {
-                       case "gboolean":
+                       case "bool":
+                               var ret = GLib.Value(typeof(bool));
                                ret.set_boolean(val.down() == "false" ? false : true);
                                return ret;
-                       case "guint":
+                               
+                       case "uint":
+                               var ret = GLib.Value(typeof(uint));
                                ret.set_uint(int.parse(val));
                                return ret;
                                
-                       case "gint":
+                       case "int":
+                               var ret = GLib.Value(typeof(int));
                                ret.set_int(int.parse(val));
                                return ret;
 
-                       case "gfloat":
-                               ret.set_float(long.parse(val));
+                       // uint64 ...??
+
+                       case "long":
+                               var ret = GLib.Value(typeof(long));
+                               ret.set_long((long)int64.parse(val));
+                               return ret;
+                       
+                       case "ulong":
+                               var ret = GLib.Value(typeof(ulong));
+                               ret.set_ulong((ulong) uint64.parse(val));
+                               return ret;
+
+                       case "float":
+                               var ret = GLib.Value(typeof(float));
+                               ret.set_float((float)double.parse(val));
                                return ret;
                                
-                       case "utf8":
+                       case "string":
+                               var ret = GLib.Value(typeof(string));
                                ret.set_string(val);
                                return ret;
 
                        default:
-
+                               return null;
+                               /*
                                var sval =  GLib.Value(typeof(string));
                                sval.set_string(val);
                        
@@ -472,7 +569,10 @@ public class JsRender.NodeToGtk : Object {
                                        return null;
                                }
                                return ret;
+                               */
                }
+               // should not get here..
+               return null;
        }