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", "flags", "type", "buttons", "message_format" ]
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(item['.ctor']) !== 'undefined') {
388 strbuilder(ipad + "this.el = new " + cls + "("+ item['.ctor'] + ");\n" );
391 strbuilder(ipad + "this.el = new " + cls + "();\n" );
394 //var meths = this.palete.getPropertiesFor(item['|xns'] + '.' + item.xtype, 'methods');
395 //print(JSON.stringify(meths,null,4));Seed.quit();
401 strbuilder(ipad + "_this = this;\n");
402 strbuilder(ipad + this.name + " = this;\n");
404 if (item.xvala_id !== false) {
405 strbuilder(ipad + "_this." + item.xvala_id + " = this;\n");
411 // initialize.. my vars..
412 strbuilder("\n" + ipad + "// my vars\n");
413 for (var k in item) {
417 var kk = k.substring(1);
419 var vv = v.split(':');
423 strbuilder(ipad + "this." + k + " = " + vv[1] +";\n");
428 // what are the properties of this class???
429 strbuilder("\n" + ipad + "// set gobject values\n");
430 var props = this.palete.getPropertiesFor(item['|xns'] + '.' + item.xtype, 'props');
434 props.forEach(function(p) {
438 if (typeof(item[p.name]) != 'undefined' && typeof(item[p.name]) != 'object' ) {
439 citems[p.name] = true;
442 strbuilder(ipad + "this.el." + p.name + " = " + JSON.stringify(item[p.name]) + ";\n");
445 if (typeof(item['|' + p.name]) != 'undefined' && typeof(item['|' + p.name]) != 'object' ) {
446 citems['|' + p.name] = true;
447 //if (p.ctor_only ) {
448 // strbuilder(ipad + "Object(" + p.name + " : " + item['|' + p.name] + ");\n");
450 strbuilder(ipad + "this.el." + p.name + " = " + item['|' + p.name] + ";\n");
459 // add all the child items..
460 if (typeof(item.items) != 'undefined') {
461 for(var i =0;i<item.items.length;i++) {
462 var ci = item.items[i];
463 var packing = ci.pack ? ci.pack.split(',') : [ 'add' ];
464 var pack = packing.shift();
465 strbuilder(ipad + "var child_" + i + " = new " + ci.xvala_xcls + "();\n" )
467 strbuilder(ipad + "this.el." + pack + " ( child_" + i + ".el " +
468 (packing.length ? ", " + packing.join(",") : "") + " );\n"
474 if (typeof(item['|init']) != 'undefined') {
477 var v = item['|init'].split(/\/*--/);
479 strbuilder("\n" + ipad + "// init method \n");
480 var vv = v[1].replace('*/', "");
481 //print(JSON.stringify(vv));Seed.quit();
482 vv = vv.replace(/^\n+/,'');
483 vv = vv.replace(/\n+$/,'');
484 vv = vv.replace(/\n/g,"\n" + ipad);
485 strbuilder(ipad + vv + "\n");
489 citems['|pack'] = true;
490 citems['|items'] = true;
491 citems['|init'] = true;
493 if (item.listeners) {
494 // print(JSON.stringify(item.listeners));Seed.quit();
496 strbuilder("\n" + ipad + "// listeners \n");
497 // add all the signal handlers..
498 for (var k in item.listeners) {
501 var v = item.listeners[k].split(/\/*--/);
505 var vv = v[1].replace('*/', "");
506 //print(JSON.stringify(vv));Seed.quit();
507 vv = vv.replace(/^\n+/,'');
508 vv = vv.replace(/\n+$/,'');
509 vv = vv.replace(/\n/g,"\n" + ipad);
510 strbuilder(ipad + "this.el." + k + ".connect( " + vv + " );\n");
519 strbuilder(pad + "}\n");
522 strbuilder("\n" + pad + "// userdefined functions \n");
524 // user defined functions...
526 for (var k in item) {
527 if (typeof(citems[k]) != 'undefined') {
528 strbuilder("\n" + pad + "// skip " + k + " - already used \n");
532 strbuilder("\n" + pad + "// skip " + k + " - not pipe \n");
535 // function in the format of {type} (args) { .... }
537 var v = item[k].split(/\/*--/);
539 strbuilder("\n" + pad + "// skip " + k + " - could not find seperator\n");
542 var vv = v[1].replace('*/', "");
543 //print(JSON.stringify(vv));Seed.quit();
544 vv = vv.replace(/^\n+/,'');
545 vv = vv.replace(/\n+$/,'');
546 vv = vv.replace(/\n/g,"\n" + ipad);
549 var rtype = vva.shift();
550 var body = vva.join(' ');
553 strbuilder(pad + "public " + rtype + " " + k.substring(1) +body + "\n");
562 strbuilder(inpad + "}\n");
566 // next loop throug children..
567 if (typeof(item.items) != 'undefined') {
568 for(var i =0;i<item.items.length;i++) {
569 this.toValaItem(item.items[i], 1, strbuilder);
573 strbuilder(inpad + "}\n");