1 //<script type="text/javascript">
2 //Gtk = imports.gi.Gtk;
3 GI = imports.gi.GIRepository;
4 GLib = imports.gi.GLib;
8 imports['Object.js'].load(Object);
10 console = imports['console.js'].console;
13 xnew = imports['xnew.js'].xnew;
20 xnew.load(Introspect,'JSDOC/Introspect');
24 Object.extend(Introspect, {
29 namespaces : function(ns)
31 // this should be a class of it's own...
32 this.references[ns] = []; // technically not needed - but fills in files..
33 // get this from GI... (it's the path..)
38 if (!GLib.file_test(dir, GLib.FileTest.EXISTS)) {
41 var gdir = GLib.dir_open(dir,0);
45 var fn = gdir.read_name();
46 // console.log('trying ' + fn);
51 if (!fn.match(/.typelib$/)) {
54 var par = fn.split('-').shift();
55 //console.log('trying ' + par);
56 if (ret.indexOf(par) > -1) {
64 var gi = GI.IRepository.get_default();
65 var pth = GI.IRepository.get_search_path ();
76 var gi = GI.IRepository.get_default();
78 titleType: 'Namespace',
89 // so ns looks like class..
91 extendsClasses : [], // what it extends...
92 childClasses : [], // what uses it..
96 values : [], /// really constants.
101 for (var i=0; i < gi.get_n_infos (ns); i++ ) {
102 var info = gi.get_info (ns, i);
104 var info_type = GI.base_info_get_type (info);
106 case GI.IInfoType.OBJECT:
107 ret.objects.push(GI.base_info_get_name(info));
108 this.clsGatherInterfaces(ns , GI.base_info_get_name(info));
110 case GI.IInfoType.INTERFACE:
111 ret.interfaces.push(GI.base_info_get_name(info));
113 case GI.IInfoType.FUNCTION:
114 new Introspect.Method(info, ret, 'functions', []);
117 case GI.IInfoType.CALLBACK:
118 // new Introspect.Callback(info, ret, 'callbacks', []);
121 case GI.IInfoType.ENUM:
122 case GI.IInfoType.FLAGS:
123 ret.enums.push(GI.base_info_get_name(info));
125 case GI.IInfoType.STRUCT:
126 if (GI.struct_info_is_gtype_struct (info)) {
130 ret.structs.push(GI.base_info_get_name(info));
132 case GI.IInfoType.UNION:
133 ret.unions.push(GI.base_info_get_name(info));
135 case GI.IInfoType.CONSTANT:
136 new Introspect.Constant(info, ret, 'values', []);
147 var gi = GI.IRepository.get_default();
148 var ver = gi.get_version(ns);
149 var pth = GI.IRepository.get_search_path ();
150 var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
152 ret.gir_file = gir_path + '/'+ ns + '-' + ver + '.gir';
153 ret.gir_filename = ns + '-' + ver + '.gir';
155 //console.dump(this.ifaceList);
162 // store all the interfaces, so we can show a list of them later...
163 // called when you list the namespace
164 clsGatherInterfaces : function(ns, cls)
166 var gi = GI.IRepository.get_default();
167 var bb = gi.find_by_name(ns, cls);
168 var fullname = ns+'.'+cls;
169 this.ifaceList = this.ifaceList || { };
172 for(var i =0; i < GI.object_info_get_n_interfaces(bb); i++) {
174 var prop = GI.object_info_get_interface(bb,i);
176 var add = GI.base_info_get_namespace(prop) +'.' + GI.base_info_get_name(prop);
177 this.ifaceList[add] = this.ifaceList[add] || [];
178 if (this.ifaceList[add].indexOf(fullname) < 0) {
179 this.ifaceList[add].push(fullname);
191 doc : function(what) {
192 var ns = what.split('.').shift();
193 this.commentLoad(ns);
194 return typeof(this.comments[ns][what]) == 'undefined' ? '' : this.comments[ns][what];
202 commentLoad : function(ns)
205 if (typeof(this.comments[ns]) != 'undefined') {
209 console.log("LOAD DOCS: " + ns);
210 var gi = GI.IRepository.get_default();
211 var ver = gi.get_version(ns);
213 this.comments[ns] = {};
218 // no idea why this is broken on my build system.
219 var getAttribute = function(n, name){
220 var properties = n.properties;
222 if (properties.name == name)
223 return properties.children.content;
224 properties = properties.next
230 function walk (element, path) {
237 var n = getAttribute(element, 'name') ;
238 //console.log("WALK" + n);
239 if (element.name == 'signal') {
244 path += path.length ? '.' : '';
247 if (element.name == 'return-value') {
248 path += '.return-value';
251 var d = getAttribute(element,'doc');
253 // Seed.print(path + ':' + d);
257 var child = element.children;
260 //console.log(child.tag);
261 if (child.type == "element"){
268 var pth = GI.IRepository.get_search_path ();
271 var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
275 var fn = gir_path + '/'+ ns + '-' + ver + '.gir';
278 if (!GLib.file_test(fn, GLib.FileTest.EXISTS)) {
279 console.log('missing docc file ' + fn);
280 this.comments[ns] = {};
284 var doc = xml.parseFile(fn);
285 //console.log("xmldoc?" + doc);
288 this.comments[ns] = ret;
292 factory : function(type, ns, name) {
293 if (typeof (this.registry[ns +'.' + name]) == 'undefined') {
294 this.registry[ns +'.' + name] = new Introspect[type](ns,name);
295 this.registry[ns +'.' + name].load();
298 return this.registry[ns +'.' + name];