1 //<script type="text/javascript">
5 * abstraction layer / tree builder etc...
12 var console = imports['console.js'].console;
14 //var xnew = imports['xnew.js'].xnew;
16 function apply (o, c){
17 if(o && c && typeof c == 'object'){
30 dumpRegistry: function(scope, id)
34 for (var i in xnew.registry) {
36 for(var j in xnew.registry[i]) {
44 * xnew.get(this, 'someid')
45 * xnew.get(this).someid
47 * fetches from a registry of components.
50 * xnsid : 'Builder.test' // at top leve, all sub elements inherit it..
56 get: function(scope, id)
58 var s = typeof(scope) == 'object' ? scope.xnsid : scope;
60 if (typeof(this.pre_registry[s]) != 'undefined') {
61 this.xnew(this.pre_registry[s]);
62 delete this.pre_registry[s];
66 if (typeof(id) == 'undefined') {
67 if (typeof(xnew.registry[s]) !='undefined') {
68 Seed.print("Success - got " + s);
69 return xnew.registry[s];
72 var ar = s.split('.');
78 xnew.registry[s] = xnew.registry[s] || {};
81 var ret = typeof(xnew.registry[s][id]) == 'undefined' ? false : xnew.registry[s][id]
84 Seed.print((ret ? "Success" : "FAILED") + " - check for NS:" + s + " ID: " + id);
86 console.dump(this.dumpRegistry());
94 * load a directory, and overlay it's properties onto the variable provider..
101 load: function (obj, path)
103 var GLib = imports.gi.GLib;
105 var gdir = GLib.dir_open(__script_path__ + '/' + path,0);
111 var fn = gdir.read_name ? gdir.read_name() : Glib.gdir_read_name(gdir);
112 //console.log('trying ' + path + '/' + fn);
117 if (!fn.match(/.js$/)) {
120 var v = fn.replace(/.js$/, '');
121 imports[path + '/' + fn];
122 var assign = imports[path + '/' + fn][v];
123 //console.log('loaded : ' + path + '/'+v);
125 Seed.print("using file as object for " + path + ':' + typeof(assign) + ':' + v);
127 obj[v] = obj[v] || assign;
132 * create a delegate..
137 createDelegate : function(method, obj, args, appendArgs){
140 var callArgs = args || arguments;
141 if(appendArgs === true){
142 callArgs = Array.prototype.slice.call(arguments, 0);
143 callArgs = callArgs.concat(args);
144 }else if(typeof appendArgs == "number"){
145 callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
146 var applyArgs = [appendArgs, 0].concat(args); // create method call params
147 Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
149 return method.apply(obj || window, callArgs);
156 copyArray: function (ar) {
158 for(var i = 0 ; i < ar.length; i++) {
165 * create a definition of an interface..
167 * it get's registered, however not created.
172 create : function (o)
174 this.pre_registry[o.xnsid] = o;
180 * factory.. ??? - better name???
182 * converts a object structure, and constructs a class... using xtype/xns fields.
188 xnew: function (o, in_xnsid)
190 in_xnsid = in_xnsid || '';
191 var xnsid = '' + in_xnsid;
193 if ((o.xtype == 'Include') && (o.xns == 'xnew')) {
194 if (typeof(o.cls) != 'string') {
195 return xnew.xnew( o.cls.create(), xnsid);
198 o = this.pre_registry[cls];
200 if (typeof(o.xtype) == 'function') {
201 return new o.xtype(o);
204 o.listeners = o.listeners || {};
205 o.packing = o.packing || [ 'add' ];
206 o.items = o.items || [];
209 if (typeof(o.xnsid) !='undefined') {
210 Seed.print("\n\n------------------------------------------");
211 Seed.print( o.xnsid);
212 Seed.print("------------------------------------------\n\n");
215 if ((typeof(xnsid) != 'undefined') && !o.xnsid) {
218 if (o.xnsid && o.xid) {
219 xnew.registry = xnew.registry || { };
220 xnew.registry[o.xnsid] = xnew.registry[o.xnsid] || {};
221 xnew.registry[o.xnsid][o.xid] = o;
225 var isSeed = typeof(Seed) != 'undefined';
227 var constructor = false
231 Seed.print('xnew : ' + o.xns + '.' + o.xtype);
232 // support for xns='Gtk', xtyle='Window'..
233 var NS = imports.gi[o.xns];
235 Seed.print('Invalid xns: ' + o.xns);
237 constructor = NS[o.xtype];
239 Seed.print('Invalid xtype: ' + o.xns + '.' + o.xtype);
242 // how to hanlde gjs constructor???? - can it even be done..
244 o.el = o.el || (isSeed ? new constructor(o) : new constructor());
249 if (o.listeners._new) { // rendered!?!?
250 Seed.print('Call : ' + o.xtype+'.listeners._new');
251 o.listeners._new.call(o);
255 //Seed.print(o.pack.length);
256 // packing - if 'add method exists on created node use that..
259 for( var i =0; i < o.items.length;i++) {
264 o.items[i] = xnew.xnew(o.items[i], xnsid);
266 if (typeof(o.items[i].packing) == 'function') {
268 o.items[i].packing.apply(o, [ o , o.items[i] ]);
269 o.items[i].xparent = o;
272 var pack_m = o.items[i].packing[0];
274 if (pack_m && typeof(o.el[pack_m]) == 'undefined') {
275 Seed.print('pack method not available : ' + o.xtype + '.' + pack_m);
278 Seed.print('Pack ' + o.xtype + '.'+ pack_m + '(' + o.items[i].xtype + ')');
280 args = this.copyArray(o.items[i].packing);
281 args[0] = o.items[i].el;
282 Seed.print('args: ' + args.length);
284 o.el[pack_m].apply(o.el, args);
287 o.items[i].xparent = o;
292 for (var i in o.set) {
293 Seed.print('Set ' + i);
294 if (typeof(o.el[i].apply) !='undefined') {
295 o.el[i].apply(o.el, o.set[i]);
300 for (var i in o.listeners) {
301 if (i.substring(0,1) == '_') {
304 Seed.print('Add Listener ' + i);
306 var _li = this.createDelegate(o.listeners[i],o);
307 // private listeners that are not copied to GTk.
311 // Seed.print(typeof(_li));
312 o.el.signal[i].connect(_li);
314 o.el.connect( i, _li);
320 if (o.listeners._rendered) { // rendered!?!?
321 Seed.print('Call : ' + o.xtype+'.listeners._rendered');
322 o.listeners._rendered.call(o);