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);
24 GI.IBaseInfo.prototype.get_attribute ( n) {
25 return GI.base_info_get_attribute(this, n);
35 namespaces : function(ns)
37 // this should be a class of it's own...
38 this.references[ns] = []; // technically not needed - but fills in files..
39 // get this from GI... (it's the path..)
44 if (!GLib.file_test(dir, GLib.FileTest.EXISTS)) {
47 File.list(dir).forEach(function(fn)
49 if (!fn.match(/\.typelib$/)) {
52 var par = fn.split('-').shift();
53 //console.log('trying ' + par);
54 if (ret.indexOf(par) > -1) {
61 var gi = GI.Repository.get_default();
62 var pth = GI.Repository.get_search_path();
73 var gi = GI.Repository.get_default();
75 titleType: 'Namespace',
86 // so ns looks like class..
88 extendsClasses : [], // what it extends...
89 childClasses : [], // what uses it..
93 values : [], /// really constants.
98 for (var i=0; i < gi.get_n_infos (ns); i++ ) {
99 var info = gi.get_info (ns, i);
100 // print("NAME: " + info.get_name());
102 var info_type = GI.base_info_get_type (info);
103 // print("Type: " + info_type);
105 case GI.InfoType.OBJECT:
106 ret.objects.push(info.get_name());
107 this.clsGatherInterfaces(ns , info.get_name());
109 case GI.InfoType.INTERFACE:
110 ret.interfaces.push(info.get_name());
112 case GI.InfoType.FUNCTION:
113 new imports.Method.Method(info, ret, 'functions', []);
116 case GI.InfoType.CALLBACK:
117 // new Introspect.Callback(info, ret, 'callbacks', []);
120 case GI.InfoType.ENUM:
121 case GI.InfoType.FLAGS:
122 ret.enums.push(info.get_name());
124 case GI.InfoType.STRUCT:
125 if (GI.struct_info_is_gtype_struct (info)) {
129 ret.structs.push(info.get_name());
131 case GI.InfoType.UNION:
132 ret.unions.push(info.get_name());
134 case GI.InfoType.CONSTANT:
135 new imports.Constant.Constant(info, ret, 'values', []);
144 print ("SCAN NAMESPACE ALL DONE");
146 var gi = GI.Repository.get_default();
147 var ver = gi.get_version(ns);
148 var pth = GI.Repository.get_search_path ();
149 var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
151 ret.gir_file = gir_path + '/'+ ns + '-' + ver + '.gir';
152 ret.gir_filename = ns + '-' + ver + '.gir';
154 //console.dump(this.ifaceList);
161 // store all the interfaces, so we can show a list of them later...
162 // called when you list the namespace
163 clsGatherInterfaces : function(ns, cls)
165 // print("clsGatherInterfaces: " + ns + ", " + cls);
166 var gi = GI.Repository.get_default();
167 var bb = gi.find_by_name(ns, cls);
168 var fullname = ns+'.'+cls;
169 this.ifaceList = this.ifaceList || { };
172 for(var i =0; i < GI.object_info_get_n_interfaces(bb); i++) {
174 var prop = GI.object_info_get_interface(bb,i);
176 var add = prop.get_namespace() +'.' + prop.get_name();
177 this.ifaceList[add] = this.ifaceList[add] || [];
178 if (this.ifaceList[add].indexOf(fullname) < 0) {
179 this.ifaceList[add].push(fullname);
191 doc : function(what) {
192 print ("DOC: + " +what);
193 var ns = what.split('.').shift();
195 this.commentLoad(ns);
196 return typeof(this.comments[ns][what]) == 'undefined' ? '' : this.comments[ns][what];
204 commentLoad : function(ns)
207 if (typeof(this.comments[ns]) != 'undefined') {
211 console.log("LOAD DOCS: " + ns);
212 var gi = GI.Repository.get_default();
213 var ver = gi.get_version(ns);
215 this.comments[ns] = {};
220 // no idea why this is broken on my build system.
221 var getAttribute = function(n, name){
222 var properties = n.properties;
224 if (properties.name == name)
225 return properties.children.content;
226 properties = properties.next
232 function walk (element, path) {
239 var n = getAttribute(element, 'name') ;
240 //console.log("WALK" + n);
241 if (element.name == 'signal') {
246 path += path.length ? '.' : '';
249 if (element.name == 'return-value') {
250 path += '.return-value';
253 var d = getAttribute(element,'doc');
255 // Seed.print(path + ':' + d);
259 var child = element.children;
262 //console.log(child.tag);
263 if (child.type == "element"){
270 var pth = GI.Repository.get_search_path ();
273 var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
277 var fn = gir_path + '/'+ ns + '-' + ver + '.gir';
280 if (!GLib.file_test(fn, GLib.FileTest.EXISTS)) {
281 console.log('missing docc file ' + fn);
282 this.comments[ns] = {};
286 var doc = xml.parseFile(fn);
287 //console.log("xmldoc?" + doc);
290 this.comments[ns] = ret;
294 factory : function(type, ns, name) {
295 if (typeof (this.registry[ns +'.' + name]) == 'undefined') {
296 this.registry[ns +'.' + name] = new imports[type][type](ns,name);
297 this.registry[ns +'.' + name].load();
300 return this.registry[ns +'.' + name];