7 public class Introspect.El : Object
21 public class Gtk : Palete {
33 // various loader methods..
37 //this.comments = { };
41 public override void load () {
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>();
62 for (var i = 0; i < data.length; i++) {
63 var d = data[i].strip();
64 //print("READ " + d + "\n");
68 Regex.match_simple ("^\\s+$", d)
70 Regex.match_simple ("^\\s*/", d)
75 if (Regex.match_simple ("^left:", d)) {
77 if (left.length() > 0 ){
78 cfg.append(new Usage( left, right));
84 if (Regex.match_simple ("^right:", d)) {
89 //print("add left: " + d + "\n");
93 //print("add Right: " + d + "\n");
98 if (left.length > 0 ){
99 cfg.append(new Usage( left, right));
101 this.map = cfg.copy();
105 public string doc(string what) {
106 var ns = what.split(".")[0];
107 var gir = Gir.factory(ns);
108 return gir.doc(what);
110 //return typeof(this.comments[ns][what]) == 'undefined' ? '' : this.comments[ns][what];
113 // does not handle implements...
115 public Gee.HashMap<string,GirObject> getPropertiesFor(string ename, string type)
117 //print("Loading for " + ename);
121 // if (typeof(this.proplist[ename]) != 'undefined') {
122 //print("using cache");
123 // return this.proplist[ename][type];
125 // use introspection to get lists..
127 var es = ename.split(".");
128 var gir = Gir.factory(es[0]);
130 var cls = gir.classes.get(es[1]);
132 var ret = new Gee.HashMap<string,GirObject>();
134 //throw new Error.INVALID_VALUE( "Could not find class: " + ename);
139 //cls.parseSignals(); // ?? needed for add handler..
140 //cls.parseMethods(); // ?? needed for ??..
141 //cls.parseConstructors(); // ?? needed for ??..
155 throw new Error.INVALID_VALUE( "getPropertiesFor called with: " + type);
156 //var ret = new Gee.HashMap<string,GirObject>();
162 //cls.overlayInterfaces(gir);
167 public string[] getInheritsFor(string ename)
170 var es = ename.split(".");
171 var gir = Gir.factory(es[0]);
173 var cls = gir.classes.get(es[1]);
177 return cls.inheritsToStringArray();
182 genParams: function(sig, meth)
186 meth.ret_type = this.typeToName(GIRepository.callable_info_get_return_type(sig));
187 // might be a numbeR??
189 for(var a_i =0; a_i < GIRepository.callable_info_get_n_args(sig); a_i++) {
190 var arg = GIRepository.callable_info_get_arg(sig, a_i);
193 name : arg.get_name(),
194 type : this.typeToName(arg.get_type(), true)
202 genSkel: function(sig) // should really use genParams...
206 var ret_type = this.typeToName(GIRepository.callable_info_get_return_type(sig));
207 // might be a numbeR??
208 if (ret_type == 'boolean') {
209 ret = " return false;\n";
211 for(var a_i =0; a_i < GIRepository.callable_info_get_n_args(sig); a_i++) {
212 var arg = GIRepository.callable_info_get_arg(sig, a_i);
214 args.push(arg.get_name());
216 return 'function (' + args.join(', ') + ") {\n" + ret + "}";
221 typeToName : function (type_info, allow_iface) // find type for properties or arguments.
223 var ty = GIRepository.type_tag_to_string( GIRepository.type_info_get_tag(type_info));
225 if ((ty == 'void') && GIRepository.type_info_is_pointer(type_info)) {
229 return false; // unspported
231 if (ty != 'interface') {
234 // we can accept enum types here..
235 var interface_info = GIRepository.type_info_get_interface(type_info);
236 var interface_type = interface_info.get_type();
238 if (!allow_iface && interface_type != GIRepository.InfoType.ENUM) {
241 return interface_info.get_namespace() + '.' + interface_info.get_name();
245 * merge two proprety arrays' ignoring what's overrriden.
250 overrides : function (top, bottom)
254 return !top.every(function(t) {
255 if (t.name == b.name) {
261 bottom.forEach(function(e) {
273 findType : function (data, prop, value)
276 if ((prop == '|xns') || (prop == 'xtype')) {
280 var qname = this.guessName(data);
281 if (prop[0] == '|') {
282 prop= prop.substring(1);
285 var prs = this.getPropertiesFor(qname, 'props');
287 prs.forEach(function(e) {
291 if (e.name == prop) {
297 return Base.prototype.findType(data, prop,value);
304 findOptions : function(ename)
307 var es = ename.split('.');
309 return Base.prototype.findOptions(ename);
311 var gi = GIRepository.Repository.get_default();
312 var bi = gi.find_by_name(es[0], es[1]);
313 var etype = GIRepository.object_info_get_type(bi);
314 if (etype != GIRepository.InfoType.ENUM) {
315 console.log("Options not handled yet!!!");
319 // got an enum.. let's return the values..
320 for(var i =0; i < bi.get_n_values(); i++) {
322 var prop = bi.get_value(i);
325 ret.push( ename + '.' + prop.get_name().toUpperCase() )
330 * determine the packing types..
332 getDefaultPack: function(pname, cname) {
333 var list = this.getPackingList(pname,cname);
334 // console.dump(list);
337 if (!list.every(function(e) { return e.name != 'add'; })) {
338 return 'add'; // add is in our list..?? what about args..?!?
342 e.params.forEach(function(p,i) {
343 if (ret === false) { return; } // skip broken..
344 if (i==0) { return; } // skip first..
345 if (p.type == 'boolean') {
349 if (p.type == 'number') {
353 if (p.type == 'uint') {
357 ret = false; // invalid!
359 return ret === false ? false : ret.join(',');
362 list.every(function(e) {
365 //print("DEFAULT PACK TEST : " + e.name + " : " +packret);
366 if (packret !== false) {
369 return true; // continue
371 //print("DEFAULT PACK: " + packret);
372 // should we do best match..?
378 getPackingList :function (pname, cname)
380 var funcs = this.getPropertiesFor(pname,'methods');
381 //print("getPackingList : ALL FUNCS");
382 //console.dump(funcs);
385 // let's assume top down...
386 var inherits = [ cname ];
387 inherits.push.apply(inherits, this.getPropertiesFor(cname,'inherits'));
388 funcs.forEach(function(m) {
389 if (m.params.length && (typeof(m.params[0].type) == 'string') &&
390 inherits.indexOf(m.params[0].type) > -1) {
398 public override void fillPack(JsRender.Node node,JsRender.Node parent)
401 string inherits = " " + string.joinv(" ", this.getInheritsFor (node.fqn())) + " ";
402 // parent.fqn() method ( node.fqn()
403 var methods = this.getPropertiesFor (parent.fqn(), "methods");
405 var map = methods.map_iterator();
407 var n = map.get_key();
408 var meth = map.get_value();
409 if (meth.paramset == null || meth.paramset.params.length() < 1) {
412 var fp = meth.paramset.params.nth_data(0);
413 var type = Gir.fqtype(fp.type, meth.ns);
414 if (!inherits.contains(" " + type + " ")) {
417 var pack = meth.name;
418 for(var i =1; i < meth.paramset.params.length(); i++) {
419 var ty = Gir.fqtype(meth.paramset.params.nth_data(i).type, meth.ns);
420 pack += "," + Gir.guessDefaultValueForType(ty);
422 node.set("pack", pack);