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 = GLib.dir_read_name(gdir);
112 //console.log('trying ' + path + '/' + fn);
114 GLib.dir_close(gdir);
117 if (!fn.match(/.js$/)) {
120 var v = fn.replace(/.js$/, '');
121 var assign = imports[path + '/' + fn][v];
122 //console.log('loaded : ' + path + '/'+v);
124 Seed.print("using file as object for " + path + ':' +v);
126 obj[v] = obj[v] || assign;
131 * create a delegate..
136 createDelegate : function(method, obj, args, appendArgs){
139 var callArgs = args || arguments;
140 if(appendArgs === true){
141 callArgs = Array.prototype.slice.call(arguments, 0);
142 callArgs = callArgs.concat(args);
143 }else if(typeof appendArgs == "number"){
144 callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
145 var applyArgs = [appendArgs, 0].concat(args); // create method call params
146 Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
148 return method.apply(obj || window, callArgs);
155 copyArray: function (ar) {
157 for(var i = 0 ; i < ar.length; i++) {
164 * create a definition of an interface..
166 * it get's registered, however not created.
171 create : function (o)
173 this.pre_registry[o.xnsid] = o;
179 * factory.. ??? - better name???
181 * converts a object structure, and constructs a class... using xtype/xns fields.
187 xnew: function (o, in_xnsid)
189 in_xnsid = in_xnsid || '';
190 var xnsid = '' + in_xnsid;
192 if ((o.xtype == 'Include') && (o.xns == 'xnew')) {
193 if (typeof(o.cls) != 'string') {
194 return xnew.xnew( o.cls.create(), xnsid);
197 o = this.pre_registry[cls];
199 if (typeof(o.xtype) == 'function') {
200 return new o.xtype(o);
203 o.listeners = o.listeners || {};
204 o.packing = o.packing || [ 'add' ];
205 o.items = o.items || [];
208 if (typeof(o.xnsid) !='undefined') {
209 Seed.print("\n\n------------------------------------------");
210 Seed.print( o.xnsid);
211 Seed.print("------------------------------------------\n\n");
214 if ((typeof(xnsid) != 'undefined') && !o.xnsid) {
217 if (o.xnsid && o.xid) {
218 xnew.registry = xnew.registry || { };
219 xnew.registry[o.xnsid] = xnew.registry[o.xnsid] || {};
220 xnew.registry[o.xnsid][o.xid] = o;
224 var isSeed = typeof(Seed) != 'undefined';
226 var constructor = false
230 Seed.print('xnew : ' + o.xns + '.' + o.xtype);
231 // support for xns='Gtk', xtyle='Window'..
232 var NS = imports.gi[o.xns];
234 Seed.print('Invalid xns: ' + o.xns);
236 constructor = NS[o.xtype];
238 Seed.print('Invalid xtype: ' + o.xns + '.' + o.xtype);
241 // how to hanlde gjs constructor???? - can it even be done..
243 o.el = o.el || (isSeed ? new constructor(o) : new constructor());
248 if (o.listeners._new) { // rendered!?!?
249 Seed.print('Call : ' + o.xtype+'.listeners._new');
250 o.listeners._new.call(o);
254 //Seed.print(o.pack.length);
255 // packing - if 'add method exists on created node use that..
258 for( var i =0; i < o.items.length;i++) {
263 o.items[i] = xnew.xnew(o.items[i], xnsid);
265 if (typeof(o.items[i].packing) == 'function') {
267 o.items[i].packing.apply(o, [ o , o.items[i] ]);
268 o.items[i].xparent = o;
271 var pack_m = o.items[i].packing[0];
273 if (pack_m && typeof(o.el[pack_m]) == 'undefined') {
274 Seed.print('pack method not available : ' + o.xtype + '.' + pack_m);
277 Seed.print('Pack ' + o.xtype + '.'+ pack_m + '(' + o.items[i].xtype + ')');
279 args = this.copyArray(o.items[i].packing);
280 args[0] = o.items[i].el;
281 Seed.print('args: ' + args.length);
283 o.el[pack_m].apply(o.el, args);
286 o.items[i].xparent = o;
291 for (var i in o.set) {
292 Seed.print('Set ' + i);
293 if (typeof(o.el[i].apply) !='undefined') {
294 o.el[i].apply(o.el, o.set[i]);
299 for (var i in o.listeners) {
300 if (i.substring(0,1) == '_') {
303 Seed.print('Add Listener ' + i);
305 var _li = this.createDelegate(o.listeners[i],o);
306 // private listeners that are not copied to GTk.
310 // Seed.print(typeof(_li));
311 o.el.signal[i].connect(_li);
313 o.el.connect( i, _li);
319 if (o.listeners._rendered) { // rendered!?!?
320 Seed.print('Call : ' + o.xtype+'.listeners._rendered');
321 o.listeners._rendered.call(o);