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;
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 File.list(dir).forEach(function(fn)
32 if (!fn.match(/\.typelib$/)) {
35 var par = fn.split('-').shift();
36 //console.log('trying ' + par);
37 if (ret.indexOf(par) > -1) {
44 var gi = GI.Repository.get_default();
45 var pth = GI.Repository.get_search_path();
56 var gi = GI.Repository.get_default();
58 titleType: 'Namespace',
69 // so ns looks like class..
71 extendsClasses : [], // what it extends...
72 childClasses : [], // what uses it..
76 values : [], /// really constants.
81 for (var i=0; i < gi.get_n_infos (ns); i++ ) {
82 var info = gi.get_info (ns, i);
83 // print("NAME: " + info.get_name());
85 var info_type = GI.base_info_get_type (info);
86 // print("Type: " + info_type);
88 case GI.InfoType.OBJECT:
89 ret.objects.push(info.get_name());
90 this.clsGatherInterfaces(ns , info.get_name());
92 case GI.InfoType.INTERFACE:
93 ret.interfaces.push(info.get_name());
95 case GI.InfoType.FUNCTION:
96 new imports.Method.Method(info, ret, 'functions', []);
99 case GI.InfoType.CALLBACK:
100 // new Introspect.Callback(info, ret, 'callbacks', []);
103 case GI.InfoType.ENUM:
104 case GI.InfoType.FLAGS:
105 ret.enums.push(info.get_name());
107 case GI.InfoType.STRUCT:
108 if (GI.struct_info_is_gtype_struct (info)) {
112 ret.structs.push(info.get_name());
114 case GI.InfoType.UNION:
115 ret.unions.push(info.get_name());
117 case GI.InfoType.CONSTANT:
118 new imports.Constant.Constant(info, ret, 'values', []);
127 print ("SCAN NAMESPACE ALL DONE");
129 var gi = GI.Repository.get_default();
130 var ver = GI.Repository.get_version(gi,ns);
131 var pth = GI.Repository.get_search_path ();
132 var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
134 ret.gir_file = gir_path + '/'+ ns + '-' + ver + '.gir';
135 ret.gir_filename = ns + '-' + ver + '.gir';
137 //console.dump(this.ifaceList);
144 // store all the interfaces, so we can show a list of them later...
145 // called when you list the namespace
146 clsGatherInterfaces : function(ns, cls)
148 // print("clsGatherInterfaces: " + ns + ", " + cls);
149 var gi = GI.Repository.get_default();
150 var bb = gi.find_by_name(ns, cls);
151 var fullname = ns+'.'+cls;
152 this.ifaceList = this.ifaceList || { };
155 for(var i =0; i < GI.object_info_get_n_interfaces(bb); i++) {
157 var prop = GI.object_info_get_interface(bb,i);
159 var add = prop.get_namespace() +'.' + prop.get_name();
160 this.ifaceList[add] = this.ifaceList[add] || [];
161 if (this.ifaceList[add].indexOf(fullname) < 0) {
162 this.ifaceList[add].push(fullname);
174 doc : function(what) {
175 print ("DOC: + " +what);
176 var ns = what.split('.').shift();
178 this.commentLoad(ns);
179 return typeof(this.comments[ns][what]) == 'undefined' ? '' : this.comments[ns][what];
187 commentLoad : function(ns)
190 if (typeof(this.comments[ns]) != 'undefined') {
194 console.log("LOAD DOCS: " + ns);
195 var gi = GI.Repository.get_default();
196 var ver = gi.get_version(ns);
198 this.comments[ns] = {};
203 // no idea why this is broken on my build system.
204 var getAttribute = function(n, name){
205 var properties = n.properties;
207 if (properties.name == name)
208 return properties.children.content;
209 properties = properties.next
215 function walk (element, path) {
222 var n = getAttribute(element, 'name') ;
223 //console.log("WALK" + n);
224 if (element.name == 'signal') {
229 path += path.length ? '.' : '';
232 if (element.name == 'return-value') {
233 path += '.return-value';
236 var d = getAttribute(element,'doc');
238 // Seed.print(path + ':' + d);
242 var child = element.children;
245 //console.log(child.tag);
246 if (child.type == "element"){
253 var pth = GI.Repository.get_search_path ();
256 var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
260 var fn = gir_path + '/'+ ns + '-' + ver + '.gir';
263 if (!GLib.file_test(fn, GLib.FileTest.EXISTS)) {
264 console.log('missing docc file ' + fn);
265 this.comments[ns] = {};
269 var doc = xml.parseFile(fn);
270 //console.log("xmldoc?" + doc);
273 this.comments[ns] = ret;
277 factory : function(type, ns, name) {
278 if (typeof (this.registry[ns +'.' + name]) == 'undefined') {
279 this.registry[ns +'.' + name] = new imports[type][type](ns,name);
280 this.registry[ns +'.' + name].load();
283 return this.registry[ns +'.' + name];