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;
23 namespaces : function(ns)
25 // this should be a class of it's own...
26 this.references[ns] = []; // technically not needed - but fills in files..
27 // get this from GI... (it's the path..)
32 if (!GLib.file_test(dir, GLib.FileTest.EXISTS)) {
35 File.list(dir).forEach(function(fn)
37 if (!fn.match(/\.typelib$/)) {
40 var par = fn.split('-').shift();
41 //console.log('trying ' + par);
42 if (ret.indexOf(par) > -1) {
49 var gi = GI.Repository.get_default();
50 var pth = GI.Repository.get_search_path();
61 var gi = GI.Repository.get_default();
63 titleType: 'Namespace',
74 // so ns looks like class..
76 extendsClasses : [], // what it extends...
77 childClasses : [], // what uses it..
81 values : [], /// really constants.
86 for (var i=0; i < gi.get_n_infos (ns); i++ ) {
87 var info = gi.get_info (ns, i);
88 // print("NAME: " + info.get_name());
90 var info_type = GI.base_info_get_type (info);
91 // print("Type: " + info_type);
93 case GI.InfoType.OBJECT:
94 ret.objects.push(info.get_name());
95 this.clsGatherInterfaces(ns , info.get_name());
97 case GI.InfoType.INTERFACE:
98 ret.interfaces.push(info.get_name());
100 case GI.InfoType.FUNCTION:
101 new imports.Method.Method(info, ret, 'functions', []);
104 case GI.InfoType.CALLBACK:
105 // new Introspect.Callback(info, ret, 'callbacks', []);
108 case GI.InfoType.ENUM:
109 case GI.InfoType.FLAGS:
110 ret.enums.push(info.get_name());
112 case GI.InfoType.STRUCT:
113 if (GI.struct_info_is_gtype_struct (info)) {
117 ret.structs.push(info.get_name());
119 case GI.InfoType.UNION:
120 ret.unions.push(info.get_name());
122 case GI.InfoType.CONSTANT:
123 new imports.Constant.Constant(info, ret, 'values', []);
132 print ("SCAN NAMESPACE ALL DONE");
134 var gi = GI.Repository.get_default();
135 var ver = gi.get_version(ns);
136 var pth = GI.Repository.get_search_path ();
137 var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
139 ret.gir_file = gir_path + '/'+ ns + '-' + ver + '.gir';
140 ret.gir_filename = ns + '-' + ver + '.gir';
142 //console.dump(this.ifaceList);
149 // store all the interfaces, so we can show a list of them later...
150 // called when you list the namespace
151 clsGatherInterfaces : function(ns, cls)
153 // print("clsGatherInterfaces: " + ns + ", " + cls);
154 var gi = GI.Repository.get_default();
155 var bb = gi.find_by_name(ns, cls);
156 var fullname = ns+'.'+cls;
157 this.ifaceList = this.ifaceList || { };
160 for(var i =0; i < GI.object_info_get_n_interfaces(bb); i++) {
162 var prop = GI.object_info_get_interface(bb,i);
164 var add = prop.get_namespace() +'.' + prop.get_name();
165 this.ifaceList[add] = this.ifaceList[add] || [];
166 if (this.ifaceList[add].indexOf(fullname) < 0) {
167 this.ifaceList[add].push(fullname);
179 doc : function(what) {
180 print ("DOC: + " +what);
181 var ns = what.split('.').shift();
183 this.commentLoad(ns);
184 return typeof(this.comments[ns][what]) == 'undefined' ? '' : this.comments[ns][what];
192 commentLoad : function(ns)
195 if (typeof(this.comments[ns]) != 'undefined') {
199 console.log("LOAD DOCS: " + ns);
200 var gi = GI.Repository.get_default();
201 var ver = gi.get_version(ns);
203 this.comments[ns] = {};
208 // no idea why this is broken on my build system.
209 var getAttribute = function(n, name){
210 var properties = n.properties;
212 if (properties.name == name)
213 return properties.children.content;
214 properties = properties.next
220 function walk (element, path) {
227 var n = getAttribute(element, 'name') ;
228 //console.log("WALK" + n);
229 if (element.name == 'signal') {
234 path += path.length ? '.' : '';
237 if (element.name == 'return-value') {
238 path += '.return-value';
241 var d = getAttribute(element,'doc');
243 // Seed.print(path + ':' + d);
247 var child = element.children;
250 //console.log(child.tag);
251 if (child.type == "element"){
258 var pth = GI.Repository.get_search_path ();
261 var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
265 var fn = gir_path + '/'+ ns + '-' + ver + '.gir';
268 if (!GLib.file_test(fn, GLib.FileTest.EXISTS)) {
269 console.log('missing docc file ' + fn);
270 this.comments[ns] = {};
274 var doc = xml.parseFile(fn);
275 //console.log("xmldoc?" + doc);
278 this.comments[ns] = ret;
282 factory : function(type, ns, name) {
283 if (typeof (this.registry[ns +'.' + name]) == 'undefined') {
284 this.registry[ns +'.' + name] = new imports[type][type](ns,name);
285 this.registry[ns +'.' + name].load();
288 return this.registry[ns +'.' + name];