2 // valac -g --pkg gee-1.0 --pkg libxml-2.0 --pkg gobject-introspection-1.0 --pkg json-glib-1.0 Palete/Gir.vala -o /tmp/Gir
4 public static int main (string[] args) {
6 var g = Palete.Gir.factory("Gtk");
7 var test = g.classes.get("ToolButton");
10 var generator = new Json.Generator ();
11 var n = new Json.Node(Json.NodeType.OBJECT);
12 n.set_object(test.toJSON());
13 generator.set_root(n);
15 generator.pretty = true;
17 print(generator.to_data(null));
26 // Gir - is the libvala based version -
29 public class Gir : GirObject {
31 //Gee.Hashmap<string,what> nodes;
33 public Gir (string ns)
39 public string doc(string what)
41 var ar = what.split(".");
42 var cls = this.classes.get(ar[1]);
44 return cls.doctxt != null ? cls.doctxt : "";
46 // return the property.. by default..
47 var pr = cls.props.get(ar[2]);
48 return pr.doctxt != null ? pr.doctxt : "";
52 * since constructors from the API from gir or vala do not map
53 * correctly to properties, we have an Gir.overides file in resources
54 * that changes the ctor's for some elements.
57 public void loadOverrides(bool force = false)
59 if (overrides_loaded && ! force) {
63 var pa = new Json.Parser();
64 pa.load_from_file(BuilderApplication.configDirectory() + "/resources/Gir.overides");
65 var node = pa.get_root();
67 if (node.get_node_type () != Json.NodeType.OBJECT) {
68 throw new GirError.INVALID_FORMAT ("Error loading gir.overides : Unexpected element type %s", node.type_name ());
70 overrides = new Gee.HashMap<string,string>();
73 var obj = node.get_object ();
76 obj.foreach_member((o , key, value) => {
79 var v = obj.get_string_member(key);
82 overrides.set(key, v);
86 overrides_loaded = true;
93 * == all static below here...
96 public static Gee.HashMap<string,Gir> cache = null;
99 public static Gir? factory(string ns)
102 cache = new Gee.HashMap<string,Gir>();
103 var a = new VapiParser( );
104 a.create_valac_tree();
107 var ret = cache.get(ns);
113 var add = new Gir(ns);
117 var iter = add.classes.map_iterator();
119 iter.get_value().overlayParent();
121 // loop again and add the ctor properties.
122 iter = add.classes.map_iterator();
124 iter.get_value().overlayCtorProperties();
131 if (ret != null && !ret.is_overlaid) {
132 ret.is_overlaid = true;
133 var iter = ret.classes.map_iterator();
135 iter.get_value().overlayParent();
137 // loop again and add the ctor properties.
138 iter = ret.classes.map_iterator();
140 iter.get_value().overlayCtorProperties();
152 public static GirObject? factoryFqn(string fqn)
154 var bits = fqn.split(".");
155 if (bits.length < 1) {
159 var f = (GirObject)factory(bits[0]);
161 if (bits.length == 1 || f ==null) {
164 return f.fetchByFqn(fqn.substring(bits[0].length+1)); // since classes are stored in fqn format...?
171 * guess the fqn of a type == eg. gboolean or Widget etc...
173 public static string fqtypeLookup(string type, string ns) {
175 if (g.classes.has_key(type)) {
176 return ns + "." + type;
179 if (g.consts.has_key(type)) {
180 return ns + "." + type;
184 // look at includes..
185 var iter = g.includes.map_iterator();
187 // skip empty namespaces on include..?
188 if ( iter.get_key() == "") {
191 var ret = fqtypeLookup(type, iter.get_key());
202 // needed still - where's it called form..
203 public static string guessDefaultValueForType(string type) {
204 //print("guessDefaultValueForType: %s\n", type);
205 if (type.length < 1 || type.contains(".")) {
216 return "?"+ type + "?";