1 //<script type="text/javascript">
2 //Gtk = imports.gi.Gtk;
3 GI = imports.gi.GIRepository;
4 GLib = imports.gi.GLib;
6 File = imports.File.File;
8 XObject = imports.XObject.XObject;
10 console = imports.console.console;
14 GI.Repository = GI.IRepository;
16 GI.InfoType = GI.IInfoType;
18 GI.IBaseInfo.prototype.get_name = function(n) {
19 return GI.base_info_get_name(this, n);
30 namespaces : function(ns)
32 // this should be a class of it's own...
33 this.references[ns] = []; // technically not needed - but fills in files..
34 // get this from GI... (it's the path..)
39 if (!GLib.file_test(dir, GLib.FileTest.EXISTS)) {
42 File.list(dir).forEach(function(fn)
44 if (!fn.match(/\.typelib$/)) {
47 var par = fn.split('-').shift();
48 //console.log('trying ' + par);
49 if (ret.indexOf(par) > -1) {
56 var gi = GI.Repository.get_default();
57 var pth = GI.Repository.get_search_path();
68 var gi = GI.Repository.get_default();
70 titleType: 'Namespace',
81 // so ns looks like class..
83 extendsClasses : [], // what it extends...
84 childClasses : [], // what uses it..
88 values : [], /// really constants.
93 for (var i=0; i < gi.get_n_infos (ns); i++ ) {
94 var info = gi.get_info (ns, i);
95 // print("NAME: " + info.get_name());
97 var info_type = GI.base_info_get_type (info);
98 // print("Type: " + info_type);
100 case GI.InfoType.OBJECT:
101 ret.objects.push(info.get_name());
102 this.clsGatherInterfaces(ns , info.get_name());
104 case GI.InfoType.INTERFACE:
105 ret.interfaces.push(info.get_name());
107 case GI.InfoType.FUNCTION:
108 new imports.Method.Method(info, ret, 'functions', []);
111 case GI.InfoType.CALLBACK:
112 // new Introspect.Callback(info, ret, 'callbacks', []);
115 case GI.InfoType.ENUM:
116 case GI.InfoType.FLAGS:
117 ret.enums.push(info.get_name());
119 case GI.InfoType.STRUCT:
120 if (GI.struct_info_is_gtype_struct (info)) {
124 ret.structs.push(info.get_name());
126 case GI.InfoType.UNION:
127 ret.unions.push(info.get_name());
129 case GI.InfoType.CONSTANT:
130 new imports.Constant.Constant(info, ret, 'values', []);
139 print ("SCAN NAMESPACE ALL DONE");
141 var gi = GI.Repository.get_default();
142 var ver = gi.get_version(ns);
143 var pth = GI.Repository.get_search_path ();
144 var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
146 ret.gir_file = gir_path + '/'+ ns + '-' + ver + '.gir';
147 ret.gir_filename = ns + '-' + ver + '.gir';
149 //console.dump(this.ifaceList);
156 // store all the interfaces, so we can show a list of them later...
157 // called when you list the namespace
158 clsGatherInterfaces : function(ns, cls)
160 // print("clsGatherInterfaces: " + ns + ", " + cls);
161 var gi = GI.Repository.get_default();
162 var bb = gi.find_by_name(ns, cls);
163 var fullname = ns+'.'+cls;
164 this.ifaceList = this.ifaceList || { };
167 for(var i =0; i < GI.object_info_get_n_interfaces(bb); i++) {
169 var prop = GI.object_info_get_interface(bb,i);
171 var add = prop.get_namespace() +'.' + prop.get_name();
172 this.ifaceList[add] = this.ifaceList[add] || [];
173 if (this.ifaceList[add].indexOf(fullname) < 0) {
174 this.ifaceList[add].push(fullname);
186 doc : function(what) {
187 print ("DOC: + " +what);
188 var ns = what.split('.').shift();
190 this.commentLoad(ns);
191 return typeof(this.comments[ns][what]) == 'undefined' ? '' : this.comments[ns][what];
199 commentLoad : function(ns)
202 if (typeof(this.comments[ns]) != 'undefined') {
206 console.log("LOAD DOCS: " + ns);
207 var gi = GI.Repository.get_default();
208 var ver = gi.get_version(ns);
210 this.comments[ns] = {};
215 // no idea why this is broken on my build system.
216 var getAttribute = function(n, name){
217 var properties = n.properties;
219 if (properties.name == name)
220 return properties.children.content;
221 properties = properties.next
227 function walk (element, path) {
234 var n = getAttribute(element, 'name') ;
235 //console.log("WALK" + n);
236 if (element.name == 'signal') {
241 path += path.length ? '.' : '';
244 if (element.name == 'return-value') {
245 path += '.return-value';
248 var d = getAttribute(element,'doc');
250 // Seed.print(path + ':' + d);
254 var child = element.children;
257 //console.log(child.tag);
258 if (child.type == "element"){
265 var pth = GI.Repository.get_search_path ();
268 var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
272 var fn = gir_path + '/'+ ns + '-' + ver + '.gir';
275 if (!GLib.file_test(fn, GLib.FileTest.EXISTS)) {
276 console.log('missing docc file ' + fn);
277 this.comments[ns] = {};
281 var doc = xml.parseFile(fn);
282 //console.log("xmldoc?" + doc);
285 this.comments[ns] = ret;
289 factory : function(type, ns, name) {
290 if (typeof (this.registry[ns +'.' + name]) == 'undefined') {
291 this.registry[ns +'.' + name] = new imports[type][type](ns,name);
292 this.registry[ns +'.' + name].load();
295 return this.registry[ns +'.' + name];