src/Palete/Palete.vala
[app.Builder.js] / src / Palete / Gir.vala
index fa6df75..0b60527 100644 (file)
@@ -20,9 +20,22 @@ public static int main (string[] args) {
  */
 namespace Palete {
  
-       public abstract class GirBase : GirObject { 
+        
+    
+    
+    // Gir - is the libvala based version - 
+    
+    
+       public class Gir : GirObject {
+    
+               //Gee.Hashmap<string,what> nodes;
                
-               public abstract void load();
+               public Gir (string ns)
+               {
+                       base("Package",ns);
+                        
+               }
+                
                public string doc(string what)
                {
                        var ar = what.split(".");
@@ -35,26 +48,106 @@ namespace Palete {
                        return pr.doctxt != null ? pr.doctxt : "";
 
                }
-       }
-    
-       public class Gir : GirBase {
-    
-               public static  Gee.HashMap<string,Gir> cache = null;
-               //Gee.Hashmap<string,what> nodes;
-               
-               public Gir (string ns)
+               /**
+                * since constructors from the API from gir or vala do not map
+                * correctly to properties, we have an Gir.overides file in resources
+                * that changes the ctor's for some elements.
+                * 
+                */
+                
+               public static void checkParamOverride(GirObject c)
                {
-                       base("Package",ns);
+                       
+                       print("checkParamOverride :check %s\n", c.name);
+                       var parset = c.gparent;
+                       if (parset == null || parset.nodetype != "Paramset") {
+                               print("skip parent not Paramset\n");
+                               return;
+                       }
+                       var method = parset.gparent;
+                       // we can do this for pack methods..
+                       if (method == null) {
+                               print("skip parent.parent is null\n");
+                               return;
+                       }
+                       var cls = method.gparent;
+                       if (cls == null || cls.nodetype != "Class") {
+                               //print("skip parent.parent.parent not Class\n");
+                               return;
+                       }
+
+                        
+                       
+                       c.name =  fetchOverride( cls.name, method.name, c.name);
                }
+               public static bool overrides_loaded = false;
+               public static Gee.HashMap<string,string> overrides;
+       
+               public static string fetchOverride(  string cls, string method, string param)
+               {
+                       // overrides should be in a file Gir.overides
+                       // in that "Gtk.Label.new.str" : "label"
+                       loadOverrides();
+                       var key = "%s.%s.%s".printf(cls,method,param);
+                        //print("Chekcing for key %s\n", key);
+                       if (!overrides.has_key(key)) {
+                               return param;
+                       }
+                       return overrides.get(key);
+
+
+               }
+                
+               public static void loadOverrides(bool force = false)
+               {
+                       if (overrides_loaded && ! force) {
+                               return;
+                       }
                
+                       var pa = new Json.Parser();
+                       pa.load_from_file(BuilderApplication.configDirectory() + "/resources/Gir.overides");
+                       var node = pa.get_root();
+                   
+                       if (node.get_node_type () != Json.NodeType.OBJECT) {
+                               throw new GirError.INVALID_FORMAT ("Error loading gir.overides : Unexpected element type %s", node.type_name ());
+                       }
+                       overrides = new Gee.HashMap<string,string>();
                
+               
+                       var obj = node.get_object ();
+               
+               
+                       obj.foreach_member((o , key, value) => {
+                               //print(key+"\n");
+                               var v = obj.get_string_member(key);
+                               overrides.set(key, v);
+                       });
+       
+                       overrides_loaded = true;
+
+               
+
+               }
+               
+               /**
+                *  == all static below here...
+                * 
+                */
+               public static  Gee.HashMap<string,Gir> cache = null;
 
                
-               public static GirBase?  factory(string ns) {
+               public static Gir?  factory(string ns) 
+               {
                        if (cache == null) {
                                cache = new Gee.HashMap<string,Gir>();
+                               var a = new VapiParser( );
+                               a.create_valac_tree();
+                                 
                        }
                        var ret = cache.get(ns);
+                       
+                       
+                       /*
                        if (ret == null) {
 
                                var add = new Gir(ns);
@@ -74,6 +167,23 @@ namespace Palete {
                                
                                ret = cache.get(ns);
                        }
+                       */
+                       if (ret != null && !ret.is_overlaid) {
+                               ret.is_overlaid = true;
+                               var iter = ret.classes.map_iterator();
+                               while(iter.next()) {
+                                       iter.get_value().overlayParent();
+                               }
+                               // loop again and add the ctor properties.
+                               iter = ret.classes.map_iterator();
+                               while(iter.next()) {
+                                       iter.get_value().overlayCtorProperties();
+                               }       
+                               
+                               
+                       }
+                       
+                       
                         
 
                        return ret;
@@ -148,7 +258,6 @@ namespace Palete {
 
                }
 
-