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");
371 for (var k in item) {
380 var kk = k.substring(1);
382 var vv = v.split(':');
383 strbuilder(pad + "public " + vv[0] + " " + kk + ";\n");
390 strbuilder("\n" + ipad + "// ctor \n");
391 strbuilder(pad + "public " + xcls + "()\n" + pad + "{\n");
394 // this may need to look up properties to fill in the arguments..
395 // introspection does not workk..... - as things like gtkmessagedialog
398 if (typeof(ctors[cls]) !== 'undefined') {
400 for(var i =0;i< ctors[cls].length;i++) {
402 var nv = ctors[cls][i].split(':');
404 if (typeof(item[nv[0]]) != 'undefined' && typeof(item[nv[0]]) != 'object' ) {
405 citems[nv[0]] = true;
406 args.push(JSON.stringify(item[nv[0]]));
409 if (typeof(item['|' + nv[0]]) != 'undefined' && typeof(item['|' + nv[0]]) != 'object' ) {
410 citems[nv[0]] = true;
411 citems['|' + nv[0]] = true;
412 args.push(item['|' + nv[0]]);
415 args.push(nv.length > 1 ? nv[1] : 'null');
418 strbuilder(ipad + "this.el = new " + cls + "( "+ args.join(", ") + " );\n" );
421 strbuilder(ipad + "this.el = new " + cls + "();\n" );
424 //var meths = this.palete.getPropertiesFor(item['|xns'] + '.' + item.xtype, 'methods');
425 //print(JSON.stringify(meths,null,4));Seed.quit();
431 strbuilder(ipad + "_this = this;\n");
432 strbuilder(ipad + this.name + " = this;\n");
434 if (item.xvala_id !== false) {
435 strbuilder(ipad + "_this." + item.xvala_id + " = this;\n");
441 // initialize.. my vars..
442 strbuilder("\n" + ipad + "// my vars\n");
443 for (var k in item) {
447 var kk = k.substring(1);
449 var vv = v.split(':');
453 strbuilder(ipad + "this" + k + " = " + vv[1] +";\n");
458 // what are the properties of this class???
459 strbuilder("\n" + ipad + "// set gobject values\n");
460 var props = this.palete.getPropertiesFor(item['|xns'] + '.' + item.xtype, 'props');
464 props.forEach(function(p) {
466 if (typeof(citems[p.name]) != 'undefined') {
470 if (typeof(item[p.name]) != 'undefined' && typeof(item[p.name]) != 'object' ) {
471 citems[p.name] = true;
474 strbuilder(ipad + "this.el." + p.name + " = " + JSON.stringify(item[p.name]) + ";\n");
477 if (typeof(item['|' + p.name]) != 'undefined' && typeof(item['|' + p.name]) != 'object' ) {
478 citems['|' + p.name] = true;
479 //if (p.ctor_only ) {
480 // strbuilder(ipad + "Object(" + p.name + " : " + item['|' + p.name] + ");\n");
482 strbuilder(ipad + "this.el." + p.name + " = " + item['|' + p.name] + ";\n");
491 // add all the child items..
492 if (typeof(item.items) != 'undefined') {
493 for(var i =0;i<item.items.length;i++) {
494 var ci = item.items[i];
495 var packing = ci.pack ? ci.pack.split(',') : [ 'add' ];
496 var pack = packing.shift();
497 strbuilder(ipad + "var child_" + i + " = new " + ci.xvala_xcls + "();\n" )
499 strbuilder(ipad + "this.el." + pack + " ( child_" + i + ".el " +
500 (packing.length ? ", " + packing.join(",") : "") + " );\n"
506 if (typeof(item['|init']) != 'undefined') {
509 var v = item['|init'].split(/\/*--/);
511 strbuilder("\n" + ipad + "// init method \n");
512 var vv = v[1].replace('*/', "");
513 //print(JSON.stringify(vv));Seed.quit();
514 vv = vv.replace(/^\n+/,'');
515 vv = vv.replace(/\n+$/,'');
516 vv = vv.replace(/\n/g,"\n" + ipad);
517 strbuilder(ipad + vv + "\n");
521 citems['|pack'] = true;
522 citems['|items'] = true;
523 citems['|init'] = true;
525 if (item.listeners) {
526 // print(JSON.stringify(item.listeners));Seed.quit();
528 strbuilder("\n" + ipad + "// listeners \n");
529 // add all the signal handlers..
530 for (var k in item.listeners) {
533 var v = item.listeners[k].split(/\/*--/);
535 var vv = v[0].replace(/^function/, '');
536 vv = vv.replace(/\) \{/, ') => {');
537 vv = vv.replace(/^\n+/,'');
538 vv = vv.replace(/\n+$/,'');
539 vv = vv.replace(/\n/g,"\n" + ipad);
547 var vv = v[1].replace('*/', "");
548 //print(JSON.stringify(vv));Seed.quit();
549 vv = vv.replace(/^\n+/,'');
550 vv = vv.replace(/\n+$/,'');
551 vv = vv.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) { .... }
580 var v = item[k].split(/\/*--/);
582 strbuilder("\n" + pad + "// skip " + k + " - could not find seperator\n");
585 var vv = v[1].replace('*/', "");
586 //print(JSON.stringify(vv));Seed.quit();
587 vv = vv.replace(/^\n+/,'');
588 vv = vv.replace(/\n+$/,'');
589 vv = vv.replace(/\n/g,"\n" + ipad);
592 var rtype = vva.shift();
593 var body = vva.join(' ');
596 strbuilder(pad + "public " + rtype + " " + k.substring(1) +body + "\n");
605 strbuilder(inpad + "}\n");
609 // next loop throug children..
610 if (typeof(item.items) != 'undefined') {
611 for(var i =0;i<item.items.length;i++) {
612 this.toValaItem(item.items[i], 1, strbuilder);
616 strbuilder(inpad + "}\n");