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" ]
26 //"name":"Edit Module Details",
28 //"btype":"FORM", // was to be components...
30 //"module":"Pman.Tab.BuilderTop2"
32 cfg.parent = cfg.parent || '';
33 if (!cfg.name || !cfg.fullname ) {
35 // name is in theory filename without .bjs (or .js eventually...)
36 cfg.name = cfg.path.split('/').pop().replace(/\.(bjs|js)$/, '');
38 cfg.fullname = (cfg.parent.length ? (cfg.parent + '.') : '' ) + cfg.name;
44 var jstr = JSON.parse(cfg.json);
45 this.items = [ jstr ];
46 //console.log(cfg.items.length);
47 delete cfg.json; // not needed!
51 var p = cfg.items && cfg.items.length && cfg.items[0].parent ? cfg.items[0].parent : false;
53 // ensure real data is set...
64 Gtk.superclass.constructor.call(this, cfg);
68 this.id = 'file-gtk-' + gid++;
70 // various loader methods..
76 setNSID : function(id)
79 this.items[0]['*class'] = id;
87 loadItems : function(cb)
91 if (this.items !== false) {
96 name: "ArgumentError",
97 message : "no callback for loadItems"
100 Seed.print("load: " + this.path);
106 var src = File.read(this.path);
108 var cfg = JSON.parse(src);
109 print("loaded data");
112 //_this.name = cfg.name; -- this should not happen - name should always match filename!!
113 _this.parent = cfg.parent;
114 _this.title = cfg.title;
115 _this.items = cfg.items || [];
125 * convert xtype for munged output..
128 mungeXtype : function(xtype, els)
130 els.push('xtype: '+ xtype);
133 toSource : function()
136 if (!this.items[0]) {
139 var data = JSON.parse(JSON.stringify(this.items[0]));
140 // we should base this on the objects in the tree really..
141 var i = [ 'Gtk', 'Gdk', 'Pango', 'GLib', 'Gio', 'GObject',
142 'GtkSource', 'WebKit', 'Vte' ]; //, 'GtkClutter' , 'Gdl'];
144 i.forEach(function(e) {
145 src += e+" = imports.gi." + e +";\n";
148 src += "console = imports.console;\n"; // path?!!?
149 src += "XObject = imports.XObject.XObject;\n"; // path?!!?
152 src += this.name + '=new XObject('+ this.mungeToString(data) + ");\n";
153 src += this.name + '.init();\n';
154 // register it in the cache
155 src += "XObject.cache['/" + this.name + "'] = " + this.name + ";\n";
163 Base.prototype.save.call(this);
171 * save as a javascript file.
172 * why is this not save...???
179 var fn = GLib.path_get_dirname(this.path) + '/' + this.name + '.js';
180 print("WRITE : " + fn);
181 File.write(fn, this.toSource());
189 var fn = GLib.path_get_dirname(this.path) + '/' + this.name + '.vala';
190 print("WRITE : " + fn);
191 File.write(fn, this.toVala());
195 valaCompileCmd : function()
198 var fn = '/tmp/' + this.name + '.vala';
199 print("WRITE : " + fn);
200 File.write(fn, this.toVala(true));
207 "--pkg" , "gtk+-3.0",
208 "--pkg", "libnotify",
209 "--pkg", "gtksourceview-3.0",
210 "--pkg", "libwnck-3.0",
211 fn , "-o", "/tmp/" + this.name];
220 getTree : function( o ) {
226 getHelpUrl : function(cls)
228 return 'http://devel.akbkhome.com/seed/' + cls + '.html';
233 toVala: function(testcompile)
236 testcompile = testcompile || false;
239 //print(JSON.stringify(this.items[0],null,4));
240 //print(JSON.stringify(this.items[0],null,4));Seed.quit();
242 var item= XObject.xclone(this.items[0]);
244 print(JSON.stringify(item,null,4));
246 this.palete = new imports.Palete.Gtk.Gtk({});
249 this.toValaName(item);
250 // print(JSON.stringify(item,null,4));Seed.quit();
252 ret += "/* -- to compile\n";
253 ret += "valac --pkg gio-2.0 --pkg posix --pkg gtk+-3.0 --pkg libnotify --pkg gtksourceview-3.0 --pkg libwnck-3.0 \\\n";
254 //ret += " " + item.xvala_id + ".vala -o /tmp/" + item.xvala_id +"\n";
255 ret += " /tmp/" + this.name + ".vala -o /tmp/" + this.name +"\n";
259 ret += "/* -- to test class\n";
262 ret += "static int main (string[] args) {\n";
263 ret += " Gtk.init (ref args);\n";
264 ret += " new " + item.xvala_xcls +"();\n";
265 ret += " " + this.name +".show_all();\n";
266 ret += " Gtk.main ();\n";
267 ret += " return 0;\n";
273 // print(JSON.stringify(item,null,4));
274 this.toValaItem(item,0, function(s) {
282 toValaNS : function(item)
284 var ns = item['|xns'] ;
285 if (ns == 'GtkSource') {
292 toValaName : function(item) {
294 var cls = this.toValaNS(item) + item.xtype;
295 var id = item.id ? item.id : (item.xtype + this.vcnt);
296 var props = this.palete.getPropertiesFor(cls, 'props');
300 item.xvala_cls = cls;
301 item.xvala_xcls = 'Xcls_' + id;
302 item.xvala_id = item.id ? item.id : false;
303 this.vitems.push(item);
305 if (typeof(item.items) == 'undefined') {
308 for(var i =0;i<item.items.length;i++) {
309 this.toValaName(item.items[i]);
315 toValaItem : function(item, depth, strbuilder)
317 // print(JSON.stringify(item,null,4));
319 var inpad = new Array( depth +1 ).join(" ");
321 var pad = new Array( depth +2 ).join(" ");
322 var ipad = new Array( depth +3 ).join(" ");
324 var cls = item.xvala_cls;
326 var xcls = item.xvala_xcls;
332 strbuilder(inpad + "public static " + xcls + " " + this.name + ";\n\n");
333 strbuilder(inpad + "private static " + xcls + " _this;\n\n");
339 // class xxx { WrappedGtk el; }
340 strbuilder(inpad + "public class " + xcls + "\n" + inpad + "{\n");
341 strbuilder(pad + "public " + cls + " el;\n");
345 //public bool paused = false;
346 //public static StatusIconA statusicon;
348 //strbuilder(pad + "public static " + xcls + " _this;\n");
349 for(var i=1;i < this.vitems.length; i++) {
350 if (this.vitems[i].xvala_id !== false) {
351 strbuilder(pad + "public " + this.vitems[i].xvala_xcls + " " + this.vitems[i].xvala_id + ";\n");
357 strbuilder("\n" + ipad + "// my vars\n");
360 for (var k in item) {
369 var kk = k.substring(1);
371 var vv = v.split(':');
372 strbuilder(pad + "public " + vv[0] + " " + kk + ";\n");
379 strbuilder("\n" + ipad + "// ctor \n");
380 strbuilder(pad + "public " + xcls + "()\n" + pad + "{\n");
383 // this may need to look up properties to fill in the arguments..
384 // introspection does not workk..... - as things like gtkmessagedialog
387 if (typeof(ctors[cls]) !== 'undefined') {
389 for(var i =0;i< ctors[cls].length;i++) {
391 var nv = ctors[cls][i].split(':');
393 if (typeof(item[nv[0]]) != 'undefined' && typeof(item[nv[0]]) != 'object' ) {
394 citems[nv[0]] = true;
395 args.push(JSON.stringify(item[nv[0]]));
398 if (typeof(item['|' + nv[0]]) != 'undefined' && typeof(item['|' + nv[0]]) != 'object' ) {
399 citems[nv[0]] = true;
400 args.push(item['|' + nv[0]]);
403 args.push(nv.length > 1 ? nv[1] : 'null');
406 strbuilder(ipad + "this.el = new " + cls + "( "+ args.join(", ") + " );\n" );
409 strbuilder(ipad + "this.el = new " + cls + "();\n" );
412 //var meths = this.palete.getPropertiesFor(item['|xns'] + '.' + item.xtype, 'methods');
413 //print(JSON.stringify(meths,null,4));Seed.quit();
419 strbuilder(ipad + "_this = this;\n");
420 strbuilder(ipad + this.name + " = this;\n");
422 if (item.xvala_id !== false) {
423 strbuilder(ipad + "_this." + item.xvala_id + " = this;\n");
429 // initialize.. my vars..
430 strbuilder("\n" + ipad + "// my vars\n");
431 for (var k in item) {
435 var kk = k.substring(1);
437 var vv = v.split(':');
441 strbuilder(ipad + "this." + k + " = " + vv[1] +";\n");
446 // what are the properties of this class???
447 strbuilder("\n" + ipad + "// set gobject values\n");
448 var props = this.palete.getPropertiesFor(item['|xns'] + '.' + item.xtype, 'props');
452 props.forEach(function(p) {
456 if (typeof(item[p.name]) != 'undefined' && typeof(item[p.name]) != 'object' ) {
457 citems[p.name] = true;
460 strbuilder(ipad + "this.el." + p.name + " = " + JSON.stringify(item[p.name]) + ";\n");
463 if (typeof(item['|' + p.name]) != 'undefined' && typeof(item['|' + p.name]) != 'object' ) {
464 citems['|' + p.name] = true;
465 //if (p.ctor_only ) {
466 // strbuilder(ipad + "Object(" + p.name + " : " + item['|' + p.name] + ");\n");
468 strbuilder(ipad + "this.el." + p.name + " = " + item['|' + p.name] + ";\n");
477 // add all the child items..
478 if (typeof(item.items) != 'undefined') {
479 for(var i =0;i<item.items.length;i++) {
480 var ci = item.items[i];
481 var packing = ci.pack ? ci.pack.split(',') : [ 'add' ];
482 var pack = packing.shift();
483 strbuilder(ipad + "var child_" + i + " = new " + ci.xvala_xcls + "();\n" )
485 strbuilder(ipad + "this.el." + pack + " ( child_" + i + ".el " +
486 (packing.length ? ", " + packing.join(",") : "") + " );\n"
492 if (typeof(item['|init']) != 'undefined') {
495 var v = item['|init'].split(/\/*--/);
497 strbuilder("\n" + ipad + "// init method \n");
498 var vv = v[1].replace('*/', "");
499 //print(JSON.stringify(vv));Seed.quit();
500 vv = vv.replace(/^\n+/,'');
501 vv = vv.replace(/\n+$/,'');
502 vv = vv.replace(/\n/g,"\n" + ipad);
503 strbuilder(ipad + vv + "\n");
507 citems['|pack'] = true;
508 citems['|items'] = true;
509 citems['|init'] = true;
511 if (item.listeners) {
512 // print(JSON.stringify(item.listeners));Seed.quit();
514 strbuilder("\n" + ipad + "// listeners \n");
515 // add all the signal handlers..
516 for (var k in item.listeners) {
519 var v = item.listeners[k].split(/\/*--/);
523 var vv = v[1].replace('*/', "");
524 //print(JSON.stringify(vv));Seed.quit();
525 vv = vv.replace(/^\n+/,'');
526 vv = vv.replace(/\n+$/,'');
527 vv = vv.replace(/\n/g,"\n" + ipad);
528 strbuilder(ipad + "this.el." + k + ".connect( " + vv + " );\n");
537 strbuilder(pad + "}\n");
540 strbuilder("\n" + pad + "// userdefined functions \n");
542 // user defined functions...
544 for (var k in item) {
545 if (typeof(citems[k]) != 'undefined') {
546 strbuilder("\n" + pad + "// skip " + k + " - already used \n");
550 strbuilder("\n" + pad + "// skip " + k + " - not pipe \n");
553 // function in the format of {type} (args) { .... }
555 var v = item[k].split(/\/*--/);
557 strbuilder("\n" + pad + "// skip " + k + " - could not find seperator\n");
560 var vv = v[1].replace('*/', "");
561 //print(JSON.stringify(vv));Seed.quit();
562 vv = vv.replace(/^\n+/,'');
563 vv = vv.replace(/\n+$/,'');
564 vv = vv.replace(/\n/g,"\n" + ipad);
567 var rtype = vva.shift();
568 var body = vva.join(' ');
571 strbuilder(pad + "public " + rtype + " " + k.substring(1) +body + "\n");
580 strbuilder(inpad + "}\n");
584 // next loop throug children..
585 if (typeof(item.items) != 'undefined') {
586 for(var i =0;i<item.items.length;i++) {
587 this.toValaItem(item.items[i], 1, strbuilder);
591 strbuilder(inpad + "}\n");