7 public class Introspect.El : Object
21 public class Gtk : Palete {
23 public Gee.ArrayList<string> package_cache;
32 var context = new Vala.CodeContext ();
34 dirname = Path.get_dirname (context.get_vapi_path("glib-2.0"));
38 // various loader methods..
42 //this.comments = { };
46 public override void load () {
48 this.loadUsageFile(BuilderApplication.configDirectory() + "/resources/GtkUsage.txt");
53 public string doc(string what) {
54 var ns = what.split(".")[0];
55 var gir = Gir.factory(ns);
58 //return typeof(this.comments[ns][what]) == 'undefined' ? '' : this.comments[ns][what];
61 // does not handle implements...
62 public override GirObject? getClass(string ename)
65 var es = ename.split(".");
66 var gir = Gir.factory(es[0]);
68 return gir.classes.get(es[1]);
72 public override Gee.HashMap<string,GirObject> getPropertiesFor(string ename, string type)
74 //print("Loading for " + ename);
78 // if (typeof(this.proplist[ename]) != 'undefined') {
79 //print("using cache");
80 // return this.proplist[ename][type];
82 // use introspection to get lists..
84 var es = ename.split(".");
85 var gir = Gir.factory(es[0]);
87 var cls = gir.classes.get(es[1]);
89 var ret = new Gee.HashMap<string,GirObject>();
91 //throw new Error.INVALID_VALUE( "Could not find class: " + ename);
96 //cls.parseSignals(); // ?? needed for add handler..
97 //cls.parseMethods(); // ?? needed for ??..
98 //cls.parseConstructors(); // ?? needed for ??..
112 throw new Error.INVALID_VALUE( "getPropertiesFor called with: " + type);
113 //var ret = new Gee.HashMap<string,GirObject>();
119 //cls.overlayInterfaces(gir);
124 public string[] getInheritsFor(string ename)
128 var cls = Gir.factoryFqn(ename);
130 if (cls == null || cls.nodetype != "Class") {
131 print("getInheritsFor:could not find cls: %s\n", ename);
135 return cls.inheritsToStringArray();
140 public override void fillPack(JsRender.Node node,JsRender.Node parent)
143 string inherits = string.joinv(" ",
144 this.getInheritsFor (node.fqn())) + " ";
145 inherits += node.fqn() + " ";
146 //print ("fillPack:Inherits : %s\n", inherits);
147 // parent.fqn() method ( node.fqn()
148 var methods = this.getPropertiesFor (parent.fqn(), "methods");
150 var res = new Gee.HashMap<string,string>();
151 var map = methods.map_iterator();
154 var n = map.get_key();
155 //print ("fillPack:checking method %s\n", n);
157 var meth = map.get_value();
158 if (meth.paramset == null || meth.paramset.params.size < 1) {
159 print ("fillPack:c -- no params\n");
163 var fp = meth.paramset.params.get(0);
165 var type = Gir.fqtypeLookup(fp.type, meth.ns);
166 print ("fillPack:first param type is %s\n", type);
169 if (!inherits.contains(" " + type + " ")) {
174 var pack = meth.name;
175 for(var i =1; i < meth.paramset.params.size; i++) {
176 var ty = Gir.fqtypeLookup(meth.paramset.params.get(i).type, meth.ns);
177 pack += "," + Gir.guessDefaultValueForType(ty);
180 print ("fillPack:add pack: -- %s\n",pack );
182 res.set(meth.name, pack);
190 if (res.has_key("pack_start")) {
191 node.props.set("* pack", res.get("pack_start"));
194 if (res.has_key("add")) {
195 node.props.set("* pack", res.get("add"));
198 var riter = res.map_iterator();
199 while(riter.next()) {
200 node.props.set("* pack", riter.get_value());
206 public Gee.ArrayList<string> packages(Project.Gtk gproject)
208 var vapidirs = gproject.vapidirs();
209 var ret = new Gee.ArrayList<string>();
210 ret.add_all(this.package_cache);
211 for(var i = 0; i < vapidirs.length;i++) {
212 ret.add_all(this.loadPackages(vapidirs[i]));
218 public Gee.ArrayList<string> loadPackages(string dirname)
221 var ret = new Gee.ArrayList<string>();
222 //this.package_cache = new Gee.ArrayList<string>();
225 var dir = File.new_for_path(dirname);
227 var file_enum = dir.enumerate_children(
228 GLib.FileAttribute.STANDARD_DISPLAY_NAME,
229 GLib.FileQueryInfoFlags.NONE,
235 while ((next_file = file_enum.next_file(null)) != null) {
236 var fn = next_file.get_display_name();
237 if (!Regex.match_simple("\\.vapi$", fn)) {
240 ret.add(Path.get_basename(fn).replace(".vapi", ""));
243 print("oops - something went wrong scanning the packages\n");