//<Script type="text/javascript">
Gio = imports.gi.Gio;
+GLib = imports.gi.GLib;
console = imports.console;
XObject = imports.XObject.XObject;
-
+File = imports.File.File;
//----------------------- our roo verison
Base = imports.Builder.Provider.File.Base.Base;
//console.dump(cfg);
cfg.parent = cfg.parent || '';
if (!cfg.name || !cfg.fullname ) {
- cfg.name = cfg.path.split('/').pop().replace(/\.js$/, '');
+
+ // name is in theory filename without .bjs (or .js eventually...)
+ cfg.name = cfg.path.split('/').pop().replace(/\.(bjs|js)$/, '');
+
cfg.fullname = (cfg.parent.length ? (cfg.parent + '.') : '' ) + cfg.name;
}
- this.items = [];
+ this.items = false;
if (cfg.json) {
var jstr = JSON.parse(cfg.json);
this.items = [ jstr ];
// super?!?!
this.id = 'file-gtk-' + gid++;
+ //console.dump(this);
// various loader methods..
},
loadItems : function(cb)
{
- if (!cb) {
- throw "no callback for loadItems";
- }
+
console.log("load Items!");
if (this.items !== false) {
return false;
}
+ if (!cb) {
+ throw {
+ name: "ArgumentError",
+ message : "no callback for loadItems"
+ };
+ }
Seed.print("load: " + this.path);
- var file = Gio.file_new_for_path(this.path);
+
- var _this = this;
- file.read_async(0, null, function(source,result) {
- var stream = source.read_finish(result)
- var dstream = new Gio.DataInputStream.c_new(stream);
-
- var src = dstream.read_until("");
- var cfg = JSON.parse(src);
- print("loaded data");
- console.dump(cfg);
-
- _this.name = cfg.name;
- _this.parent = cfg.parent;
- _this.title = cfg.title;
- _this.items = cfg.items || [];
+ var _this = this;
+ var src = File.read(this.path);
+
+ var cfg = JSON.parse(src);
+ print("loaded data");
+ //console.dump(cfg);
+
+ //_this.name = cfg.name; -- this should not happen - name should always match filename!!
+ _this.parent = cfg.parent;
+ _this.title = cfg.title;
+ _this.items = cfg.items || [];
+
cb();
+
+
// update to new JSDOC api!?
/*
cb();
*/
- });
+
},
- /**
- * fixme - update to new style
- *
- *
+ /**
+ * convert xtype for munged output..
*
*/
-
- toSourceStdClass: function()
+ mungeXtype : function(xtype, els)
{
- var cfg = this.items[0]
- var fcfg = XObject.extend({ }, this.items[0]);
- delete fcfg['*class'];
- delete fcfg['*extends'];
- delete fcfg['*static'];
- delete fcfg['|constructor'];
-
- var hasExtends = (typeof(cfg['*extends']) != 'undefined') && cfg['*extends'].length;
- var hasConstructor = (typeof(cfg['|constructor']) != 'undefined');
- var isStatic = (typeof(cfg['*static']) == '*static');
-
- var newline = '';
- var endline = '';
- if (hasExtends) {
- newline = hasConstructor ?
-
-
- cfg['//constructor'] + "\n" +
- cfg['*class'] + " = " + cfg['|constructor'] + "\n\n"+
- "Roo.extend(" + cfg['*class'] + ":, " + cfg['*extends'] + ", " :
-
- cfg['//*class'] + "\n" +
- cfg['*class'] + " = new " + cfg['*extends'] + "(" ;
-
- endline = ');';
- } else {
-
-
-
- newline = hasConstructor ?
-
- cfg['//constructor'] + "\n" +
- cfg['*class'] + " = " + cfg['|constructor'] + "\n\n"+
- 'Roo.apply( ' + cfg['*class'] + ".prototype , " :
-
- cfg['//*class'] + "\n" +
- cfg['*class'] + " = ";
-
-
- endline = hasConstructor ? ');' : ';';
- }
-
- return this.outputHeader() +
- newline +
- this.objectToJsString(fcfg,1) +
- endline;
-
-
-
-
+ els.push('xtype: '+ xtype);
},
- toSource: function()
+ /**
+ * saveJS
+ *
+ * save as a javascript file.
+ *
+ *
+ *
+ */
+ saveJS: function()
{
- // dump the file tree back out to a string.
-
- if (typeof(this.items[0]['*class']) != 'undefined') {
- return this.toSourceStdClass();
+ if (!this.items[0]) {
+ return false;
}
+ var data = JSON.parse(JSON.stringify(this.items[0]));
+ var i = [ 'Gtk', 'Gdk', 'Pango', 'GLib', 'Gio', 'GObject', 'GtkSource', 'WebKit', 'Vte' , 'GtkClutter' , 'Gdl'];
+ var src = "";
+ i.forEach(function(e) {
+ src += e+" = imports.gi." + e +";\n";
+ });
+ src += "console = imports.console;\n"; // path?!!?
+ src += "XObject = imports.XObject.XObject;\n"; // path?!!?
- // technically there will be different versions of this.
- var o = this.mungePropObj(this.items[0]);
- //console.dump(o);
- //Seed.quit();
-
- return this.outputHeader() +
- [
- "function create()",
- "{",
- " return "
- ].join("\n") +
- this.objectToJsString(o,2) +
- [
- ";", // end return value..
- "}"
- ].join("\n");
+ src += this.name + '=new XObject('+ this.mungeToString(data) + ");\n";
+ src += this.name + '.init();\n';
+ // register it in the cache
+ src += "XObject.cache['/" + this.name + "'] = " + this.name + ";\n";
-
-
-
-
-
+ var fn = GLib.path_get_dirname(this.path) + '/' + this.name + '.js';
+ print("WRITE : " + fn);
+ File.write(fn, src);
+ return fn;
},
-
- outputHeader : function()
- {
- var ret = '//<script type="text/javascript">' + "\n";
- ret += "\n\n// gi imports\n";
- Roo.each(this.giImports, function(i) {
- ret += i + " = imports.gi." + i + ";\n";
- });
- ret += "\n\n// file imports\n";
- for(var k in this.imports) {
- ret += k + " = imports[" + JSON.stringify(this.imports[k]) + "];\n";
- }
-
- return ret + "\n\n";
- }
-
/*
getTree : function( o ) {
}
*/
+ getHelpUrl : function(cls)
+ {
+ return 'http://devel.akbkhome.com/seed/' + cls + '.html';
+ }
});
\ No newline at end of file