7 public class Introspect.El : Object
21 public class Gtk : Palete {
33 // various loader methods..
37 //this.comments = { };
46 print("Palete Load called\n");
48 if (!FileUtils.test ("/usr/share/appBuilder/GtkUsage.txt", FileTest.EXISTS)) {
49 throw new Error.MISSING_FILE("/usr/share/appBuilder/GtkUsage.txt not found");
53 FileUtils.get_contents("/usr/share/appBuilder/GtkUsage.txt", out raw);
55 var data = raw.split("\n");
57 var cfg = new GLib.List<Usage>();
58 var left = new GLib.List<string>();
59 var right = new GLib.List<string>();
61 for (var i = 0; i < data.length; i++) {
62 var d = data[i].strip();
63 //print("READ " + d + "\n");
67 Regex.match_simple ("^\\s+$", d)
69 Regex.match_simple ("^\\s*/", d)
74 if (Regex.match_simple ("^left:", d)) {
76 if (left.length() > 0 ){
77 cfg.append(new Usage( left, right));
79 left = new GLib.List<string>();
80 right = new GLib.List<string>();
83 if (Regex.match_simple ("^right:", d)) {
88 //print("add left: " + d + "\n");
92 //print("add Right: " + d + "\n");
97 if (left.length() > 0 ){
98 cfg.append(new Usage( left, right));
100 this.map = cfg.copy();
104 public string doc(string what) {
105 var ns = what.split(".")[0];
106 var gir = Gir.factory(ns);
107 return gir.doc(what);
109 //return typeof(this.comments[ns][what]) == 'undefined' ? '' : this.comments[ns][what];
112 // does not handle implements...
114 public Gee.HashMap<string,GirObject> getPropertiesFor(string ename, string type)
116 //print("Loading for " + ename);
120 // if (typeof(this.proplist[ename]) != 'undefined') {
121 //print("using cache");
122 // return this.proplist[ename][type];
124 // use introspection to get lists..
126 var es = ename.split(".");
127 var gir = Gir.factory(es[0]);
129 var cls = gir.classes.get(es[1]);
131 var ret = new Gee.HashMap<string,GirObject>();
133 //throw new Error.INVALID_VALUE( "Could not find class: " + ename);
138 //cls.parseSignals(); // ?? needed for add handler..
139 //cls.parseMethods(); // ?? needed for ??..
140 //cls.parseConstructors(); // ?? needed for ??..
154 throw new Error.INVALID_VALUE( "getPropertiesFor called with: " + type);
155 //var ret = new Gee.HashMap<string,GirObject>();
161 //cls.overlayInterfaces(gir);
166 public string[] getInheritsFor(string ename)
169 var es = ename.split(".");
170 var gir = Gir.factory(es[0]);
172 var cls = gir.classes.get(es[1]);
176 return cls.inheritsToStringArray();
181 genParams: function(sig, meth)
185 meth.ret_type = this.typeToName(GIRepository.callable_info_get_return_type(sig));
186 // might be a numbeR??
188 for(var a_i =0; a_i < GIRepository.callable_info_get_n_args(sig); a_i++) {
189 var arg = GIRepository.callable_info_get_arg(sig, a_i);
192 name : arg.get_name(),
193 type : this.typeToName(arg.get_type(), true)
201 genSkel: function(sig) // should really use genParams...
205 var ret_type = this.typeToName(GIRepository.callable_info_get_return_type(sig));
206 // might be a numbeR??
207 if (ret_type == 'boolean') {
208 ret = " return false;\n";
210 for(var a_i =0; a_i < GIRepository.callable_info_get_n_args(sig); a_i++) {
211 var arg = GIRepository.callable_info_get_arg(sig, a_i);
213 args.push(arg.get_name());
215 return 'function (' + args.join(', ') + ") {\n" + ret + "}";
220 typeToName : function (type_info, allow_iface) // find type for properties or arguments.
222 var ty = GIRepository.type_tag_to_string( GIRepository.type_info_get_tag(type_info));
224 if ((ty == 'void') && GIRepository.type_info_is_pointer(type_info)) {
228 return false; // unspported
230 if (ty != 'interface') {
233 // we can accept enum types here..
234 var interface_info = GIRepository.type_info_get_interface(type_info);
235 var interface_type = interface_info.get_type();
237 if (!allow_iface && interface_type != GIRepository.InfoType.ENUM) {
240 return interface_info.get_namespace() + '.' + interface_info.get_name();
244 * merge two proprety arrays' ignoring what's overrriden.
249 overrides : function (top, bottom)
253 return !top.every(function(t) {
254 if (t.name == b.name) {
260 bottom.forEach(function(e) {
272 findType : function (data, prop, value)
275 if ((prop == '|xns') || (prop == 'xtype')) {
279 var qname = this.guessName(data);
280 if (prop[0] == '|') {
281 prop= prop.substring(1);
284 var prs = this.getPropertiesFor(qname, 'props');
286 prs.forEach(function(e) {
290 if (e.name == prop) {
296 return Base.prototype.findType(data, prop,value);
303 findOptions : function(ename)
306 var es = ename.split('.');
308 return Base.prototype.findOptions(ename);
310 var gi = GIRepository.Repository.get_default();
311 var bi = gi.find_by_name(es[0], es[1]);
312 var etype = GIRepository.object_info_get_type(bi);
313 if (etype != GIRepository.InfoType.ENUM) {
314 console.log("Options not handled yet!!!");
318 // got an enum.. let's return the values..
319 for(var i =0; i < bi.get_n_values(); i++) {
321 var prop = bi.get_value(i);
324 ret.push( ename + '.' + prop.get_name().toUpperCase() )
329 * determine the packing types..
331 getDefaultPack: function(pname, cname) {
332 var list = this.getPackingList(pname,cname);
333 // console.dump(list);
336 if (!list.every(function(e) { return e.name != 'add'; })) {
337 return 'add'; // add is in our list..?? what about args..?!?
341 e.params.forEach(function(p,i) {
342 if (ret === false) { return; } // skip broken..
343 if (i==0) { return; } // skip first..
344 if (p.type == 'boolean') {
348 if (p.type == 'number') {
352 if (p.type == 'uint') {
356 ret = false; // invalid!
358 return ret === false ? false : ret.join(',');
361 list.every(function(e) {
364 //print("DEFAULT PACK TEST : " + e.name + " : " +packret);
365 if (packret !== false) {
368 return true; // continue
370 //print("DEFAULT PACK: " + packret);
371 // should we do best match..?
377 getPackingList :function (pname, cname)
379 var funcs = this.getPropertiesFor(pname,'methods');
380 //print("getPackingList : ALL FUNCS");
381 //console.dump(funcs);
384 // let's assume top down...
385 var inherits = [ cname ];
386 inherits.push.apply(inherits, this.getPropertiesFor(cname,'inherits'));
387 funcs.forEach(function(m) {
388 if (m.params.length && (typeof(m.params[0].type) == 'string') &&
389 inherits.indexOf(m.params[0].type) > -1) {
397 public override void fillPack(JsRender.Node node,JsRender.Node parent)
400 string inherits = " " + string.joinv(" ", this.getInheritsFor (node.fqn())) + " ";
401 // parent.fqn() method ( node.fqn()
402 var methods = this.getPropertiesFor (parent.fqn(), "methods");
404 var map = methods.map_iterator();
406 var n = map.get_key();
407 var meth = map.get_value();
408 if (meth.paramset == null || meth.paramset.params.length() < 1) {
411 var fp = meth.paramset.params.nth_data(0);
412 var type = Gir.fqtype(fp.type, meth.ns);
413 if (!inherits.contains(" " + type + " ")) {
416 var pack = meth.name;
417 for(var i =1; i < meth.paramset.params.length(); i++) {
418 var ty = Gir.fqtype(meth.paramset.params.nth_data(i).type, meth.ns);
419 pack += "," + Gir.guessDefaultValueForType(ty);
421 node.set("pack", pack);