7 public class Introspect.El : Object
21 public class Gtk : Palete {
23 public Gee.ArrayList<string> package_cache;
34 // various loader methods..
38 //this.comments = { };
42 public override void load () {
44 this.loadUsageFile(Builder4.Application.configDirectory() + "/resources/GtkUsage.txt");
49 public string doc(string what) {
50 var ns = what.split(".")[0];
51 var gir = Gir.factory(ns);
54 //return typeof(this.comments[ns][what]) == 'undefined' ? '' : this.comments[ns][what];
57 // does not handle implements...
58 public override GirObject? getClass(string ename)
61 var es = ename.split(".");
62 var gir = Gir.factory(es[0]);
64 return gir.classes.get(es[1]);
68 public override Gee.HashMap<string,GirObject> getPropertiesFor(string ename, string type)
70 //print("Loading for " + ename);
74 // if (typeof(this.proplist[ename]) != 'undefined') {
75 //print("using cache");
76 // return this.proplist[ename][type];
78 // use introspection to get lists..
80 var es = ename.split(".");
81 var gir = Gir.factory(es[0]);
83 var cls = gir.classes.get(es[1]);
85 var ret = new Gee.HashMap<string,GirObject>();
87 //throw new Error.INVALID_VALUE( "Could not find class: " + ename);
92 //cls.parseSignals(); // ?? needed for add handler..
93 //cls.parseMethods(); // ?? needed for ??..
94 //cls.parseConstructors(); // ?? needed for ??..
108 throw new Error.INVALID_VALUE( "getPropertiesFor called with: " + type);
109 //var ret = new Gee.HashMap<string,GirObject>();
115 //cls.overlayInterfaces(gir);
120 public string[] getInheritsFor(string ename)
124 var cls = Gir.factoryFqn(ename);
126 if (cls == null || cls.nodetype != "Class") {
127 print("getInheritsFor:could not find cls: %s\n", ename);
131 return cls.inheritsToStringArray();
136 public override void fillPack(JsRender.Node node,JsRender.Node parent)
139 string inherits = string.joinv(" ",
140 this.getInheritsFor (node.fqn())) + " ";
141 inherits += node.fqn() + " ";
142 //print ("fillPack:Inherits : %s\n", inherits);
143 // parent.fqn() method ( node.fqn()
144 var methods = this.getPropertiesFor (parent.fqn(), "methods");
146 var res = new Gee.HashMap<string,string>();
147 var map = methods.map_iterator();
150 var n = map.get_key();
151 //print ("fillPack:checking method %s\n", n);
153 var meth = map.get_value();
154 if (meth.paramset == null || meth.paramset.params.size < 1) {
155 print ("fillPack:c -- no params\n");
159 var fp = meth.paramset.params.get(0);
161 var type = Gir.fqtypeLookup(fp.type, meth.ns);
162 print ("fillPack:first param type is %s\n", type);
165 if (!inherits.contains(" " + type + " ")) {
170 var pack = meth.name;
171 for(var i =1; i < meth.paramset.params.size; i++) {
172 var ty = Gir.fqtypeLookup(meth.paramset.params.get(i).type, meth.ns);
173 pack += "," + Gir.guessDefaultValueForType(ty);
176 print ("fillPack:add pack: -- %s\n",pack );
178 res.set(meth.name, pack);
186 if (res.has_key("pack_start")) {
187 node.props.set("* pack", res.get("pack_start"));
190 if (res.has_key("add")) {
191 node.props.set("* pack", res.get("add"));
194 var riter = res.map_iterator();
195 while(riter.next()) {
196 node.props.set("* pack", riter.get_value());
202 public Gee.ArrayList<string> packages()
204 return this.package_cache;
207 public void loadPackages()
211 this.package_cache = new Gee.ArrayList<string>();
212 var context = new Vala.CodeContext ();
213 var dirname = Path.get_dirname (context.get_vapi_path("glib-2.0"));
215 var dir = File.new_for_path(dirname);
217 var file_enum = dir.enumerate_children(
218 GLib.FileAttribute.STANDARD_DISPLAY_NAME,
219 GLib.FileQueryInfoFlags.NONE,
225 while ((next_file = file_enum.next_file(null)) != null) {
226 var fn = next_file.get_display_name();
227 if (!Regex.match_simple("\\.vapi$", fn)) {
230 this.package_cache.add(Path.get_basename(fn).replace(".vapi", ""));
233 print("oops - something went wrong scanning the packages\n");