1 //<script type="text/javascript">
2 //Gtk = imports.gi.Gtk;
3 GI = imports.gi.GIRepository;
4 GLib = imports.gi.GLib;
7 //GObject = imports.gi.GObject;
9 console = imports['console.js'].console;
10 JSDOC = imports['JSDOC.js'].JSDOC;
11 Roo = imports['Roo.js'].Roo;
12 xnew = imports['xnew.js'].xnew;
19 xnew.load(Introspect,'JSDOC/Introspect');
23 Roo.apply( Introspect, {
28 namespaces : function(ns)
30 // this should be a class of it's own...
31 this.references[ns] = []; // technically not needed - but fills in files..
32 // get this from GI... (it's the path..)
37 if (!GLib.file_test(dir, GLib.FileTest.EXISTS)) {
40 var gdir = GLib.dir_open(dir,0);
44 var fn = GLib.dir_read_name(gdir);
45 // console.log('trying ' + fn);
50 if (!fn.match(/.typelib$/)) {
53 var par = fn.split('-').shift();
54 //console.log('trying ' + par);
55 if (ret.indexOf(par) > -1) {
63 var gi = GI.IRepository.get_default();
64 var pth = GI.IRepository.get_search_path ();
75 var gi = GI.IRepository.get_default();
77 titleType: 'Namespace',
88 // so ns looks like class..
90 extendsClasses : [], // what it extends...
91 childClasses : [], // what uses it..
95 values : [], /// really constants.
100 for (var i=0; i < gi.get_n_infos (ns); i++ ) {
101 var info = gi.get_info (ns, i);
103 var info_type = GI.base_info_get_type (info);
105 case GI.IInfoType.OBJECT:
106 ret.objects.push(GI.base_info_get_name(info));
107 this.clsGatherInterfaces(ns , GI.base_info_get_name(info));
109 case GI.IInfoType.INTERFACE:
110 ret.interfaces.push(GI.base_info_get_name(info));
112 case GI.IInfoType.FUNCTION:
113 new Introspect.Method(info, ret, 'functions', []);
116 case GI.IInfoType.CALLBACK:
117 // new Introspect.Callback(info, ret, 'callbacks', []);
120 case GI.IInfoType.ENUM:
121 case GI.IInfoType.FLAGS:
122 ret.enums.push(GI.base_info_get_name(info));
124 case GI.IInfoType.STRUCT:
125 if (GI.struct_info_is_gtype_struct (info)) {
129 ret.structs.push(GI.base_info_get_name(info));
131 case GI.IInfoType.UNION:
132 ret.unions.push(GI.base_info_get_name(info));
134 case GI.IInfoType.CONSTANT:
135 new Introspect.Constant(info, ret, 'values', []);
144 //console.dump(this.ifaceList);
151 // store all the interfaces, so we can show a list of them later...
152 // called when you list the namespace
153 clsGatherInterfaces : function(ns, cls)
155 var gi = GI.IRepository.get_default();
156 var bb = gi.find_by_name(ns, cls);
157 var fullname = ns+'.'+cls;
158 this.ifaceList = this.ifaceList || { };
161 for(var i =0; i < GI.object_info_get_n_interfaces(bb); i++) {
163 var prop = GI.object_info_get_interface(bb,i);
165 var add = GI.base_info_get_namespace(prop) +'.' + GI.base_info_get_name(prop);
166 this.ifaceList[add] = this.ifaceList[add] || [];
167 if (this.ifaceList[add].indexOf(fullname) < 0) {
168 this.ifaceList[add].push(fullname);
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];
191 commentLoad : function(ns)
194 if (typeof(this.comments[ns]) != 'undefined') {
198 console.log("LOAD DOCS: " + ns);
199 var gi = GI.IRepository.get_default();
200 var ver = gi.get_version(ns);
202 this.comments[ns] = {};
207 // no idea why this is broken on my build system.
208 var getAttribute = function(n, name){
209 var properties = n.properties;
211 if (properties.name == name)
212 return properties.children.content;
213 properties = properties.next
219 function walk (element, path) {
226 var n = getAttribute(element, 'name') ;
227 //console.log("WALK" + n);
229 path += path.length ? '.' : '';
232 if (element.name == 'return-value') {
233 path += '.return-value';
237 var d = getAttribute(element,'doc');
239 // Seed.print(path + ':' + d);
243 var child = element.children;
246 //console.log(child.tag);
247 if (child.type == "element"){
254 var pth = GI.IRepository.get_search_path ();
257 var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
261 var fn = gir_path + '/'+ ns + '-' + ver + '.gir';
264 if (!GLib.file_test(fn, GLib.FileTest.EXISTS)) {
265 console.log('missing docc file ' + fn);
266 this.comments[ns] = {};
270 var doc = xml.parseFile(fn);
271 console.log("xmldoc?" + doc);
274 this.comments[ns] = ret;
278 factory : function(type, ns, name) {
279 if (typeof (this.registry[ns +'.' + name]) == 'undefined') {
280 this.registry[ns +'.' + name] = new Introspect[type](ns,name);
281 this.registry[ns +'.' + name].load();
284 return this.registry[ns +'.' + name];