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.IRepository.get_default();
54 var pth = GI.IRepository.get_search_path ();
65 var gi = GI.IRepository.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.get_n_infos (ns); i++ ) {
91 var info = gi.get_info (ns, i);
93 var info_type = GI.base_info_get_type (info);
95 case GI.IInfoType.OBJECT:
96 ret.objects.push(GI.base_info_get_name(info));
97 this.clsGatherInterfaces(ns , GI.base_info_get_name(info));
99 case GI.IInfoType.INTERFACE:
100 ret.interfaces.push(GI.base_info_get_name(info));
102 case GI.IInfoType.FUNCTION:
103 new imports.Method.Method(info, ret, 'functions', []);
106 case GI.IInfoType.CALLBACK:
107 // new Introspect.Callback(info, ret, 'callbacks', []);
110 case GI.IInfoType.ENUM:
111 case GI.IInfoType.FLAGS:
112 ret.enums.push(GI.base_info_get_name(info));
114 case GI.IInfoType.STRUCT:
115 if (GI.struct_info_is_gtype_struct (info)) {
119 ret.structs.push(GI.base_info_get_name(info));
121 case GI.IInfoType.UNION:
122 ret.unions.push(GI.base_info_get_name(info));
124 case GI.IInfoType.CONSTANT:
125 new imports.Constant.Constant(info, ret, 'values', []);
136 var gi = GI.IRepository.get_default();
137 var ver = gi.get_version(ns);
138 var pth = GI.IRepository.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 var gi = GI.IRepository.get_default();
156 var bb = gi.find_by_name(ns, cls);
157 var fullname = ns+'.'+cls;
158 this.ifaceList = this.ifaceList || { };
161 for(var i =0; i < GI.object_info_get_n_interfaces(bb); i++) {
163 var prop = GI.object_info_get_interface(bb,i);
165 var add = GI.base_info_get_namespace(prop) +'.' + GI.base_info_get_name(prop);
166 this.ifaceList[add] = this.ifaceList[add] || [];
167 if (this.ifaceList[add].indexOf(fullname) < 0) {
168 this.ifaceList[add].push(fullname);
180 doc : function(what) {
181 var ns = what.split('.').shift();
182 this.commentLoad(ns);
183 return typeof(this.comments[ns][what]) == 'undefined' ? '' : this.comments[ns][what];
191 commentLoad : function(ns)
194 if (typeof(this.comments[ns]) != 'undefined') {
198 console.log("LOAD DOCS: " + ns);
199 var gi = GI.IRepository.get_default();
200 var ver = gi.get_version(ns);
202 this.comments[ns] = {};
207 // no idea why this is broken on my build system.
208 var getAttribute = function(n, name){
209 var properties = n.properties;
211 if (properties.name == name)
212 return properties.children.content;
213 properties = properties.next
219 function walk (element, path) {
226 var n = getAttribute(element, 'name') ;
227 //console.log("WALK" + n);
228 if (element.name == 'signal') {
233 path += path.length ? '.' : '';
236 if (element.name == 'return-value') {
237 path += '.return-value';
240 var d = getAttribute(element,'doc');
242 // Seed.print(path + ':' + d);
246 var child = element.children;
249 //console.log(child.tag);
250 if (child.type == "element"){
257 var pth = GI.IRepository.get_search_path ();
260 var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
264 var fn = gir_path + '/'+ ns + '-' + ver + '.gir';
267 if (!GLib.file_test(fn, GLib.FileTest.EXISTS)) {
268 console.log('missing docc file ' + fn);
269 this.comments[ns] = {};
273 var doc = xml.parseFile(fn);
274 //console.log("xmldoc?" + doc);
277 this.comments[ns] = ret;
281 factory : function(type, ns, name) {
282 if (typeof (this.registry[ns +'.' + name]) == 'undefined') {
283 this.registry[ns +'.' + name] = new imports[type][type](ns,name);
284 this.registry[ns +'.' + name].load();
287 return this.registry[ns +'.' + name];