1 //<Script type="text/javascript">
4 GLib = imports.gi.GLib;
6 XObject = imports.XObject.XObject;
7 File = imports.File.File;
9 //----------------------- our roo verison
10 Base = imports.JsRender.Base.Base;
15 "Gtk.MessageDialog" : [ "parent:null", "flags:Gtk.DialogFlags.MODAL", "message_type", "buttons", "text" ],
16 "Gtk.ToolButton": [ "icon_widget:null", "label:null" ],
18 "Gtk.ScrolledWindow": [ "hadjustment:null", "vadjustment:null" ],
19 "Gtk.SourceBuffer": [ "table:null" ],
20 "Gtk.VBox": [ "homogeneous:true", "spacing:0" ],
33 //"name":"Edit Module Details",
35 //"btype":"FORM", // was to be components...
37 //"module":"Pman.Tab.BuilderTop2"
39 cfg.parent = cfg.parent || '';
40 if (!cfg.name || !cfg.fullname ) {
42 // name is in theory filename without .bjs (or .js eventually...)
43 cfg.name = cfg.path.split('/').pop().replace(/\.(bjs|js)$/, '');
45 cfg.fullname = (cfg.parent.length ? (cfg.parent + '.') : '' ) + cfg.name;
51 var jstr = JSON.parse(cfg.json);
52 this.items = [ jstr ];
53 //console.log(cfg.items.length);
54 delete cfg.json; // not needed!
58 var p = cfg.items && cfg.items.length && cfg.items[0].parent ? cfg.items[0].parent : false;
60 // ensure real data is set...
71 Gtk.superclass.constructor.call(this, cfg);
75 this.id = 'file-gtk-' + gid++;
77 // various loader methods..
83 setNSID : function(id)
86 this.items[0]['*class'] = id;
94 loadItems : function(cb)
98 if (this.items !== false) {
103 name: "ArgumentError",
104 message : "no callback for loadItems"
107 Seed.print("load: " + this.path);
113 var src = File.read(this.path);
115 var cfg = JSON.parse(src);
116 print("loaded data");
119 //_this.name = cfg.name; -- this should not happen - name should always match filename!!
120 _this.parent = cfg.parent;
121 _this.title = cfg.title;
122 _this.items = cfg.items || [];
132 * convert xtype for munged output..
135 mungeXtype : function(xtype, els)
137 els.push('xtype: '+ xtype);
140 toSource : function()
143 if (!this.items[0]) {
146 var data = JSON.parse(JSON.stringify(this.items[0]));
147 // we should base this on the objects in the tree really..
148 var i = [ 'Gtk', 'Gdk', 'Pango', 'GLib', 'Gio', 'GObject',
149 'GtkSource', 'WebKit', 'Vte' ]; //, 'GtkClutter' , 'Gdl'];
151 i.forEach(function(e) {
152 src += e+" = imports.gi." + e +";\n";
155 src += "console = imports.console;\n"; // path?!!?
156 src += "XObject = imports.XObject.XObject;\n"; // path?!!?
159 src += this.name + '=new XObject('+ this.mungeToString(data) + ");\n";
160 src += this.name + '.init();\n';
161 // register it in the cache
162 src += "XObject.cache['/" + this.name + "'] = " + this.name + ";\n";
170 Base.prototype.save.call(this);
178 * save as a javascript file.
179 * why is this not save...???
186 var fn = GLib.path_get_dirname(this.path) + '/' + this.name + '.js';
187 print("WRITE : " + fn);
188 File.write(fn, this.toSource());
196 var fn = GLib.path_get_dirname(this.path) + '/' + this.name + '.vala';
197 print("WRITE : " + fn);
198 File.write(fn, this.toVala());
202 valaCompileCmd : function()
205 var fn = '/tmp/' + this.name + '.vala';
206 print("WRITE : " + fn);
207 File.write(fn, this.toVala(true));
214 "--pkg" , "gtk+-3.0",
215 "--pkg", "libnotify",
216 "--pkg", "gtksourceview-3.0",
217 "--pkg", "libwnck-3.0",
218 fn , "-o", "/tmp/" + this.name];
227 getTree : function( o ) {
233 getHelpUrl : function(cls)
235 return 'http://devel.akbkhome.com/seed/' + cls + '.html';
240 toVala: function(testcompile)
243 testcompile = testcompile || false;
246 //print(JSON.stringify(this.items[0],null,4));
247 //print(JSON.stringify(this.items[0],null,4));Seed.quit();
249 var item= XObject.xclone(this.items[0]);
251 print(JSON.stringify(item,null,4));
253 this.palete = new imports.Palete.Gtk.Gtk({});
256 this.toValaName(item);
257 // print(JSON.stringify(item,null,4));Seed.quit();
259 ret += "/* -- to compile\n";
260 ret += "valac --pkg gio-2.0 --pkg posix --pkg gtk+-3.0 --pkg libnotify --pkg gtksourceview-3.0 --pkg libwnck-3.0 \\\n";
261 //ret += " " + item.xvala_id + ".vala -o /tmp/" + item.xvala_id +"\n";
262 ret += " /tmp/" + this.name + ".vala -o /tmp/" + this.name +"\n";
266 ret += "/* -- to test class\n";
269 ret += "static int main (string[] args) {\n";
270 ret += " Gtk.init (ref args);\n";
271 ret += " new " + item.xvala_xcls +"();\n";
272 ret += " " + this.name +".show_all();\n";
273 ret += " Gtk.main ();\n";
274 ret += " return 0;\n";
280 // print(JSON.stringify(item,null,4));
281 this.toValaItem(item,0, function(s) {
289 toValaNS : function(item)
291 var ns = item['|xns'] ;
292 if (ns == 'GtkSource') {
299 toValaName : function(item) {
301 var cls = this.toValaNS(item) + item.xtype;
302 var id = item.id ? item.id : (item.xtype + this.vcnt);
303 var props = this.palete.getPropertiesFor(cls, 'props');
307 item.xvala_cls = cls;
308 item.xvala_xcls = 'Xcls_' + id;
309 item.xvala_id = item.id ? item.id : false;
310 this.vitems.push(item);
312 if (typeof(item.items) == 'undefined') {
315 for(var i =0;i<item.items.length;i++) {
316 this.toValaName(item.items[i]);
322 toValaItem : function(item, depth, strbuilder)
324 // print(JSON.stringify(item,null,4));
326 var inpad = new Array( depth +1 ).join(" ");
328 var pad = new Array( depth +2 ).join(" ");
329 var ipad = new Array( depth +3 ).join(" ");
331 var cls = item.xvala_cls;
333 var xcls = item.xvala_xcls;
339 strbuilder(inpad + "public static " + xcls + " " + this.name + ";\n\n");
345 // class xxx { WrappedGtk el; }
346 strbuilder(inpad + "public class " + xcls + "\n" + inpad + "{\n");
347 strbuilder(pad + "public " + cls + " el;\n");
350 strbuilder(pad + "private static " + xcls + " _this;\n\n");
356 //public bool paused = false;
357 //public static StatusIconA statusicon;
359 //strbuilder(pad + "public static " + xcls + " _this;\n");
360 for(var i=1;i < this.vitems.length; i++) {
361 if (this.vitems[i].xvala_id !== false) {
362 strbuilder(pad + "public " + this.vitems[i].xvala_xcls + " " + this.vitems[i].xvala_id + ";\n");
368 strbuilder("\n" + ipad + "// my vars\n");
372 for (var k in item) {
381 var kk = k.substring(1);
383 var vv = kk.split(':');
384 if (vv[0] == 'signal') {
385 strbuilder(pad + "public " + vv[0] + " " + vv[1] + " " + vv[2] + item[k] + ";\n");
388 strbuilder(pad + "public " + vv[0] + " " + vv[1] + ";\n");
396 strbuilder("\n" + ipad + "// ctor \n");
397 strbuilder(pad + "public " + xcls + "()\n" + pad + "{\n");
400 // this may need to look up properties to fill in the arguments..
401 // introspection does not workk..... - as things like gtkmessagedialog
402 if (cls == 'Gtk.Table') {
404 var methods = this.palete.getPropertiesFor(cls, 'methods');
406 print(JSON.stringify(this.palete.proplist[cls], null,4));
412 if (typeof(ctors[cls]) !== 'undefined') {
414 for(var i =0;i< ctors[cls].length;i++) {
416 var nv = ctors[cls][i].split(':');
418 if (typeof(item[nv[0]]) != 'undefined' && typeof(item[nv[0]]) != 'object' ) {
419 citems[nv[0]] = true;
420 args.push(JSON.stringify(item[nv[0]]));
423 if (typeof(item['|' + nv[0]]) != 'undefined' && typeof(item['|' + nv[0]]) != 'object' ) {
424 citems[nv[0]] = true;
425 citems['|' + nv[0]] = true;
426 args.push(item['|' + nv[0]]);
429 args.push(nv.length > 1 ? nv[1] : 'null');
432 strbuilder(ipad + "this.el = new " + cls + "( "+ args.join(", ") + " );\n" );
435 strbuilder(ipad + "this.el = new " + cls + "();\n" );
438 //var meths = this.palete.getPropertiesFor(item['|xns'] + '.' + item.xtype, 'methods');
439 //print(JSON.stringify(meths,null,4));Seed.quit();
445 strbuilder(ipad + "_this = this;\n");
446 strbuilder(ipad + this.name + " = this;\n");
448 if (item.xvala_id !== false) {
449 strbuilder(ipad + "_this." + item.xvala_id + " = this;\n");
455 // initialize.. my vars..
456 strbuilder("\n" + ipad + "// my vars\n");
457 for (var k in item) {
461 var kk = k.substring(1);
463 var vv = kk.split(':');
464 if (v.length < 1 || vv[0] == "signal") {
467 strbuilder(ipad + "this" + vv[1] + " = " + v +";\n");
472 // what are the properties of this class???
473 strbuilder("\n" + ipad + "// set gobject values\n");
474 var props = this.palete.getPropertiesFor(item['|xns'] + '.' + item.xtype, 'props');
478 props.forEach(function(p) {
480 if (typeof(citems[p.name]) != 'undefined') {
484 if (typeof(item[p.name]) != 'undefined' && typeof(item[p.name]) != 'object' ) {
485 citems[p.name] = true;
488 strbuilder(ipad + "this.el." + p.name + " = " + JSON.stringify(item[p.name]) + ";\n");
491 if (typeof(item['|' + p.name]) != 'undefined' && typeof(item['|' + p.name]) != 'object' ) {
492 citems['|' + p.name] = true;
493 //if (p.ctor_only ) {
494 // strbuilder(ipad + "Object(" + p.name + " : " + item['|' + p.name] + ");\n");
496 strbuilder(ipad + "this.el." + p.name + " = " + item['|' + p.name] + ";\n");
505 // add all the child items..
506 if (typeof(item.items) != 'undefined') {
507 for(var i =0;i<item.items.length;i++) {
508 var ci = item.items[i];
509 var packing = ci.pack ? ci.pack.split(',') : [ 'add' ];
510 var pack = packing.shift();
511 strbuilder(ipad + "var child_" + i + " = new " + ci.xvala_xcls + "();\n" )
513 strbuilder(ipad + "this.el." + pack + " ( child_" + i + ".el " +
514 (packing.length ? ", " + packing.join(",") : "") + " );\n"
520 if (typeof(item['|init']) != 'undefined') {
523 var v = item['|init'].split(/\/*--/);
525 strbuilder("\n" + ipad + "// init method \n");
526 var vv = v[1].replace('*/', "");
527 //print(JSON.stringify(vv));Seed.quit();
528 vv = vv.replace(/^\n+/,'');
529 vv = vv.replace(/\n+$/,'');
530 vv = vv.replace(/\n/g,"\n" + ipad);
531 strbuilder(ipad + vv + "\n");
535 citems['|pack'] = true;
536 citems['|items'] = true;
537 citems['|init'] = true;
539 if (item.listeners) {
540 // print(JSON.stringify(item.listeners));Seed.quit();
542 strbuilder("\n" + ipad + "// listeners \n");
543 // add all the signal handlers..
544 for (var k in item.listeners) {
547 var v = item.listeners[k] ;
549 var vv = v.replace(/\n/g,"\n" + ipad);
553 strbuilder(ipad + "this.el." + k + ".connect( " + vv + " );\n");
562 strbuilder(pad + "}\n");
565 strbuilder("\n" + pad + "// userdefined functions \n");
567 // user defined functions...
569 for (var k in item) {
570 if (typeof(citems[k]) != 'undefined') {
571 strbuilder("\n" + pad + "// skip " + k + " - already used \n");
575 strbuilder("\n" + pad + "// skip " + k + " - not pipe \n");
578 // function in the format of {type} (args) { .... }
581 //print(JSON.stringify(vv));Seed.quit();
582 vv = vv.replace(/^\n+/,'');
583 vv = vv.replace(/\n+$/,'');
584 vv = vv.replace(/\n/g,"\n" + ipad);
586 var vva = k.split(':');
587 if (vva.length < 2) {
588 strbuilder("\n" + pad + "// skip " + k + " - no return type\n");
591 var rtype = vva.shift().substring(1);
593 var fname = vva.shift() || '???';
595 strbuilder(pad + "public " + rtype + " " + fname + body + "\n");
604 strbuilder(inpad + "}\n");
608 // next loop throug children..
609 if (typeof(item.items) != 'undefined') {
610 for(var i =0;i<item.items.length;i++) {
611 this.toValaItem(item.items[i], 1, strbuilder);
615 strbuilder(inpad + "}\n");