function XObject (cfg) {
// first apply cfg if set.
- this.config = cfg;
- if (cfg.init) {
- this.init = cfg.init; // override!
+ //print("new XOBJECT!!!");
+ this.config = {};
+ this.constructor = XObject;
+
+ // copy down all elements into self..
+
+ for (var i in cfg) {
+ this[i] = cfg[i];
+ if ((typeof(cfg[i]) == 'function') || (typeof(cfg[i]) == 'function')) {
+ continue;
+ }
+ // these properties are not copied to cfg.
+ if (i == 'pack' ||
+ i == 'id' ||
+ i == 'xtype' ||
+ i == 'xdebug' ||
+ i == 'xns') {
+ continue;
+ }
+
+
+ this.config[i] = cfg[i];
}
+ this.items = this.items || [];
+ // pack can be false!
+ this.pack = typeof(this.pack) == 'undefined' ? ['add'] : this.pack;
}
*/
init : function()
{
- var cfg = this.config;
-
- print("new xobj?" + XObject.keys(cfg).join(','));
- //print(cfg);
- o = {};
-
- cfg.items = cfg.items || [];
-
- XObject.extend(o, cfg); // copy everything into o.
-
- this.pack = typeof(cfg.pack) == 'undefined' ? ['add'] : cfg.pack;
-
- XObject.extend(this, o);
-
+
+ var items = [];
+ this.items.forEach(function(i) {
+ items.push(i);
+ });
// remove items.
-
this.listeners = this.listeners || {};
this.items = [];
-
- // remove objects/functions from o, so they can be sent to the contructor.
- for (var i in o) {
- if ((typeof(o[i]) == 'object') ||
- (typeof(o[i]) == 'function') ||
- i == 'pack' ||
- i == 'id' ||
- i == 'xtype' ||
- i == 'xdebug' ||
- i == 'xns'
- ) {
- delete o[i];
- }
- }
-
+
// do we need to call 'beforeInit here?'
// handle include?
var isSeed = typeof(Seed) != 'undefined';
// xtype= Gtk.Menu ?? what about c_new stuff?
- print("init: typeof(xtype): " + typeof(this.xtype));
- if (typeof(this.xtype) == 'function') {
- print("func?" + XObject.keys(o).join(','));
- this.el = this.el || this.xtype(o);
+ if (XObject.debug) print("init: typeof(xtype): " + typeof(this.xtype));
+ if (!this.el && typeof(this.xtype) == 'function') {
+ if (XObject.debug) print("func?" + XObject.keys(this.config).join(','));
+ this.el = this.xtype(this.config);
}
- if (typeof(this.xtype) == 'object') {
- print("obj?" + XObject.keys(o).join(','));
- this.el = this.el || new this.xtype(o);
+ if (!this.el && typeof(this.xtype) == 'object') {
+ if (XObject.debug) print("obj?" + XObject.keys(this.config).join(','));
+ this.el = new (this.xtype)(this.config);
}
//print(this.el);
- if (!this.el && o.xns) {
+ if (!this.el && this.xns) {
- var NS = imports.gi[o.xns];
+ var NS = imports.gi[this.xns];
if (!NS) {
- Seed.print('Invalid xns: ' + o.xns);
+ Seed.print('Invalid xns: ' + this.xns);
}
- constructor = NS[o.xtype];
+ constructor = NS[this.xtype];
if (!constructor) {
- Seed.print('Invalid xtype: ' + o.xns + '.' + o.xtype);
+ Seed.print('Invalid xtype: ' + this.xns + '.' + this.xtype);
}
- this.el = isSeed ? new constructor(o) : new constructor();
+ this.el = isSeed ? new constructor(this.config) : new constructor();
}
- print("init: typeof(el):" + this.typeof(el));
+ if (XObject.debug) print("init: typeof(el):" + typeof(this.el));
// always overlay props..
// check for 'write' on object..
*/
- for (var i in o) {
+ for (var i in this.config) {
// only write to writable properties
// if (XObject.writeablePropsCache[this.xtype.type].indexOf(i) < 0) {
// continue;
// }
- this.el[i] = o[i];
+ this.el[i] = this.config[i];
}
// register it!
//if (o.xnsid && o.id) {
// XObject.registry[o.xnsid] = XObject.registry[o.xnsid] || {};
// XObject.registry[o.xnsid][o.id] = this;
//}
-
- cfg.items.forEach(this.addItem, this);
+ var _this=this;
+ items.forEach(function(i) {
+ _this.addItem(i);
+ })
+
for (var i in this.listeners) {
this.addListener(i, this.listeners[i]);
* @arg cfg {Object} same as XObject constructor.
*/
addItem : function(o) {
-
- print("CTR:PROTO:" + ( o.id ? o.id : '??'));
- print(o.constructor.prototype == XObject.prototype);
+ if (typeof(o) == 'undefined') {
+ print("Invalid Item added to this!");
+ imports.console.dump(this);
+ Seed.quit();
+ }
var item = (o.constructor == XObject) ? o : new XObject(o);
item.init();
- print("addItem - call init [" + item.pack.join(',') + ']');
- print(item.el);
+ //print("CTR:PROTO:" + ( item.id ? item.id : '??'));
+ // print("addItem - call init [" + item.pack.join(',') + ']');
+ if (!item.el) {
+ print("NO EL!");
+ imports.console.dump(item);
+ Seed.quit();
+ }
+
item.parent = this;
this.items.push(item);
}
if (typeof(item.pack) == 'function') {
// parent, child
- item.pack.apply(o, [ o , o.items[i] ]);
+ item.pack.apply(item, [ this , item ]);
item.parent = this;
return;
}
//Seed.print('Pack ' + this.el + '.'+ pack_m + '(' + item.el + ')');
args.unshift(item.el);
- print('[' + args.join(',') +']');
+ if (XObject.debug) print('[' + args.join(',') +']');
//Seed.print('args: ' + args.length);
if (pack_m) {
this.el[pack_m].apply(this.el, args);
addListener : function(sig, fn)
{
- Seed.print("Add signal " + sig);
+ if (XObject.debug) Seed.print("Add signal " + sig);
var _li = XObject.createDelegate(fn,this);
// private listeners that are not copied to GTk.
this.items.forEach(function(ch) {
+ if (ret) {
+ return;
+ }
if (ch.id == xid) {
ret = ch;
- return true;
}
})
if (ret) {
return ret;
}
// iterate children.
+ var _this = this;
this.items.forEach(function(ch) {
- ret = ch.get(xid);
if (ret) {
- return true;
+ return;
+ }
+ if (!ch.get) {
+ print("invalid item...");
+ imports.console.dump(_this);
+ Seed.quit();
}
+ ret = ch.get(xid);
+
})
return ret;
}
}
-
-XObject.writeablePropsCache = { };
-
+
/**
* Copies all the properties of config to obj.
*
XObject.extend(XObject,
{
+ /**
+ * @property {Boolean} debug XObject debugging. - set to true to debug.
+ *
+ */
+ debug : false,
/**
* Copies all the properties of config to obj, if the do not exist.
* @param {Object} obj The receiver of the properties