xnew.js
authorAlan Knowles <alan@akbkhome.com>
Mon, 28 Jun 2010 10:14:55 +0000 (18:14 +0800)
committerAlan Knowles <alan@akbkhome.com>
Mon, 28 Jun 2010 10:14:55 +0000 (18:14 +0800)
xnew.js [deleted file]

diff --git a/xnew.js b/xnew.js
deleted file mode 100644 (file)
index 873c983..0000000
--- a/xnew.js
+++ /dev/null
@@ -1,328 +0,0 @@
-//<script type="text/javascript">
-
-/**
- * 
- * abstraction layer / tree builder etc...
- * 
- * 
- * 
- * 
- */
-
-var console  = imports['console.js'].console;
-
-//var xnew = imports['xnew.js'].xnew;
-
-function apply (o, c){
-    if(o && c && typeof c == 'object'){
-        for(var p in c){
-            o[p] = c[p];
-        }
-    }
-    return o;
-};
-
-
-var xnew = {
-    registry : { },
-    pre_registry : { },
-    
-    dumpRegistry: function(scope, id)
-    {
-        var ret = { }
-           
-        for (var i in xnew.registry) {
-            ret[i] = [];
-            for(var j in xnew.registry[i]) {
-                ret[i].push(j);
-           }
-        }
-        return ret;
-        
-    },
-    /**
-     * xnew.get(this, 'someid')
-     * xnew.get(this).someid 
-     * 
-     * fetches from a registry of components.
-     * 
-     * defined by {
-     *       xnsid : 'Builder.test' // at top leve, all sub elements inherit it..
-     *       xid : 'test'
-     * 
-     * 
-     */
-
-    get: function(scope, id)
-    {
-        var s = typeof(scope) == 'object' ? scope.xnsid : scope;
-        
-        if (typeof(this.pre_registry[s]) != 'undefined') {
-            this.xnew(this.pre_registry[s]);
-            delete this.pre_registry[s];
-        }
-        
-        
-        if (typeof(id) == 'undefined') {
-            if (typeof(xnew.registry[s]) !='undefined') {
-                Seed.print("Success - got " + s);
-                return xnew.registry[s];
-            }
-            
-            var ar = s.split('.');
-            id = ar.pop();
-            s = ar.join('.');
-        }
-        
-        
-        xnew.registry[s] = xnew.registry[s] || {};
-           
-        
-        var ret = typeof(xnew.registry[s][id]) == 'undefined' ? false : xnew.registry[s][id]
-        
-        
-        Seed.print((ret ? "Success" : "FAILED") + " - check for NS:" + s + " ID: " + id);
-        if (!ret) {
-            console.dump(this.dumpRegistry());
-           }
-        return ret;
-        
-    },
-    
-    
-    /**
-     * load a directory, and overlay it's properties onto the variable provider..
-     * 
-     * 
-     * 
-     */
-
-
-    load: function (obj, path) 
-    {
-        var GLib = imports.gi.GLib;
-        var ret = [];
-        var gdir = GLib.dir_open(__script_path__ + '/' + path,0);
-        
-        
-        
-        while (true) {
-            
-            var fn = gdir.read_name ? gdir.read_name() :  GLib.dir_read_name(gdir);
-            //console.log('trying ' + path + '/' + fn);
-            if (!fn) {
-                gdir.close ? gdir.close() : GLib.dir_close(gdir);
-                return;
-            }
-            if (!fn.match(/.js$/)) {
-                continue;
-            }
-            var v = fn.replace(/.js$/, '');
-            imports[path + '/' + fn];
-            var assign = imports[path + '/' + fn][v];
-            //console.log('loaded : ' + path + '/'+v);
-            if (!obj[v]) {
-                Seed.print("using file as object for " + path + ':' + typeof(assign) + ':' + v);
-            }
-            obj[v] = obj[v] || assign;
-            
-        }
-    },
-    /**
-     * create a  delegate..
-     * 
-     */
-
-
-    createDelegate : function(method, obj, args, appendArgs){
-        
-        return function() {
-            var callArgs = args || arguments;
-            if(appendArgs === true){
-                callArgs = Array.prototype.slice.call(arguments, 0);
-                callArgs = callArgs.concat(args);
-            }else if(typeof appendArgs == "number"){
-                callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
-                    var applyArgs = [appendArgs, 0].concat(args); // create method call params
-                    Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
-                }
-                return method.apply(obj || window, callArgs);
-            };
-    },
-    /**
-     * copy an array...
-     * 
-     */
-    copyArray: function (ar) {
-        var ret = [];
-        for(var i = 0 ; i < ar.length; i++) {
-            ret[i] = ar[i];
-        }
-        return ret;
-    },
-    
-    /**
-     * create a definition of an interface..
-     * 
-     * it get's registered, however not created.
-     * 
-     * 
-     * 
-     */
-    create : function (o)
-    {
-        this.pre_registry[o.xnsid] = o;
-      
-    },
-    
-    
-    /**
-     * factory.. ??? - better name???
-     * 
-     * converts a object structure, and constructs a class... using xtype/xns fields.
-     * 
-     * 
-     * 
-     */
-    
-    xnew: function (o, in_xnsid)
-    {
-        in_xnsid = in_xnsid || '';
-        var xnsid = '' + in_xnsid;
-         
-        if ((o.xtype == 'Include') && (o.xns == 'xnew')) {
-            if (typeof(o.cls) != 'string') {
-                return xnew.xnew( o.cls.create(), xnsid);
-            }
-            var cls = o.cls;
-            o = this.pre_registry[cls];
-        }
-        if (typeof(o.xtype) == 'function') {
-            return   new o.xtype(o);
-        }
-        o.set = o.set || {}; 
-        o.listeners = o.listeners || {}; 
-        o.packing = o.packing || [ 'add' ]; 
-        o.items = o.items || []; 
-        // handle xnsid..
-        
-        if (typeof(o.xnsid) !='undefined') {
-            Seed.print("\n\n------------------------------------------");
-            Seed.print( o.xnsid);
-            Seed.print("------------------------------------------\n\n");
-            xnsid = ''+ o.xnsid;
-        }
-        if ((typeof(xnsid) != 'undefined') &&  !o.xnsid) {
-            o.xnsid = xnsid;
-        }
-        if (o.xnsid  && o.xid) {
-            xnew.registry = xnew.registry || { };
-            xnew.registry[o.xnsid] = xnew.registry[o.xnsid] || {}; 
-            xnew.registry[o.xnsid][o.xid] = o;
-        }
-        
-        
-        var isSeed = typeof(Seed) != 'undefined';
-        
-        var constructor = false
-        
-     
-        // XNS contructor..
-        Seed.print('xnew : ' + o.xns + '.' + o.xtype);
-        // support for xns='Gtk', xtyle='Window'..
-        var NS = imports.gi[o.xns];
-        if (!NS) {
-            Seed.print('Invalid xns: ' + o.xns);
-        }
-        constructor = NS[o.xtype];
-        if (!constructor) {
-            Seed.print('Invalid xtype: ' + o.xns + '.' + o.xtype);
-        }
-         
-        // how to hanlde gjs constructor???? - can it even be done..
-        
-        o.el  = o.el ||  (isSeed ? new constructor(o) : new constructor());
-        
-        
-        
-        
-        if (o.listeners._new) { // rendered!?!?
-            Seed.print('Call : ' + o.xtype+'.listeners._new');
-            o.listeners._new.call(o);
-        }
-        
-        
-        //Seed.print(o.pack.length);
-        // packing  - if 'add method exists on created node use that..
-        
-        
-        for( var i =0; i < o.items.length;i++) {
-            
-            
-            
-            
-            o.items[i] = xnew.xnew(o.items[i], xnsid);
-            
-            if (typeof(o.items[i].packing) == 'function') {
-                // parent, child
-                o.items[i].packing.apply(o, [ o , o.items[i] ]);
-                o.items[i].xparent = o;
-                continue;
-            }
-            var pack_m = o.items[i].packing[0];
-            
-            if (pack_m && typeof(o.el[pack_m]) == 'undefined') {
-                Seed.print('pack method not available : ' + o.xtype + '.' +  pack_m);
-                continue;
-            }
-            Seed.print('Pack ' + o.xtype + '.'+ pack_m + '(' + o.items[i].xtype + ')');
-            // copy..
-            args = this.copyArray(o.items[i].packing);
-            args[0] = o.items[i].el;
-            Seed.print('args: ' + args.length);
-            if (pack_m) {
-                o.el[pack_m].apply(o.el, args);
-            }
-            
-            o.items[i].xparent = o;
-        }
-        
-        /// Setting stuff...
-        
-        for (var i in o.set) {
-            Seed.print('Set ' + i);
-            if (typeof(o.el[i].apply) !='undefined') {
-                o.el[i].apply(o.el, o.set[i]);
-               }
-            
-        }
-          
-        for (var i in o.listeners) {
-            if (i.substring(0,1) == '_') {
-                continue;
-            }
-            Seed.print('Add Listener ' + i);
-            
-            var _li = this.createDelegate(o.listeners[i],o);
-            // private listeners that are not copied to GTk.
-            
-             
-            if (isSeed) {
-              //   Seed.print(typeof(_li));
-                o.el.signal[i].connect(_li);
-            } else {
-                o.el.connect( i, _li);
-            }
-             
-        }
-       
-        // apply functions..
-        if (o.listeners._rendered) { // rendered!?!?
-            Seed.print('Call : ' + o.xtype+'.listeners._rendered');
-            o.listeners._rendered.call(o);
-        }
-        
-        return o;
-
-    }
-};