7 public class Introspect.El : Object
21 public class Gtk : Palete {
33 // various loader methods..
37 //this.comments = { };
41 public override void load () {
43 this.loadUsageFile(Builder4.Application.configDirectory() + "/resources/GtkUsage.txt");
48 public string doc(string what) {
49 var ns = what.split(".")[0];
50 var gir = Gir.factory(ns);
53 //return typeof(this.comments[ns][what]) == 'undefined' ? '' : this.comments[ns][what];
56 // does not handle implements...
57 public override GirObject? getClass(string ename)
60 var es = ename.split(".");
61 var gir = Gir.factory(es[0]);
63 return gir.classes.get(es[1]);
67 public override Gee.HashMap<string,GirObject> getPropertiesFor(string ename, string type)
69 //print("Loading for " + ename);
73 // if (typeof(this.proplist[ename]) != 'undefined') {
74 //print("using cache");
75 // return this.proplist[ename][type];
77 // use introspection to get lists..
79 var es = ename.split(".");
80 var gir = Gir.factory(es[0]);
82 var cls = gir.classes.get(es[1]);
84 var ret = new Gee.HashMap<string,GirObject>();
86 //throw new Error.INVALID_VALUE( "Could not find class: " + ename);
91 //cls.parseSignals(); // ?? needed for add handler..
92 //cls.parseMethods(); // ?? needed for ??..
93 //cls.parseConstructors(); // ?? needed for ??..
107 throw new Error.INVALID_VALUE( "getPropertiesFor called with: " + type);
108 //var ret = new Gee.HashMap<string,GirObject>();
114 //cls.overlayInterfaces(gir);
119 public string[] getInheritsFor(string ename)
123 var cls = Gir.factoryFqn(ename);
125 if (cls == null || cls.nodetype != "Class") {
126 print("getInheritsFor:could not find cls: %s\n", ename);
130 return cls.inheritsToStringArray();
135 genParams: function(sig, meth)
139 meth.ret_type = this.typeToName(GIRepository.callable_info_get_return_type(sig));
140 // might be a numbeR??
142 for(var a_i =0; a_i < GIRepository.callable_info_get_n_args(sig); a_i++) {
143 var arg = GIRepository.callable_info_get_arg(sig, a_i);
146 name : arg.get_name(),
147 type : this.typeToName(arg.get_type(), true)
155 genSkel: function(sig) // should really use genParams...
159 var ret_type = this.typeToName(GIRepository.callable_info_get_return_type(sig));
160 // might be a numbeR??
161 if (ret_type == 'boolean') {
162 ret = " return false;\n";
164 for(var a_i =0; a_i < GIRepository.callable_info_get_n_args(sig); a_i++) {
165 var arg = GIRepository.callable_info_get_arg(sig, a_i);
167 args.push(arg.get_name());
169 return 'function (' + args.join(', ') + ") {\n" + ret + "}";
174 typeToName : function (type_info, allow_iface) // find type for properties or arguments.
176 var ty = GIRepository.type_tag_to_string( GIRepository.type_info_get_tag(type_info));
178 if ((ty == 'void') && GIRepository.type_info_is_pointer(type_info)) {
182 return false; // unspported
184 if (ty != 'interface') {
187 // we can accept enum types here..
188 var interface_info = GIRepository.type_info_get_interface(type_info);
189 var interface_type = interface_info.get_type();
191 if (!allow_iface && interface_type != GIRepository.InfoType.ENUM) {
194 return interface_info.get_namespace() + '.' + interface_info.get_name();
198 * merge two proprety arrays' ignoring what's overrriden.
203 overrides : function (top, bottom)
207 return !top.every(function(t) {
208 if (t.name == b.name) {
214 bottom.forEach(function(e) {
226 findType : function (data, prop, value)
229 if ((prop == '|xns') || (prop == 'xtype')) {
233 var qname = this.guessName(data);
234 if (prop[0] == '|') {
235 prop= prop.substring(1);
238 var prs = this.getPropertiesFor(qname, 'props');
240 prs.forEach(function(e) {
244 if (e.name == prop) {
250 return Base.prototype.findType(data, prop,value);
257 findOptions : function(ename)
260 var es = ename.split('.');
262 return Base.prototype.findOptions(ename);
264 var gi = GIRepository.Repository.get_default();
265 var bi = gi.find_by_name(es[0], es[1]);
266 var etype = GIRepository.object_info_get_type(bi);
267 if (etype != GIRepository.InfoType.ENUM) {
268 console.log("Options not handled yet!!!");
272 // got an enum.. let's return the values..
273 for(var i =0; i < bi.get_n_values(); i++) {
275 var prop = bi.get_value(i);
278 ret.push( ename + '.' + prop.get_name().toUpperCase() )
283 * determine the packing types..
285 getDefaultPack: function(pname, cname) {
286 var list = this.getPackingList(pname,cname);
287 // console.dump(list);
290 if (!list.every(function(e) { return e.name != 'add'; })) {
291 return 'add'; // add is in our list..?? what about args..?!?
295 e.params.forEach(function(p,i) {
296 if (ret === false) { return; } // skip broken..
297 if (i==0) { return; } // skip first..
298 if (p.type == 'boolean') {
302 if (p.type == 'number') {
306 if (p.type == 'uint') {
310 ret = false; // invalid!
312 return ret === false ? false : ret.join(',');
315 list.every(function(e) {
318 //print("DEFAULT PACK TEST : " + e.name + " : " +packret);
319 if (packret !== false) {
322 return true; // continue
324 //print("DEFAULT PACK: " + packret);
325 // should we do best match..?
331 getPackingList :function (pname, cname)
333 var funcs = this.getPropertiesFor(pname,'methods');
334 //print("getPackingList : ALL FUNCS");
335 //console.dump(funcs);
338 // let's assume top down...
339 var inherits = [ cname ];
340 inherits.push.apply(inherits, this.getPropertiesFor(cname,'inherits'));
341 funcs.forEach(function(m) {
342 if (m.params.length && (typeof(m.params[0].type) == 'string') &&
343 inherits.indexOf(m.params[0].type) > -1) {
351 public override void fillPack(JsRender.Node node,JsRender.Node parent)
354 string inherits = string.joinv(" ",
355 this.getInheritsFor (node.fqn())) + " ";
356 inherits += node.fqn() + " ";
357 //print ("fillPack:Inherits : %s\n", inherits);
358 // parent.fqn() method ( node.fqn()
359 var methods = this.getPropertiesFor (parent.fqn(), "methods");
361 var res = new Gee.HashMap<string,string>();
362 var map = methods.map_iterator();
365 var n = map.get_key();
366 //print ("fillPack:checking method %s\n", n);
368 var meth = map.get_value();
369 if (meth.paramset == null || meth.paramset.params.size < 1) {
370 print ("fillPack:c -- no params\n");
374 var fp = meth.paramset.params.get(0);
376 var type = Gir.fqtypeLookup(fp.type, meth.ns);
377 print ("fillPack:first param type is %s\n", type);
380 if (!inherits.contains(" " + type + " ")) {
385 var pack = meth.name;
386 for(var i =1; i < meth.paramset.params.size; i++) {
387 var ty = Gir.fqtypeLookup(meth.paramset.params.get(i).type, meth.ns);
388 pack += "," + Gir.guessDefaultValueForType(ty);
391 print ("fillPack:add pack: -- %s\n",pack );
393 res.set(meth.name, pack);
401 if (res.has_key("pack_start")) {
402 node.props.set("* pack", res.get("pack_start"));
405 if (res.has_key("add")) {
406 node.props.set("* pack", res.get("add"));
409 var riter = res.map_iterator();
410 while(riter.next()) {
411 node.props.set("* pack", riter.get_value());