1 //<script type="text/javascript">
2 //Gtk = imports.gi.Gtk;
3 GI = imports.gi.GIRepository;
4 GLib = imports.gi.GLib;
8 XObject = imports.XObject.XObject;
10 console = imports.console.console;
18 namespaces : function(ns)
20 // this should be a class of it's own...
21 this.references[ns] = []; // technically not needed - but fills in files..
22 // get this from GI... (it's the path..)
27 if (!GLib.file_test(dir, GLib.FileTest.EXISTS)) {
30 var gdir = GLib.dir_open(dir,0);
34 var fn = gdir.read_name ? gdir.read_name () : GLib.dir_read_name(gdir);
35 // console.log('trying ' + fn);
37 gdir.close ? gdir.close() : GLib.dir_close(gdir);
40 if (!fn.match(/.typelib$/)) {
43 var par = fn.split('-').shift();
44 //console.log('trying ' + par);
45 if (ret.indexOf(par) > -1) {
53 var gi = GI.Repository.get_default();
54 var pth = GI.Repository.get_search_path ();
65 var gi = GI.Repository.get_default();
67 titleType: 'Namespace',
78 // so ns looks like class..
80 extendsClasses : [], // what it extends...
81 childClasses : [], // what uses it..
85 values : [], /// really constants.
90 for (var i=0; i < GI.Repository.get_n_infos (gi,ns); i++ ) {
91 var info = GI.Repository.get_info (gi, ns, i);
92 print("NAME: " + ns.get_name());
94 var info_type = GI.base_info_get_type (info);
96 case GI.InfoType.OBJECT:
97 ret.objects.push(info.get_name());
98 this.clsGatherInterfaces(ns , info.get_name());
100 case GI.InfoType.INTERFACE:
101 ret.interfaces.push(info.get_name());
103 case GI.InfoType.FUNCTION:
104 new imports.Method.Method(info, ret, 'functions', []);
107 case GI.InfoType.CALLBACK:
108 // new Introspect.Callback(info, ret, 'callbacks', []);
111 case GI.InfoType.ENUM:
112 case GI.InfoType.FLAGS:
113 ret.enums.push(info.get_name());
115 case GI.InfoType.STRUCT:
116 if (GI.struct_info_is_gtype_struct (info)) {
120 ret.structs.push(info.get_name());
122 case GI.InfoType.UNION:
123 ret.unions.push(info.get_name());
125 case GI.InfoType.CONSTANT:
126 new imports.Constant.Constant(info, ret, 'values', []);
137 var gi = GI.Repository.get_default();
138 var ver = GI.Repository.get_version(gi,ns);
139 var pth = GI.Repository.get_search_path ();
140 var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
142 ret.gir_file = gir_path + '/'+ ns + '-' + ver + '.gir';
143 ret.gir_filename = ns + '-' + ver + '.gir';
145 //console.dump(this.ifaceList);
152 // store all the interfaces, so we can show a list of them later...
153 // called when you list the namespace
154 clsGatherInterfaces : function(ns, cls)
156 // print("clsGatherInterfaces: " + ns + ", " + cls);
157 var gi = GI.Repository.get_default();
158 var bb = GI.Repository.find_by_name(gi,ns, cls);
159 var fullname = ns+'.'+cls;
160 this.ifaceList = this.ifaceList || { };
163 for(var i =0; i < GI.object_info_get_n_interfaces(bb); i++) {
165 var prop = GI.object_info_get_interface(bb,i);
167 var add = prop.get_namespace() +'.' + prop.get_name();
168 this.ifaceList[add] = this.ifaceList[add] || [];
169 if (this.ifaceList[add].indexOf(fullname) < 0) {
170 this.ifaceList[add].push(fullname);
182 doc : function(what) {
183 print ("DOC: + " +what);
184 var ns = what.split('.').shift();
186 this.commentLoad(ns);
187 return typeof(this.comments[ns][what]) == 'undefined' ? '' : this.comments[ns][what];
195 commentLoad : function(ns)
198 if (typeof(this.comments[ns]) != 'undefined') {
202 console.log("LOAD DOCS: " + ns);
203 var gi = GI.Repository.get_default();
204 var ver = GI.Repository.get_version(gi,ns);
206 this.comments[ns] = {};
211 // no idea why this is broken on my build system.
212 var getAttribute = function(n, name){
213 var properties = n.properties;
215 if (properties.name == name)
216 return properties.children.content;
217 properties = properties.next
223 function walk (element, path) {
230 var n = getAttribute(element, 'name') ;
231 //console.log("WALK" + n);
232 if (element.name == 'signal') {
237 path += path.length ? '.' : '';
240 if (element.name == 'return-value') {
241 path += '.return-value';
244 var d = getAttribute(element,'doc');
246 // Seed.print(path + ':' + d);
250 var child = element.children;
253 //console.log(child.tag);
254 if (child.type == "element"){
261 var pth = GI.Repository.get_search_path ();
264 var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
268 var fn = gir_path + '/'+ ns + '-' + ver + '.gir';
271 if (!GLib.file_test(fn, GLib.FileTest.EXISTS)) {
272 console.log('missing docc file ' + fn);
273 this.comments[ns] = {};
277 var doc = xml.parseFile(fn);
278 //console.log("xmldoc?" + doc);
281 this.comments[ns] = ret;
285 factory : function(type, ns, name) {
286 if (typeof (this.registry[ns +'.' + name]) == 'undefined') {
287 this.registry[ns +'.' + name] = new imports[type][type](ns,name);
288 this.registry[ns +'.' + name].load();
291 return this.registry[ns +'.' + name];