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;
15 GI.InfoType = GI.IInfoType;
24 namespaces : function(ns)
26 // this should be a class of it's own...
27 this.references[ns] = []; // technically not needed - but fills in files..
28 // get this from GI... (it's the path..)
33 if (!GLib.file_test(dir, GLib.FileTest.EXISTS)) {
36 File.list(dir).forEach(function(fn)
38 if (!fn.match(/\.typelib$/)) {
41 var par = fn.split('-').shift();
42 //console.log('trying ' + par);
43 if (ret.indexOf(par) > -1) {
50 var gi = GI.Repository.get_default();
51 var pth = GI.Repository.get_search_path();
62 var gi = GI.Repository.get_default();
64 titleType: 'Namespace',
75 // so ns looks like class..
77 extendsClasses : [], // what it extends...
78 childClasses : [], // what uses it..
82 values : [], /// really constants.
87 for (var i=0; i < gi.get_n_infos (ns); i++ ) {
88 var info = gi.get_info (ns, i);
89 // print("NAME: " + info.get_name());
91 var info_type = GI.base_info_get_type (info);
92 // print("Type: " + info_type);
94 case GI.InfoType.OBJECT:
95 ret.objects.push(info.get_name());
96 this.clsGatherInterfaces(ns , info.get_name());
98 case GI.InfoType.INTERFACE:
99 ret.interfaces.push(info.get_name());
101 case GI.InfoType.FUNCTION:
102 new imports.Method.Method(info, ret, 'functions', []);
105 case GI.InfoType.CALLBACK:
106 // new Introspect.Callback(info, ret, 'callbacks', []);
109 case GI.InfoType.ENUM:
110 case GI.InfoType.FLAGS:
111 ret.enums.push(info.get_name());
113 case GI.InfoType.STRUCT:
114 if (GI.struct_info_is_gtype_struct (info)) {
118 ret.structs.push(info.get_name());
120 case GI.InfoType.UNION:
121 ret.unions.push(info.get_name());
123 case GI.InfoType.CONSTANT:
124 new imports.Constant.Constant(info, ret, 'values', []);
133 print ("SCAN NAMESPACE ALL DONE");
135 var gi = GI.Repository.get_default();
136 var ver = gi.get_version(ns);
137 var pth = GI.Repository.get_search_path ();
138 var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
140 ret.gir_file = gir_path + '/'+ ns + '-' + ver + '.gir';
141 ret.gir_filename = ns + '-' + ver + '.gir';
143 //console.dump(this.ifaceList);
150 // store all the interfaces, so we can show a list of them later...
151 // called when you list the namespace
152 clsGatherInterfaces : function(ns, cls)
154 // print("clsGatherInterfaces: " + ns + ", " + cls);
155 var gi = GI.Repository.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 = prop.get_namespace() +'.' + prop.get_name();
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 print ("DOC: + " +what);
182 var ns = what.split('.').shift();
184 this.commentLoad(ns);
185 return typeof(this.comments[ns][what]) == 'undefined' ? '' : this.comments[ns][what];
193 commentLoad : function(ns)
196 if (typeof(this.comments[ns]) != 'undefined') {
200 console.log("LOAD DOCS: " + ns);
201 var gi = GI.Repository.get_default();
202 var ver = gi.get_version(ns);
204 this.comments[ns] = {};
209 // no idea why this is broken on my build system.
210 var getAttribute = function(n, name){
211 var properties = n.properties;
213 if (properties.name == name)
214 return properties.children.content;
215 properties = properties.next
221 function walk (element, path) {
228 var n = getAttribute(element, 'name') ;
229 //console.log("WALK" + n);
230 if (element.name == 'signal') {
235 path += path.length ? '.' : '';
238 if (element.name == 'return-value') {
239 path += '.return-value';
242 var d = getAttribute(element,'doc');
244 // Seed.print(path + ':' + d);
248 var child = element.children;
251 //console.log(child.tag);
252 if (child.type == "element"){
259 var pth = GI.Repository.get_search_path ();
262 var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
266 var fn = gir_path + '/'+ ns + '-' + ver + '.gir';
269 if (!GLib.file_test(fn, GLib.FileTest.EXISTS)) {
270 console.log('missing docc file ' + fn);
271 this.comments[ns] = {};
275 var doc = xml.parseFile(fn);
276 //console.log("xmldoc?" + doc);
279 this.comments[ns] = ret;
283 factory : function(type, ns, name) {
284 if (typeof (this.registry[ns +'.' + name]) == 'undefined') {
285 this.registry[ns +'.' + name] = new imports[type][type](ns,name);
286 this.registry[ns +'.' + name].load();
289 return this.registry[ns +'.' + name];