1 //<Script type="text/javascript">
4 GIRepository = imports.gi.GIRepository;
5 GObject= imports.gi.GObject;
7 console = imports.console;
8 XObject = imports.XObject.XObject;
10 Base = imports.Palete.Base.Base;
11 File = imports.File.File;
12 //----------------------- our roo verison
21 // various loader methods..
38 var data = File.read(__script_path__ +'/GtkUsage.txt');
40 data = data.split(/\n/g);
46 data.forEach( function(d) {
47 if (!d.length || d.match(/^\s+$/) || d.match(/^\s*\//)) { //empty
50 if (d.match(/^left:/)) {
63 if (d.match(/^right:/)) {
68 left.push(d.replace(/\s+/g, ''));
71 right.push(d.replace(/\s+/g, ''));
87 commentLoad : function(ns)
90 if (typeof(this.comments[ns]) != 'undefined') {
94 console.log("LOAD DOCS: " + ns);
95 var gi = GIRepository.Repository.get_default();
96 var ver = gi.get_version(ns);
98 this.comments[ns] = {};
103 // no idea why this is broken on my build system.
104 function getAttribute(n, name){
105 var properties = n.properties;
107 if (properties.name == name)
108 return properties.children.content;
109 properties = properties.next
115 function walk(element, path) {
122 var n = getAttribute(element, 'name') ;
123 //console.log("WALK" + n);
124 if (element.name == 'signal') {
128 path += path.length ? '.' : '';
131 if (element.name == 'return-value') {
132 path += '.return-value';
137 var d = getAttribute(element,'doc');
139 // Seed.print(path + ':' + d);
143 var child = element.children;
146 //console.log(child.tag);
147 if (child.type == "element"){
154 var pth = GIRepository.Repository.get_search_path ();
157 var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
161 var fn = gir_path + '/'+ ns + '-' + ver + '.gir';
164 if (!File.exists(fn)) {
165 console.log('missing docc file ' + fn);
166 this.comments[ns] = {};
170 var doc = xml.parseFile(fn);
171 //console.log("xmldoc?" + doc);
174 this.comments[ns] = ret;
180 doc : function(what) {
181 var ns = what.split('.').shift();
182 this.commentLoad(ns);
183 return typeof(this.comments[ns][what]) == 'undefined' ? '' : this.comments[ns][what];
186 getPropertiesFor: function(ename, type)
188 //print("Loading for " + ename);
190 if (typeof(this.proplist[ename]) != 'undefined') {
191 //print("using cache");
192 return this.proplist[ename][type];
194 // use introspection to get lists..
195 var gi = GIRepository.Repository.get_default();
196 var es = ename.split('.');
199 giname = giname == 'Glade' ? 'Gladeui' : giname;
202 var bi = gi.find_by_name(giname , es[1]);
205 print("COULND NOT FIND BY NAME");
208 var etype = bi.get_type();;
209 var meth = etype == GIRepository.InfoType.INTERFACE ?
211 'interface_info_get_n_properties',
212 'interface_info_get_property',
213 'interface_info_get_n_signals',
214 'interface_info_get_signal',
215 'interface_info_get_n_methods',
216 'interface_info_get_method'
218 'object_info_get_n_properties',
219 'object_info_get_property',
220 'object_info_get_n_signals',
221 'object_info_get_signal',
222 'object_info_get_n_methods',
223 'object_info_get_method'
227 this.proplist[ename] = {}
228 this.proplist[ename]['props'] = [];
229 this.proplist[ename]['events'] = [];
230 this.proplist[ename]['methods'] = [];
231 this.proplist[ename]['inherits']= [];
233 var plist = this.proplist[ename]['props'] ;
234 var elist = this.proplist[ename]['events'];
235 var mlist = this.proplist[ename]['methods'];
236 var ilist = this.proplist[ename]['inherits'];
244 // properties.. -- and parent ones...!!!
245 for (var i =0;i < GIRepository[meth[0]](bi); i++) {
246 var prop = GIRepository[meth[1]](bi,i);
247 var n_original = prop.get_name();
249 var flags = GIRepository.property_info_get_flags(prop); // check for readonly..
252 var ty = this.typeToName(GIRepository.property_info_get_type(prop));
253 var flags = GIRepository.property_info_get_flags(prop);
254 print (n_original +":"+ ty);
259 name : n_original.replace(/\-/g, '_'),
261 desc : this.doc(ename + '.' + n_original),
263 ctor_only : (flags & GObject.ParamFlags.CONSTRUCT_ONLY) > 0
274 for (var i =0;i < GIRepository[meth[2]](bi); i++) {
275 var prop =GIRepository[meth[3]](bi,i);
276 var n_original = prop.get_name();
277 // print ('signal: ' + n_original);
279 name : n_original.replace(/\-/g, '_'),
280 type : 'function', //???
281 desc : this.doc(ename + '.signal.' + n_original),
282 sig : this.genSkel(prop) // fixme..
288 for (var i =0;i < GIRepository[meth[4]](bi); i++) {
289 var prop = GIRepository[meth[5]](bi,i);
290 var n_original = prop.get_name();
291 print(ename +": ADD method: " + n_original );
292 //var flags = GIRepository.property_info_get_flags(prop);
294 if (n_original.match(/^new/)) {
296 name : n_original.replace(/\-/g, '_'),
299 //desc : this.doc(ename + "."+ n_original)
301 this.genParams(prop,add);
306 // not sure why we need all the other ones...
307 //if (!(flags & GIRepository.FunctionInfoFlags.IS_METHOD)) {
310 // print ('signal: ' + n_original);
312 name : n_original.replace(/\-/g, '_'),
313 type : 'function', //???
314 desc : '', //this.doc(ename + '.' + n_original)
316 this.genParams(prop,add);
325 if (etype == GIRepository.InfoType.INTERFACE ) {
326 // print("SKIPPING PARENT - it's an interface?!?!");
331 var pi = GIRepository.object_info_get_parent(bi);
336 var pname = pi.get_namespace() + '.' + pi.get_name();
337 this.getPropertiesFor(pname, 'props');
340 elist.push.apply(elist,this.proplist[pname]['events']);
341 plist.push.apply(plist,this.proplist[pname]['props']);
343 ilist.push.apply(ilist,this.proplist[pname]['inherits']);
345 this.overrides(mlist, this.proplist[pname]['methods']);
349 print("NO PARENT FOUND?");
352 // implements needs to be more carefull as it could add dupes..
353 // use the parent implements list to ensure no dupes..
354 for(var i =0; i < GIRepository.object_info_get_n_interfaces(bi); i++) {
356 var prop = GIRepository.object_info_get_interface(bi,i);
357 var iface = prop.get_namespace() +'.'+ prop.get_name();
358 if ( ilist.indexOf(iface) > -1) {
361 this.getPropertiesFor(iface, 'props'); // just load one of them..
364 elist.push.apply(elist,this.proplist[iface]['events']);
365 plist.push.apply(plist,this.proplist[iface]['props']);
366 this.overrides(mlist, this.proplist[pname]['methods']);
368 function sfunc(a,b) {
369 if (a.name == b.name) return 0;
370 return a.name > b.name ? 1 : -1
376 return this.proplist[ename][type];
379 genParams: function(sig, meth)
383 meth.ret_type = this.typeToName(GIRepository.callable_info_get_return_type(sig));
384 // might be a numbeR??
386 for(var a_i =0; a_i < GIRepository.callable_info_get_n_args(sig); a_i++) {
387 var arg = GIRepository.callable_info_get_arg(sig, a_i);
388 print(arg.get_name());
389 print(arg.get_type());
391 name : arg.get_name(),
392 type : this.typeToName(arg.get_type(), true)
400 genSkel: function(sig) // should really use genParams...
404 var ret_type = this.typeToName(GIRepository.callable_info_get_return_type(sig));
405 // might be a numbeR??
406 if (ret_type == 'boolean') {
407 ret = " return false;\n";
409 for(var a_i =0; a_i < GIRepository.callable_info_get_n_args(sig); a_i++) {
410 var arg = GIRepository.callable_info_get_arg(sig, a_i);
412 args.push(arg.get_name());
414 return 'function (' + args.join(', ') + ") {\n" + ret + "}";
419 typeToName : function (type_info, allow_iface) // find type for properties or arguments.
422 if (type_info == 17) {
426 var x = GIRepository.type_info_get_tag(type_info);
428 var ty = GIRepository.type_tag_to_string( GIRepository.type_info_get_tag(type_info));
431 if ((ty == 'void') && GIRepository.type_info_is_pointer(type_info)) {
435 return false; // unspported
437 if (ty != 'interface') {
440 // we can accept enum types here..
441 var interface_info = GIRepository.type_info_get_interface(type_info);
442 var interface_type = interface_info.get_type();
444 if (!allow_iface && interface_type != GIRepository.InfoType.ENUM) {
447 return interface_info.get_namespace() + '.' + interface_info.get_name();
451 * merge two proprety arrays' ignoring what's overrriden.
456 overrides : function (top, bottom)
460 return !top.every(function(t) {
461 if (t.name == b.name) {
467 bottom.forEach(function(e) {
479 findType : function (data, prop, value)
482 if ((prop == '|xns') || (prop == 'xtype')) {
486 var qname = this.guessName(data);
487 if (prop[0] == '|') {
488 prop= prop.substring(1);
491 var prs = this.getPropertiesFor(qname, 'props');
493 prs.forEach(function(e) {
497 if (e.name == prop) {
503 return Base.prototype.findType(data, prop,value);
510 findOptions : function(ename)
513 var es = ename.split('.');
515 return Base.prototype.findOptions(ename);
517 var gi = GIRepository.Repository.get_default();
518 var bi = gi.find_by_name(es[0], es[1]);
521 etype = GIRepository.object_info_get_type(bi);
526 if (etype != GIRepository.InfoType.ENUM) {
527 console.log("Options not handled yet!!!");
531 // got an enum.. let's return the values..
532 for(var i =0; i < bi.get_n_values(); i++) {
534 var prop = bi.get_value(i);
537 ret.push( ename + '.' + prop.get_name().toUpperCase() )
542 * determine the packing types..
544 getDefaultPack: function(pname, cname) {
545 var list = this.getPackingList(pname,cname);
546 // console.dump(list);
549 if (!list.every(function(e) { return e.name != 'add'; })) {
550 return 'add'; // add is in our list..?? what about args..?!?
554 e.params.forEach(function(p,i) {
555 if (ret === false) { return; } // skip broken..
556 if (i==0) { return; } // skip first..
557 if (p.type == 'boolean') {
561 if (p.type == 'number') {
565 if (p.type == 'uint') {
569 ret = false; // invalid!
571 return ret === false ? false : ret.join(',');
574 list.every(function(e) {
577 //print("DEFAULT PACK TEST : " + e.name + " : " +packret);
578 if (packret !== false) {
581 return true; // continue
583 //print("DEFAULT PACK: " + packret);
584 // should we do best match..?
590 getPackingList :function (pname, cname)
592 var funcs = this.getPropertiesFor(pname,'methods');
593 //print("getPackingList : ALL FUNCS");
594 //console.dump(funcs);
597 // let's assume top down...
598 var inherits = [ cname ];
599 inherits.push.apply(inherits, this.getPropertiesFor(cname,'inherits'));
600 funcs.forEach(function(m) {
601 if (m.params.length && (typeof(m.params[0].type) == 'string') &&
602 inherits.indexOf(m.params[0].type) > -1) {