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);
93 var info_type = GI.base_info_get_type (info);
95 case GI.InfoType.OBJECT:
96 ret.objects.push(info.get_name());
97 this.clsGatherInterfaces(ns , info.get_name());
99 case GI.InfoType.INTERFACE:
100 ret.interfaces.push(info.get_name());
102 case GI.InfoType.FUNCTION:
103 new imports.Method.Method(info, ret, 'functions', []);
106 case GI.InfoType.CALLBACK:
107 // new Introspect.Callback(info, ret, 'callbacks', []);
110 case GI.InfoType.ENUM:
111 case GI.InfoType.FLAGS:
112 ret.enums.push(info.get_name());
114 case GI.InfoType.STRUCT:
115 if (GI.struct_info_is_gtype_struct (info)) {
119 ret.structs.push(info.get_name());
121 case GI.InfoType.UNION:
122 ret.unions.push(info.get_name());
124 case GI.InfoType.CONSTANT:
125 new imports.Constant.Constant(info, ret, 'values', []);
136 var gi = GI.Repository.get_default();
137 var ver = GI.Repository.get_version(gi,ns);
138 var pth = GI.Repository.get_search_path ();
139 var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
141 ret.gir_file = gir_path + '/'+ ns + '-' + ver + '.gir';
142 ret.gir_filename = ns + '-' + ver + '.gir';
144 //console.dump(this.ifaceList);
151 // store all the interfaces, so we can show a list of them later...
152 // called when you list the namespace
153 clsGatherInterfaces : function(ns, cls)
155 // print("clsGatherInterfaces: " + ns + ", " + cls);
156 var gi = GI.Repository.get_default();
157 var bb = GI.Repository.find_by_name(gi,ns, cls);
158 var fullname = ns+'.'+cls;
159 this.ifaceList = this.ifaceList || { };
162 for(var i =0; i < GI.object_info_get_n_interfaces(bb); i++) {
164 var prop = GI.object_info_get_interface(bb,i);
166 var add = prop.get_namespace() +'.' + prop.get_name();
167 this.ifaceList[add] = this.ifaceList[add] || [];
168 if (this.ifaceList[add].indexOf(fullname) < 0) {
169 this.ifaceList[add].push(fullname);
181 doc : function(what) {
182 print ("DOC: + " +what);
183 var ns = what.split('.').shift();
185 this.commentLoad(ns);
186 return typeof(this.comments[ns][what]) == 'undefined' ? '' : this.comments[ns][what];
194 commentLoad : function(ns)
197 if (typeof(this.comments[ns]) != 'undefined') {
201 console.log("LOAD DOCS: " + ns);
202 var gi = GI.Repository.get_default();
203 var ver = GI.Repository.get_version(gi,ns);
205 this.comments[ns] = {};
210 // no idea why this is broken on my build system.
211 var getAttribute = function(n, name){
212 var properties = n.properties;
214 if (properties.name == name)
215 return properties.children.content;
216 properties = properties.next
222 function walk (element, path) {
229 var n = getAttribute(element, 'name') ;
230 //console.log("WALK" + n);
231 if (element.name == 'signal') {
236 path += path.length ? '.' : '';
239 if (element.name == 'return-value') {
240 path += '.return-value';
243 var d = getAttribute(element,'doc');
245 // Seed.print(path + ':' + d);
249 var child = element.children;
252 //console.log(child.tag);
253 if (child.type == "element"){
260 var pth = GI.Repository.get_search_path ();
263 var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
267 var fn = gir_path + '/'+ ns + '-' + ver + '.gir';
270 if (!GLib.file_test(fn, GLib.FileTest.EXISTS)) {
271 console.log('missing docc file ' + fn);
272 this.comments[ns] = {};
276 var doc = xml.parseFile(fn);
277 //console.log("xmldoc?" + doc);
280 this.comments[ns] = ret;
284 factory : function(type, ns, name) {
285 if (typeof (this.registry[ns +'.' + name]) == 'undefined') {
286 this.registry[ns +'.' + name] = new imports[type][type](ns,name);
287 this.registry[ns +'.' + name].load();
290 return this.registry[ns +'.' + name];