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);
21 GI.IBaseInfo.prototype.get_namespace = function(n) {
22 return GI.base_info_get_namespace(this, n);
33 namespaces : function(ns)
35 // this should be a class of it's own...
36 this.references[ns] = []; // technically not needed - but fills in files..
37 // get this from GI... (it's the path..)
42 if (!GLib.file_test(dir, GLib.FileTest.EXISTS)) {
45 File.list(dir).forEach(function(fn)
47 if (!fn.match(/\.typelib$/)) {
50 var par = fn.split('-').shift();
51 //console.log('trying ' + par);
52 if (ret.indexOf(par) > -1) {
59 var gi = GI.Repository.get_default();
60 var pth = GI.Repository.get_search_path();
71 var gi = GI.Repository.get_default();
73 titleType: 'Namespace',
84 // so ns looks like class..
86 extendsClasses : [], // what it extends...
87 childClasses : [], // what uses it..
91 values : [], /// really constants.
96 for (var i=0; i < gi.get_n_infos (ns); i++ ) {
97 var info = gi.get_info (ns, i);
98 // print("NAME: " + info.get_name());
100 var info_type = GI.base_info_get_type (info);
101 // print("Type: " + info_type);
103 case GI.InfoType.OBJECT:
104 ret.objects.push(info.get_name());
105 this.clsGatherInterfaces(ns , info.get_name());
107 case GI.InfoType.INTERFACE:
108 ret.interfaces.push(info.get_name());
110 case GI.InfoType.FUNCTION:
111 new imports.Method.Method(info, ret, 'functions', []);
114 case GI.InfoType.CALLBACK:
115 // new Introspect.Callback(info, ret, 'callbacks', []);
118 case GI.InfoType.ENUM:
119 case GI.InfoType.FLAGS:
120 ret.enums.push(info.get_name());
122 case GI.InfoType.STRUCT:
123 if (GI.struct_info_is_gtype_struct (info)) {
127 ret.structs.push(info.get_name());
129 case GI.InfoType.UNION:
130 ret.unions.push(info.get_name());
132 case GI.InfoType.CONSTANT:
133 new imports.Constant.Constant(info, ret, 'values', []);
142 print ("SCAN NAMESPACE ALL DONE");
144 var gi = GI.Repository.get_default();
145 var ver = gi.get_version(ns);
146 var pth = GI.Repository.get_search_path ();
147 var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
149 ret.gir_file = gir_path + '/'+ ns + '-' + ver + '.gir';
150 ret.gir_filename = ns + '-' + ver + '.gir';
152 //console.dump(this.ifaceList);
159 // store all the interfaces, so we can show a list of them later...
160 // called when you list the namespace
161 clsGatherInterfaces : function(ns, cls)
163 // print("clsGatherInterfaces: " + ns + ", " + cls);
164 var gi = GI.Repository.get_default();
165 var bb = gi.find_by_name(ns, cls);
166 var fullname = ns+'.'+cls;
167 this.ifaceList = this.ifaceList || { };
170 for(var i =0; i < GI.object_info_get_n_interfaces(bb); i++) {
172 var prop = GI.object_info_get_interface(bb,i);
174 var add = prop.get_namespace() +'.' + prop.get_name();
175 this.ifaceList[add] = this.ifaceList[add] || [];
176 if (this.ifaceList[add].indexOf(fullname) < 0) {
177 this.ifaceList[add].push(fullname);
189 doc : function(what) {
190 print ("DOC: + " +what);
191 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.Repository.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.Repository.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 imports[type][type](ns,name);
295 this.registry[ns +'.' + name].load();
298 return this.registry[ns +'.' + name];