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("/usr/share/appBuilder/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...
58 public override Gee.HashMap<string,GirObject> getPropertiesFor(string ename, string type)
60 //print("Loading for " + ename);
64 // if (typeof(this.proplist[ename]) != 'undefined') {
65 //print("using cache");
66 // return this.proplist[ename][type];
68 // use introspection to get lists..
70 var es = ename.split(".");
71 var gir = Gir.factory(es[0]);
73 var cls = gir.classes.get(es[1]);
75 var ret = new Gee.HashMap<string,GirObject>();
77 //throw new Error.INVALID_VALUE( "Could not find class: " + ename);
82 //cls.parseSignals(); // ?? needed for add handler..
83 //cls.parseMethods(); // ?? needed for ??..
84 //cls.parseConstructors(); // ?? needed for ??..
98 throw new Error.INVALID_VALUE( "getPropertiesFor called with: " + type);
99 //var ret = new Gee.HashMap<string,GirObject>();
105 //cls.overlayInterfaces(gir);
110 public string[] getInheritsFor(string ename)
113 var es = ename.split(".");
114 var gir = Gir.factory(es[0]);
116 var cls = gir.classes.get(es[1]);
120 return cls.inheritsToStringArray();
125 genParams: function(sig, meth)
129 meth.ret_type = this.typeToName(GIRepository.callable_info_get_return_type(sig));
130 // might be a numbeR??
132 for(var a_i =0; a_i < GIRepository.callable_info_get_n_args(sig); a_i++) {
133 var arg = GIRepository.callable_info_get_arg(sig, a_i);
136 name : arg.get_name(),
137 type : this.typeToName(arg.get_type(), true)
145 genSkel: function(sig) // should really use genParams...
149 var ret_type = this.typeToName(GIRepository.callable_info_get_return_type(sig));
150 // might be a numbeR??
151 if (ret_type == 'boolean') {
152 ret = " return false;\n";
154 for(var a_i =0; a_i < GIRepository.callable_info_get_n_args(sig); a_i++) {
155 var arg = GIRepository.callable_info_get_arg(sig, a_i);
157 args.push(arg.get_name());
159 return 'function (' + args.join(', ') + ") {\n" + ret + "}";
164 typeToName : function (type_info, allow_iface) // find type for properties or arguments.
166 var ty = GIRepository.type_tag_to_string( GIRepository.type_info_get_tag(type_info));
168 if ((ty == 'void') && GIRepository.type_info_is_pointer(type_info)) {
172 return false; // unspported
174 if (ty != 'interface') {
177 // we can accept enum types here..
178 var interface_info = GIRepository.type_info_get_interface(type_info);
179 var interface_type = interface_info.get_type();
181 if (!allow_iface && interface_type != GIRepository.InfoType.ENUM) {
184 return interface_info.get_namespace() + '.' + interface_info.get_name();
188 * merge two proprety arrays' ignoring what's overrriden.
193 overrides : function (top, bottom)
197 return !top.every(function(t) {
198 if (t.name == b.name) {
204 bottom.forEach(function(e) {
216 findType : function (data, prop, value)
219 if ((prop == '|xns') || (prop == 'xtype')) {
223 var qname = this.guessName(data);
224 if (prop[0] == '|') {
225 prop= prop.substring(1);
228 var prs = this.getPropertiesFor(qname, 'props');
230 prs.forEach(function(e) {
234 if (e.name == prop) {
240 return Base.prototype.findType(data, prop,value);
247 findOptions : function(ename)
250 var es = ename.split('.');
252 return Base.prototype.findOptions(ename);
254 var gi = GIRepository.Repository.get_default();
255 var bi = gi.find_by_name(es[0], es[1]);
256 var etype = GIRepository.object_info_get_type(bi);
257 if (etype != GIRepository.InfoType.ENUM) {
258 console.log("Options not handled yet!!!");
262 // got an enum.. let's return the values..
263 for(var i =0; i < bi.get_n_values(); i++) {
265 var prop = bi.get_value(i);
268 ret.push( ename + '.' + prop.get_name().toUpperCase() )
273 * determine the packing types..
275 getDefaultPack: function(pname, cname) {
276 var list = this.getPackingList(pname,cname);
277 // console.dump(list);
280 if (!list.every(function(e) { return e.name != 'add'; })) {
281 return 'add'; // add is in our list..?? what about args..?!?
285 e.params.forEach(function(p,i) {
286 if (ret === false) { return; } // skip broken..
287 if (i==0) { return; } // skip first..
288 if (p.type == 'boolean') {
292 if (p.type == 'number') {
296 if (p.type == 'uint') {
300 ret = false; // invalid!
302 return ret === false ? false : ret.join(',');
305 list.every(function(e) {
308 //print("DEFAULT PACK TEST : " + e.name + " : " +packret);
309 if (packret !== false) {
312 return true; // continue
314 //print("DEFAULT PACK: " + packret);
315 // should we do best match..?
321 getPackingList :function (pname, cname)
323 var funcs = this.getPropertiesFor(pname,'methods');
324 //print("getPackingList : ALL FUNCS");
325 //console.dump(funcs);
328 // let's assume top down...
329 var inherits = [ cname ];
330 inherits.push.apply(inherits, this.getPropertiesFor(cname,'inherits'));
331 funcs.forEach(function(m) {
332 if (m.params.length && (typeof(m.params[0].type) == 'string') &&
333 inherits.indexOf(m.params[0].type) > -1) {
341 public override void fillPack(JsRender.Node node,JsRender.Node parent)
344 string inherits = " " + string.joinv(" ", this.getInheritsFor (node.fqn())) + " ";
345 // parent.fqn() method ( node.fqn()
346 var methods = this.getPropertiesFor (parent.fqn(), "methods");
348 var map = methods.map_iterator();
350 var n = map.get_key();
351 var meth = map.get_value();
352 if (meth.paramset == null || meth.paramset.params.length() < 1) {
355 var fp = meth.paramset.params.nth_data(0);
356 var type = Gir.fqtype(fp.type, meth.ns);
357 if (!inherits.contains(" " + type + " ")) {
360 var pack = meth.name;
361 for(var i =1; i < meth.paramset.params.length(); i++) {
362 var ty = Gir.fqtype(meth.paramset.params.nth_data(i).type, meth.ns);
363 pack += "," + Gir.guessDefaultValueForType(ty);
365 node.set("pack", pack);