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) => {
78 var v = obj.get_string_member(key);
79 overrides.set(key, v);
82 overrides_loaded = true;
89 * == all static below here...
92 public static Gee.HashMap<string,Gir> cache = null;
95 public static Gir? factory(string ns)
98 cache = new Gee.HashMap<string,Gir>();
99 var a = new VapiParser( );
100 a.create_valac_tree();
103 var ret = cache.get(ns);
109 var add = new Gir(ns);
113 var iter = add.classes.map_iterator();
115 iter.get_value().overlayParent();
117 // loop again and add the ctor properties.
118 iter = add.classes.map_iterator();
120 iter.get_value().overlayCtorProperties();
127 if (ret != null && !ret.is_overlaid) {
128 ret.is_overlaid = true;
129 var iter = ret.classes.map_iterator();
131 iter.get_value().overlayParent();
133 // loop again and add the ctor properties.
134 iter = ret.classes.map_iterator();
136 iter.get_value().overlayCtorProperties();
148 public static GirObject? factoryFqn(string fqn)
150 var bits = fqn.split(".");
151 if (bits.length < 1) {
155 var f = (GirObject)factory(bits[0]);
157 if (bits.length == 1 || f ==null) {
160 return f.fetchByFqn(fqn.substring(bits[0].length+1)); // since classes are stored in fqn format...?
167 * guess the fqn of a type == eg. gboolean or Widget etc...
169 public static string fqtypeLookup(string type, string ns) {
171 if (g.classes.has_key(type)) {
172 return ns + "." + type;
175 if (g.consts.has_key(type)) {
176 return ns + "." + type;
180 // look at includes..
181 var iter = g.includes.map_iterator();
183 // skip empty namespaces on include..?
184 if ( iter.get_key() == "") {
187 var ret = fqtypeLookup(type, iter.get_key());
198 // needed still - where's it called form..
199 public static string guessDefaultValueForType(string type) {
200 //print("guessDefaultValueForType: %s\n", type);
201 if (type.length < 1 || type.contains(".")) {
212 return "?"+ type + "?";