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 this.package_cache = this.loadPackages(Path.get_dirname (context.get_vapi_path("glib-2.0")));
36 // various loader methods..
40 //this.comments = { };
44 public override void load () {
46 this.loadUsageFile(BuilderApplication.configDirectory() + "/resources/GtkUsage.txt");
51 public string doc(string what) {
52 var ns = what.split(".")[0];
53 var gir = Gir.factory(ns);
56 //return typeof(this.comments[ns][what]) == 'undefined' ? '' : this.comments[ns][what];
59 // does not handle implements...
60 public override GirObject? getClass(string ename)
63 var es = ename.split(".");
64 var gir = Gir.factory(es[0]);
66 return gir.classes.get(es[1]);
70 public override Gee.HashMap<string,GirObject> getPropertiesFor(string ename, string type)
72 //print("Loading for " + ename);
76 // if (typeof(this.proplist[ename]) != 'undefined') {
77 //print("using cache");
78 // return this.proplist[ename][type];
80 // use introspection to get lists..
82 var es = ename.split(".");
83 var gir = Gir.factory(es[0]);
85 var cls = gir.classes.get(es[1]);
87 var ret = new Gee.HashMap<string,GirObject>();
89 //throw new Error.INVALID_VALUE( "Could not find class: " + ename);
94 //cls.parseSignals(); // ?? needed for add handler..
95 //cls.parseMethods(); // ?? needed for ??..
96 //cls.parseConstructors(); // ?? needed for ??..
110 throw new Error.INVALID_VALUE( "getPropertiesFor called with: " + type);
111 //var ret = new Gee.HashMap<string,GirObject>();
117 //cls.overlayInterfaces(gir);
122 public string[] getInheritsFor(string ename)
126 var cls = Gir.factoryFqn(ename);
128 if (cls == null || cls.nodetype != "Class") {
129 print("getInheritsFor:could not find cls: %s\n", ename);
133 return cls.inheritsToStringArray();
138 public override void fillPack(JsRender.Node node,JsRender.Node parent)
141 string inherits = string.joinv(" ",
142 this.getInheritsFor (node.fqn())) + " ";
143 inherits += node.fqn() + " ";
144 //print ("fillPack:Inherits : %s\n", inherits);
145 // parent.fqn() method ( node.fqn()
146 var methods = this.getPropertiesFor (parent.fqn(), "methods");
148 var res = new Gee.HashMap<string,string>();
149 var map = methods.map_iterator();
152 var n = map.get_key();
153 //print ("fillPack:checking method %s\n", n);
155 var meth = map.get_value();
156 if (meth.paramset == null || meth.paramset.params.size < 1) {
157 print ("fillPack:c -- no params\n");
161 var fp = meth.paramset.params.get(0);
163 var type = Gir.fqtypeLookup(fp.type, meth.ns);
164 print ("fillPack:first param type is %s\n", type);
167 if (!inherits.contains(" " + type + " ")) {
172 var pack = meth.name;
173 for(var i =1; i < meth.paramset.params.size; i++) {
174 var ty = Gir.fqtypeLookup(meth.paramset.params.get(i).type, meth.ns);
175 pack += "," + Gir.guessDefaultValueForType(ty);
178 print ("fillPack:add pack: -- %s\n",pack );
180 res.set(meth.name, pack);
188 if (res.has_key("pack_start")) {
189 node.props.set("* pack", res.get("pack_start"));
192 if (res.has_key("add")) {
193 node.props.set("* pack", res.get("add"));
196 var riter = res.map_iterator();
197 while(riter.next()) {
198 node.props.set("* pack", riter.get_value());
204 public Gee.ArrayList<string> packages(Project.Gtk gproject)
206 var vapidirs = gproject.vapidirs();
207 var ret = new Gee.ArrayList<string>();
208 ret.add_all(this.package_cache);
209 for(var i = 0; i < vapidirs.length;i++) {
210 var add = this.loadPackages(vapidirs[i]);
211 for (var j=0; j < add.size; j++) {
212 if (ret.contains(add.get(j))) {
223 public Gee.ArrayList<string> loadPackages(string dirname)
226 var ret = new Gee.ArrayList<string>();
227 //this.package_cache = new Gee.ArrayList<string>();
230 var dir = File.new_for_path(dirname);
232 var file_enum = dir.enumerate_children(
233 GLib.FileAttribute.STANDARD_DISPLAY_NAME,
234 GLib.FileQueryInfoFlags.NONE,
240 while ((next_file = file_enum.next_file(null)) != null) {
241 var fn = next_file.get_display_name();
242 if (!Regex.match_simple("\\.vapi$", fn)) {
245 ret.add(Path.get_basename(fn).replace(".vapi", ""));
248 print("oops - something went wrong scanning the packages\n");