var gid = 1;
+// ctors needed for Constructing vala?? -
+
+var ctors = {
+ "Gtk.Label": [ "label" ],
+ "Gtk.Box": [ "orientation", "spacing:0" ],
+ "Gtk.MessageDialog" : [ "parent:null", "flags:Gtk.DialogFlags.MODAL", "message_type", "buttons", "text" ],
+ "Gtk.ScrolledWindow": [ "hadjustment:null", "vadjustment:null" ],
+ "Gtk.SourceBuffer": [ "table:null" ],
+ "Gtk.Table": [ "n_rows", "n_columns" , "homogeneous" ],
+ "Gtk.ToolButton": [ "icon_widget:null", "label:null" ],
+ "Gtk.HBox": [ "homogeneous:true", "spacing:0" ],
+ "Gtk.VBox": [ "homogeneous:true", "spacing:0" ],
+ "Gtk.ListStore": [ "n_columns", "columns" ],
+ "Gtk.FileChooserWidget" : [ "action"],
+ //"Gtk.Entry": [ ],
+};
+
+
+
Gtk = XObject.define(
return fn;
},
- saveJS: function()
+ saveVala: function()
{
var fn = GLib.path_get_dirname(this.path) + '/' + this.name + '.vala';
File.write(fn, this.toVala());
return fn;
+ },
+ valaCompileCmd : function()
+ {
+
+ var fn = '/tmp/' + this.name + '.vala';
+ print("WRITE : " + fn);
+ File.write(fn, this.toVala(true));
+
+
+
+ return ["valac",
+ "--pkg", "gio-2.0",
+ "--pkg" , "posix" ,
+ "--pkg" , "gtk+-3.0",
+ "--pkg", "libnotify",
+ "--pkg", "gtksourceview-3.0",
+ "--pkg", "libwnck-3.0",
+ fn , "-o", "/tmp/" + this.name];
+
+
+
+
},
vcnt : false,
- toVala: function()
+ toVala: function(testcompile)
{
var ret = '';
+ testcompile = testcompile || false;
this.vcnt = 0;
//print(JSON.stringify(this.items[0],null,4));
//print(JSON.stringify(this.items[0],null,4));Seed.quit();
var item= XObject.xclone(this.items[0]);
+ if (!item.id) {
+ item.id = this.name;
+
+ }
print(JSON.stringify(item,null,4));
ret += "/* -- to compile\n";
ret += "valac --pkg gio-2.0 --pkg posix --pkg gtk+-3.0 --pkg libnotify --pkg gtksourceview-3.0 --pkg libwnck-3.0 \\\n";
//ret += " " + item.xvala_id + ".vala -o /tmp/" + item.xvala_id +"\n";
- ret += " /tmp/test.vala -o /tmp/" + item.xvala_id +"\n";
+ ret += " /tmp/" + this.name + ".vala -o /tmp/" + this.name +"\n";
ret += "*/\n";
ret += "\n\n";
-
- ret += "/* -- to test class\n";
+ if (!testcompile) {
+ ret += "/* -- to test class\n";
+ }
+ //
ret += "static int main (string[] args) {\n";
ret += " Gtk.init (ref args);\n";
ret += " new " + item.xvala_xcls +"();\n";
- ret += " " + item.xvala_id +".show_all();\n";
+ ret += " " + this.name +".show_all();\n";
ret += " Gtk.main ();\n";
ret += " return 0;\n";
ret += "}\n";
- ret += "*/\n";
+ if (!testcompile) {
+ ret += "*/\n";
+ }
ret += "\n\n";
+
+
// print(JSON.stringify(item,null,4));
this.toValaItem(item,0, function(s) {
ret+= s;
var ns = item['|xns'] ;
if (ns == 'GtkSource') {
return 'Gtk.Source'
- ns = 'Gtk.Source';
+
}
return ns + '.';
},
toValaName : function(item) {
this.vcnt++;
- var cls = this.toValaNS(item) + item.xtype;
+ var cls = this.toValaNS(item) + item.xtype; // eg. Gtk.Window
var id = item.id ? item.id : (item.xtype + this.vcnt);
var props = this.palete.getPropertiesFor(cls, 'props');
var citems = {};
if (!depth) {
- strbuilder(inpad + "public static " + xcls + " " + item.id + ";\n\n");
- strbuilder(inpad + "private static " + xcls + " _this;\n\n");
+ // Global Vars..
+ strbuilder(inpad + "public static " + xcls + " " + this.name + ";\n\n");
}
// class header..
- strbuilder(inpad + "public class " + xcls + " : " + cls + "\n" + inpad + "{\n");
+ // class xxx { WrappedGtk el; }
+ strbuilder(inpad + "public class " + xcls + "\n" + inpad + "{\n");
+ strbuilder(pad + "public " + cls + " el;\n");
+ if (!depth) {
+
+ strbuilder(pad + "private static " + xcls + " _this;\n\n");
+ }
+
// properties??
strbuilder("\n" + ipad + "// my vars\n");
+ // Key = TYPE:name
for (var k in item) {
if (k[0] != '.') {
continue;
}
+ if (k == '.ctor') {
+ continue;
+ }
+
var kk = k.substring(1);
- var v = item[k];
- var vv = v.split(':');
- strbuilder(pad + "public " + vv[0] + " " + kk + ";\n");
- citems[k] = true;
+
+ var vv = kk.split(':');
+ if (vv[0] == 'signal') {
+ strbuilder(pad + "public " + vv[0] + " " + vv[1] + " " + vv[2] + item[k] + ";\n");
+ } else {
+
+ strbuilder(pad + "public " + vv[0] + " " + vv[1] + ";\n");
+ }
+ citems[k] = true;
}
// .vala props..
strbuilder("\n" + ipad + "// ctor \n");
strbuilder(pad + "public " + xcls + "()\n" + pad + "{\n");
+ // wrapped ctor..
+ // this may need to look up properties to fill in the arguments..
+ // introspection does not workk..... - as things like gtkmessagedialog
+ /*
+ if (cls == 'Gtk.Table') {
+
+ var methods = this.palete.getPropertiesFor(cls, 'methods');
+
+ print(JSON.stringify(this.palete.proplist[cls], null,4));
+ Seed.quit();
+ }
+ */
+
+
+ if (typeof(ctors[cls]) !== 'undefined') {
+ var args = [];
+ for(var i =0;i< ctors[cls].length;i++) {
+
+ var nv = ctors[cls][i].split(':');
+
+ if (typeof(item[nv[0]]) != 'undefined' && typeof(item[nv[0]]) != 'object' ) {
+ citems[nv[0]] = true;
+ args.push(JSON.stringify(item[nv[0]]));
+ continue;
+ }
+ if (typeof(item['|' + nv[0]]) != 'undefined' && typeof(item['|' + nv[0]]) != 'object' ) {
+ citems[nv[0]] = true;
+ citems['|' + nv[0]] = true;
+ args.push(item['|' + nv[0]]);
+ continue;
+ }
+ args.push(nv.length > 1 ? nv[1] : 'null');
+
+ }
+ strbuilder(ipad + "this.el = new " + cls + "( "+ args.join(", ") + " );\n" );
+
+ } else {
+ strbuilder(ipad + "this.el = new " + cls + "();\n" );
+
+ }
+ //var meths = this.palete.getPropertiesFor(item['|xns'] + '.' + item.xtype, 'methods');
+ //print(JSON.stringify(meths,null,4));Seed.quit();
+
+
+
// public static?
if (!depth) {
strbuilder(ipad + "_this = this;\n");
- strbuilder(ipad + item.id + " = this;\n");
+ strbuilder(ipad + this.name + " = this;\n");
} else {
if (item.xvala_id !== false) {
strbuilder(ipad + "_this." + item.xvala_id + " = this;\n");
}
var kk = k.substring(1);
var v = item[k];
- var vv = v.split(':');
- if (vv.length < 2) {
+ var vv = kk.split(':');
+ if (v.length < 1 || vv[0] == "signal") {
continue;
}
- strbuilder(ipad + "this" + k + " = " + vv[1] +";\n");
+ strbuilder(ipad + "this." + vv[1] + " = " + v +";\n");
}
props.forEach(function(p) {
+
+ if (typeof(citems[p.name]) != 'undefined') {
+ return;
+ }
+
if (typeof(item[p.name]) != 'undefined' && typeof(item[p.name]) != 'object' ) {
- citems[p.name] = true;
- strbuilder(ipad + "this." + p.name + " = " + JSON.stringify(item[p.name]) + ";\n");
+ citems[p.name] = true;
+
+ var val = JSON.stringify(item[p.name]);
+ if (['xalign','yalign'].indexOf(p.name) > -1) {
+ val +='f';
+ }
+ strbuilder(ipad + "this.el." + p.name + " = " + val + ";\n");
return;
}
if (typeof(item['|' + p.name]) != 'undefined' && typeof(item['|' + p.name]) != 'object' ) {
citems['|' + p.name] = true;
- strbuilder(ipad + "this." + p.name + " = " + item['|' + p.name] + ";\n");
+ //if (p.ctor_only ) {
+ // strbuilder(ipad + "Object(" + p.name + " : " + item['|' + p.name] + ");\n");
+ //} else {
+ strbuilder(ipad + "this.el." + p.name + " = " + item['|' + p.name] + ";\n");
+ //}
return;
}
// got a property..
if (typeof(item.items) != 'undefined') {
for(var i =0;i<item.items.length;i++) {
var ci = item.items[i];
+
var packing = ci.pack ? ci.pack.split(',') : [ 'add' ];
+ if (typeof(ci['|pack']) != 'undefined') {
+ packing =ci['|pack'].split(',');
+ }
var pack = packing.shift();
- strbuilder(ipad + "this." + pack + " ( new " + ci.xvala_xcls + "()" +
+ strbuilder(ipad + "var child_" + i + " = new " + ci.xvala_xcls + "();\n" )
+
+ strbuilder(ipad + "this.el." + pack + " ( child_" + i + ".el " +
(packing.length ? ", " + packing.join(",") : "") + " );\n"
);
for (var k in item.listeners) {
- var v = item.listeners[k].split(/\/*--/);
- if (v.length < 2) {
- continue;
- }
- var vv = v[1].replace('*/', "");
- //print(JSON.stringify(vv));Seed.quit();
- vv = vv.replace(/^\n+/,'');
- vv = vv.replace(/\n+$/,'');
- vv = vv.replace(/\n/g,"\n" + ipad);
- strbuilder(ipad + "this." + k + ".connect( " + vv + " );\n");
+ var v = item.listeners[k] ;
+
+ var vv = v.replace(/\n/g,"\n" + ipad);
+
+
+
+ strbuilder(ipad + "this.el." + k + ".connect( " + vv + " );\n");
}
}
for (var k in item) {
if (typeof(citems[k]) != 'undefined') {
- //strbuilder("\n" + pad + "// skip " + k + " - already used \n");
+ strbuilder("\n" + pad + "// skip " + k + " - already used \n");
continue;
}
if (k[0] != '|') {
- // strbuilder("\n" + pad + "// skip " + k + " - not pipe \n");
+ strbuilder("\n" + pad + "// skip " + k + " - not pipe \n");
continue;
}
// function in the format of {type} (args) { .... }
-
- var v = item[k].split(/\/*--/);
- if (v.length < 2) {
- continue;
- }
- var vv = v[1].replace('*/', "");
+
+ var vv = item[k];
//print(JSON.stringify(vv));Seed.quit();
vv = vv.replace(/^\n+/,'');
vv = vv.replace(/\n+$/,'');
vv = vv.replace(/\n/g,"\n" + ipad);
- vva = vv.split(' ');
- var rtype = vva.shift();
- var body = vva.join(' ');
-
+ var vva = k.split(':');
+ if (vva.length < 2) {
+ strbuilder("\n" + pad + "// skip " + k + " - no return type\n");
+ continue;
+ }
+ var rtype = vva.shift().substring(1);
+ var body = vv;
+ var fname = vva.shift() || '???';
- strbuilder(pad + "public " + rtype + " " + k.substring(1) +body + "\n");
+ strbuilder(pad + "public " + rtype + " " + fname + body + "\n");