+++ /dev/null
-//<script type="text/javascript">
-//Gtk = imports.gi.Gtk;
-GI = imports.gi.GIRepository;
-GLib = imports.gi.GLib;
-xml = imports.libxml;
-
-
-imports['Object.js'].load(Object);
-
-console = imports['console.js'].console;
-
-
-xnew = imports['xnew.js'].xnew;
-
-
-
-
-Introspect = {};
-
-xnew.load(Introspect,'JSDOC/Introspect');
-
-
-
-Object.extend(Introspect, {
-
-
- references : { },
-
- namespaces : function(ns)
- {
- // this should be a class of it's own...
- this.references[ns] = []; // technically not needed - but fills in files..
- // get this from GI... (it's the path..)
- var ret = [];
-
- function scanGir(dir)
- {
- if (!GLib.file_test(dir, GLib.FileTest.EXISTS)) {
- return;
- }
- var gdir = GLib.dir_open(dir,0);
-
- while (true) {
-
- var fn = gdir.read_name();
- // console.log('trying ' + fn);
- if (!fn) {
- gdir.close();
- return;;
- }
- if (!fn.match(/.typelib$/)) {
- continue;
- }
- var par = fn.split('-').shift();
- //console.log('trying ' + par);
- if (ret.indexOf(par) > -1) {
- continue;
- }
- ret.push(par);
-
-
- }
- }
- var gi = GI.IRepository.get_default();
- var pth = GI.IRepository.get_search_path ();
-
- scanGir(pth[0]);
- ret.sort();
- console.dump(ret);
- return ret;
-
- },
-
-
- ns: function(ns) {
- var gi = GI.IRepository.get_default();
- ret = {
- titleType: 'Namespace',
- ns: ns,
- name : ns,
- alias : ns,
- objects : [],
- functions : [],
- enums : [],
- structs: [],
- constants : [],
- unions : [],
-
- // so ns looks like class..
-
- extendsClasses : [], // what it extends...
- childClasses : [], // what uses it..
- properties : [],
- constructors : [],
- methods : [],
- values : [], /// really constants.
- signals : [],
- interfaces: [],
- };
-
- for (var i=0; i < gi.get_n_infos (ns); i++ ) {
- var info = gi.get_info (ns, i);
-
- var info_type = GI.base_info_get_type (info);
- switch(info_type) {
- case GI.IInfoType.OBJECT:
- ret.objects.push(GI.base_info_get_name(info));
- this.clsGatherInterfaces(ns , GI.base_info_get_name(info));
- continue;
- case GI.IInfoType.INTERFACE:
- ret.interfaces.push(GI.base_info_get_name(info));
- continue;
- case GI.IInfoType.FUNCTION:
- new Introspect.Method(info, ret, 'functions', []);
- continue;
-
- case GI.IInfoType.CALLBACK:
- // new Introspect.Callback(info, ret, 'callbacks', []);
- continue;
-
- case GI.IInfoType.ENUM:
- case GI.IInfoType.FLAGS:
- ret.enums.push(GI.base_info_get_name(info));
- continue;
- case GI.IInfoType.STRUCT:
- if (GI.struct_info_is_gtype_struct (info)) {
- continue;
- }
-
- ret.structs.push(GI.base_info_get_name(info));
- continue;
- case GI.IInfoType.UNION:
- ret.unions.push(GI.base_info_get_name(info));
- continue;
- case GI.IInfoType.CONSTANT:
- new Introspect.Constant(info, ret, 'values', []);
-
- continue;
-
-
- default:
- continue;
- }
- }
-
-
- var gi = GI.IRepository.get_default();
- var ver = gi.get_version(ns);
- var pth = GI.IRepository.get_search_path ();
- var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
- //console.log(fn);
- ret.gir_file = gir_path + '/'+ ns + '-' + ver + '.gir';
- ret.gir_filename = ns + '-' + ver + '.gir';
-
- //console.dump(this.ifaceList);
- return ret;
-
- },
-
-
-
- // store all the interfaces, so we can show a list of them later...
- // called when you list the namespace
- clsGatherInterfaces : function(ns, cls)
- {
- var gi = GI.IRepository.get_default();
- var bb = gi.find_by_name(ns, cls);
- var fullname = ns+'.'+cls;
- this.ifaceList = this.ifaceList || { };
-
-
- for(var i =0; i < GI.object_info_get_n_interfaces(bb); i++) {
-
- var prop = GI.object_info_get_interface(bb,i);
-
- var add = GI.base_info_get_namespace(prop) +'.' + GI.base_info_get_name(prop);
- this.ifaceList[add] = this.ifaceList[add] || [];
- if (this.ifaceList[add].indexOf(fullname) < 0) {
- this.ifaceList[add].push(fullname);
- }
-
- }
-
-
-
- },
-
-
-
-
- doc : function(what) {
- var ns = what.split('.').shift();
- this.commentLoad(ns);
- return typeof(this.comments[ns][what]) == 'undefined' ? '' : this.comments[ns][what];
-
- },
-
-
-
- comments : {},
-
- commentLoad : function(ns)
- {
-
- if (typeof(this.comments[ns]) != 'undefined') {
- return;
- }
-
- console.log("LOAD DOCS: " + ns);
- var gi = GI.IRepository.get_default();
- var ver = gi.get_version(ns);
- if (!ver) {
- this.comments[ns] = {};
- return;
- }
- var ret = { };
-
- // no idea why this is broken on my build system.
- var getAttribute = function(n, name){
- var properties = n.properties;
- while (properties){
- if (properties.name == name)
- return properties.children.content;
- properties = properties.next
- }
- return null;
- }
-
-
- function walk (element, path) {
-
-
- if (!element) {
- return;
- }
-
- var n = getAttribute(element, 'name') ;
- //console.log("WALK" + n);
- if (element.name == 'signal') {
- path += '.signal';
- }
-
- if (n) {
- path += path.length ? '.' : '';
- path += n;
- }
- if (element.name == 'return-value') {
- path += '.return-value';
- }
-
- var d = getAttribute(element,'doc');
- if (d) {
- // Seed.print(path + ':' + d);
- ret[path] = d;
- }
-
- var child = element.children;
-
- while (child){
- //console.log(child.tag);
- if (child.type == "element"){
- walk (child, path);
- }
- child = child.next;
- }
- }
-
- var pth = GI.IRepository.get_search_path ();
-
-
- var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
-
-
- //console.log(fn);
- var fn = gir_path + '/'+ ns + '-' + ver + '.gir';
- // console.log(fn);
-
- if (!GLib.file_test(fn, GLib.FileTest.EXISTS)) {
- console.log('missing docc file ' + fn);
- this.comments[ns] = {};
-
- return;
- }
- var doc = xml.parseFile(fn);
- //console.log("xmldoc?" + doc);
- walk (doc.root, '');
- //console.dump(ret);
- this.comments[ns] = ret;
-
- },
- registry : { },
- factory : function(type, ns, name) {
- if (typeof (this.registry[ns +'.' + name]) == 'undefined') {
- this.registry[ns +'.' + name] = new Introspect[type](ns,name);
- this.registry[ns +'.' + name].load();
- }
-
- return this.registry[ns +'.' + name];
- }
-
-
-
-});
-
-
-