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;
20 //"name":"Edit Module Details",
22 //"btype":"FORM", // was to be components...
24 //"module":"Pman.Tab.BuilderTop2"
26 cfg.parent = cfg.parent || '';
27 if (!cfg.name || !cfg.fullname ) {
29 // name is in theory filename without .bjs (or .js eventually...)
30 cfg.name = cfg.path.split('/').pop().replace(/\.(bjs|js)$/, '');
32 cfg.fullname = (cfg.parent.length ? (cfg.parent + '.') : '' ) + cfg.name;
38 var jstr = JSON.parse(cfg.json);
39 this.items = [ jstr ];
40 //console.log(cfg.items.length);
41 delete cfg.json; // not needed!
45 var p = cfg.items && cfg.items.length && cfg.items[0].parent ? cfg.items[0].parent : false;
47 // ensure real data is set...
58 Gtk.superclass.constructor.call(this, cfg);
62 this.id = 'file-gtk-' + gid++;
64 // various loader methods..
70 setNSID : function(id)
73 this.items[0]['*class'] = id;
81 loadItems : function(cb)
85 if (this.items !== false) {
90 name: "ArgumentError",
91 message : "no callback for loadItems"
94 Seed.print("load: " + this.path);
100 var src = File.read(this.path);
102 var cfg = JSON.parse(src);
103 print("loaded data");
106 //_this.name = cfg.name; -- this should not happen - name should always match filename!!
107 _this.parent = cfg.parent;
108 _this.title = cfg.title;
109 _this.items = cfg.items || [];
119 * convert xtype for munged output..
122 mungeXtype : function(xtype, els)
124 els.push('xtype: '+ xtype);
127 toSource : function()
130 if (!this.items[0]) {
133 var data = JSON.parse(JSON.stringify(this.items[0]));
134 // we should base this on the objects in the tree really..
135 var i = [ 'Gtk', 'Gdk', 'Pango', 'GLib', 'Gio', 'GObject',
136 'GtkSource', 'WebKit', 'Vte' ]; //, 'GtkClutter' , 'Gdl'];
138 i.forEach(function(e) {
139 src += e+" = imports.gi." + e +";\n";
142 src += "console = imports.console;\n"; // path?!!?
143 src += "XObject = imports.XObject.XObject;\n"; // path?!!?
146 src += this.name + '=new XObject('+ this.mungeToString(data) + ");\n";
147 src += this.name + '.init();\n';
148 // register it in the cache
149 src += "XObject.cache['/" + this.name + "'] = " + this.name + ";\n";
157 Base.prototype.save.call(this);
165 * save as a javascript file.
166 * why is this not save...???
173 var fn = GLib.path_get_dirname(this.path) + '/' + this.name + '.js';
174 print("WRITE : " + fn);
175 File.write(fn, this.toSource());
183 var fn = GLib.path_get_dirname(this.path) + '/' + this.name + '.vala';
184 print("WRITE : " + fn);
185 File.write(fn, this.toVala());
189 valaCompileCmd : function()
192 var fn = '/tmp/' + this.name + '.vala';
193 print("WRITE : " + fn);
194 File.write(fn, this.toVala(true));
201 "--pkg" , "gtk+-3.0",
202 "--pkg", "libnotify",
203 "--pkg", "gtksourceview-3.0",
204 "--pkg", "libwnck-3.0",
205 fn , "-o", "/tmp/" + this.name];
214 getTree : function( o ) {
220 getHelpUrl : function(cls)
222 return 'http://devel.akbkhome.com/seed/' + cls + '.html';
227 toVala: function(testcompile)
230 testcompile = testcompile || false;
233 //print(JSON.stringify(this.items[0],null,4));
234 //print(JSON.stringify(this.items[0],null,4));Seed.quit();
236 var item= XObject.xclone(this.items[0]);
238 print(JSON.stringify(item,null,4));
240 this.palete = new imports.Palete.Gtk.Gtk({});
243 this.toValaName(item);
244 // print(JSON.stringify(item,null,4));Seed.quit();
246 ret += "/* -- to compile\n";
247 ret += "valac --pkg gio-2.0 --pkg posix --pkg gtk+-3.0 --pkg libnotify --pkg gtksourceview-3.0 --pkg libwnck-3.0 \\\n";
248 //ret += " " + item.xvala_id + ".vala -o /tmp/" + item.xvala_id +"\n";
249 ret += " /tmp/test.vala -o /tmp/" + item.xvala_id +"\n";
253 ret += "/* -- to test class\n";
256 ret += "static int main (string[] args) {\n";
257 ret += " Gtk.init (ref args);\n";
258 ret += " new " + item.xvala_xcls +"();\n";
259 ret += " " + item.xvala_id +".show_all();\n";
260 ret += " Gtk.main ();\n";
261 ret += " return 0;\n";
267 // print(JSON.stringify(item,null,4));
268 this.toValaItem(item,0, function(s) {
276 toValaNS : function(item)
278 var ns = item['|xns'] ;
279 if (ns == 'GtkSource') {
286 toValaName : function(item) {
288 var cls = this.toValaNS(item) + item.xtype;
289 var id = item.id ? item.id : (item.xtype + this.vcnt);
290 var props = this.palete.getPropertiesFor(cls, 'props');
294 item.xvala_cls = cls;
295 item.xvala_xcls = 'Xcls_' + id;
296 item.xvala_id = item.id ? item.id : false;
297 this.vitems.push(item);
299 if (typeof(item.items) == 'undefined') {
302 for(var i =0;i<item.items.length;i++) {
303 this.toValaName(item.items[i]);
309 toValaItem : function(item, depth, strbuilder)
311 // print(JSON.stringify(item,null,4));
313 var inpad = new Array( depth +1 ).join(" ");
315 var pad = new Array( depth +2 ).join(" ");
316 var ipad = new Array( depth +3 ).join(" ");
318 var cls = item.xvala_cls;
320 var xcls = item.xvala_xcls;
325 strbuilder(inpad + "public static " + xcls + " " + item.id + ";\n\n");
326 strbuilder(inpad + "private static " + xcls + " _this;\n\n");
332 strbuilder(inpad + "public class " + xcls + " : " + cls + "\n" + inpad + "{\n");
336 //public bool paused = false;
337 //public static StatusIconA statusicon;
339 //strbuilder(pad + "public static " + xcls + " _this;\n");
340 for(var i=1;i < this.vitems.length; i++) {
341 if (this.vitems[i].xvala_id !== false) {
342 strbuilder(pad + "public " + this.vitems[i].xvala_xcls + " " + this.vitems[i].xvala_id + ";\n");
348 strbuilder("\n" + ipad + "// my vars\n");
351 for (var k in item) {
356 var kk = k.substring(1);
358 var vv = v.split(':');
359 strbuilder(pad + "public " + vv[0] + " " + kk + ";\n");
366 strbuilder("\n" + ipad + "// ctor \n");
367 strbuilder(pad + "public " + xcls + "()\n" + pad + "{\n");
371 strbuilder(ipad + "_this = this;\n");
372 strbuilder(ipad + item.id + " = this;\n");
374 if (item.xvala_id !== false) {
375 strbuilder(ipad + "_this." + item.xvala_id + " = this;\n");
381 // initialize.. my vars..
382 strbuilder("\n" + ipad + "// my vars\n");
383 for (var k in item) {
387 var kk = k.substring(1);
389 var vv = v.split(':');
393 strbuilder(ipad + "this" + k + " = " + vv[1] +";\n");
398 // what are the properties of this class???
399 strbuilder("\n" + ipad + "// set gobject values\n");
400 var props = this.palete.getPropertiesFor(item['|xns'] + '.' + item.xtype, 'props');
404 props.forEach(function(p) {
408 if (typeof(item[p.name]) != 'undefined' && typeof(item[p.name]) != 'object' ) {
409 citems[p.name] = true;
412 strbuilder(ipad + "this." + p.name + " = " + JSON.stringify(item[p.name]) + ";\n");
415 if (typeof(item['|' + p.name]) != 'undefined' && typeof(item['|' + p.name]) != 'object' ) {
416 citems['|' + p.name] = true;
418 strbuilder(ipad + "Object(" + p.name + " : " + item['|' + p.name] + ");\n");
420 strbuilder(ipad + "this." + p.name + " = " + item['|' + p.name] + ";\n");
429 // add all the child items..
430 if (typeof(item.items) != 'undefined') {
431 for(var i =0;i<item.items.length;i++) {
432 var ci = item.items[i];
433 var packing = ci.pack ? ci.pack.split(',') : [ 'add' ];
434 var pack = packing.shift();
435 strbuilder(ipad + "this." + pack + " ( new " + ci.xvala_xcls + "()" +
436 (packing.length ? ", " + packing.join(",") : "") + " );\n"
442 if (typeof(item['|init']) != 'undefined') {
445 var v = item['|init'].split(/\/*--/);
447 strbuilder("\n" + ipad + "// init method \n");
448 var vv = v[1].replace('*/', "");
449 //print(JSON.stringify(vv));Seed.quit();
450 vv = vv.replace(/^\n+/,'');
451 vv = vv.replace(/\n+$/,'');
452 vv = vv.replace(/\n/g,"\n" + ipad);
453 strbuilder(ipad + vv + "\n");
457 citems['|pack'] = true;
458 citems['|items'] = true;
459 citems['|init'] = true;
461 if (item.listeners) {
462 // print(JSON.stringify(item.listeners));Seed.quit();
464 strbuilder("\n" + ipad + "// listeners \n");
465 // add all the signal handlers..
466 for (var k in item.listeners) {
469 var v = item.listeners[k].split(/\/*--/);
473 var vv = v[1].replace('*/', "");
474 //print(JSON.stringify(vv));Seed.quit();
475 vv = vv.replace(/^\n+/,'');
476 vv = vv.replace(/\n+$/,'');
477 vv = vv.replace(/\n/g,"\n" + ipad);
478 strbuilder(ipad + "this." + k + ".connect( " + vv + " );\n");
487 strbuilder(pad + "}\n");
490 strbuilder("\n" + pad + "// userdefined functions \n");
492 // user defined functions...
494 for (var k in item) {
495 if (typeof(citems[k]) != 'undefined') {
496 //strbuilder("\n" + pad + "// skip " + k + " - already used \n");
500 // strbuilder("\n" + pad + "// skip " + k + " - not pipe \n");
503 // function in the format of {type} (args) { .... }
505 var v = item[k].split(/\/*--/);
509 var vv = v[1].replace('*/', "");
510 //print(JSON.stringify(vv));Seed.quit();
511 vv = vv.replace(/^\n+/,'');
512 vv = vv.replace(/\n+$/,'');
513 vv = vv.replace(/\n/g,"\n" + ipad);
516 var rtype = vva.shift();
517 var body = vva.join(' ');
520 strbuilder(pad + "public " + rtype + " " + k.substring(1) +body + "\n");
529 strbuilder(inpad + "}\n");
533 // next loop throug children..
534 if (typeof(item.items) != 'undefined') {
535 for(var i =0;i<item.items.length;i++) {
536 this.toValaItem(item.items[i], 1, strbuilder);
540 strbuilder(inpad + "}\n");