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", "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(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[v[0]]) != 'object' ) {
394 args.push(JSON.stringify(item[v[0]]));
397 if (typeof(item['|' + v[0]]) != 'undefined' && typeof(item['|' + v[0]]) != 'object' ) {
398 args.push(item['|' + v[0]]);
401 args.push(nv.length > 1 ? nv[1] : 'null');
404 strbuilder(ipad + "this.el = new " + cls + "( "+ args.join(", ") + " );\n" );
407 strbuilder(ipad + "this.el = new " + cls + "();\n" );
410 //var meths = this.palete.getPropertiesFor(item['|xns'] + '.' + item.xtype, 'methods');
411 //print(JSON.stringify(meths,null,4));Seed.quit();
417 strbuilder(ipad + "_this = this;\n");
418 strbuilder(ipad + this.name + " = this;\n");
420 if (item.xvala_id !== false) {
421 strbuilder(ipad + "_this." + item.xvala_id + " = this;\n");
427 // initialize.. my vars..
428 strbuilder("\n" + ipad + "// my vars\n");
429 for (var k in item) {
433 var kk = k.substring(1);
435 var vv = v.split(':');
439 strbuilder(ipad + "this." + k + " = " + vv[1] +";\n");
444 // what are the properties of this class???
445 strbuilder("\n" + ipad + "// set gobject values\n");
446 var props = this.palete.getPropertiesFor(item['|xns'] + '.' + item.xtype, 'props');
450 props.forEach(function(p) {
454 if (typeof(item[p.name]) != 'undefined' && typeof(item[p.name]) != 'object' ) {
455 citems[p.name] = true;
458 strbuilder(ipad + "this.el." + p.name + " = " + JSON.stringify(item[p.name]) + ";\n");
461 if (typeof(item['|' + p.name]) != 'undefined' && typeof(item['|' + p.name]) != 'object' ) {
462 citems['|' + p.name] = true;
463 //if (p.ctor_only ) {
464 // strbuilder(ipad + "Object(" + p.name + " : " + item['|' + p.name] + ");\n");
466 strbuilder(ipad + "this.el." + p.name + " = " + item['|' + p.name] + ";\n");
475 // add all the child items..
476 if (typeof(item.items) != 'undefined') {
477 for(var i =0;i<item.items.length;i++) {
478 var ci = item.items[i];
479 var packing = ci.pack ? ci.pack.split(',') : [ 'add' ];
480 var pack = packing.shift();
481 strbuilder(ipad + "var child_" + i + " = new " + ci.xvala_xcls + "();\n" )
483 strbuilder(ipad + "this.el." + pack + " ( child_" + i + ".el " +
484 (packing.length ? ", " + packing.join(",") : "") + " );\n"
490 if (typeof(item['|init']) != 'undefined') {
493 var v = item['|init'].split(/\/*--/);
495 strbuilder("\n" + ipad + "// init method \n");
496 var vv = v[1].replace('*/', "");
497 //print(JSON.stringify(vv));Seed.quit();
498 vv = vv.replace(/^\n+/,'');
499 vv = vv.replace(/\n+$/,'');
500 vv = vv.replace(/\n/g,"\n" + ipad);
501 strbuilder(ipad + vv + "\n");
505 citems['|pack'] = true;
506 citems['|items'] = true;
507 citems['|init'] = true;
509 if (item.listeners) {
510 // print(JSON.stringify(item.listeners));Seed.quit();
512 strbuilder("\n" + ipad + "// listeners \n");
513 // add all the signal handlers..
514 for (var k in item.listeners) {
517 var v = item.listeners[k].split(/\/*--/);
521 var vv = v[1].replace('*/', "");
522 //print(JSON.stringify(vv));Seed.quit();
523 vv = vv.replace(/^\n+/,'');
524 vv = vv.replace(/\n+$/,'');
525 vv = vv.replace(/\n/g,"\n" + ipad);
526 strbuilder(ipad + "this.el." + k + ".connect( " + vv + " );\n");
535 strbuilder(pad + "}\n");
538 strbuilder("\n" + pad + "// userdefined functions \n");
540 // user defined functions...
542 for (var k in item) {
543 if (typeof(citems[k]) != 'undefined') {
544 strbuilder("\n" + pad + "// skip " + k + " - already used \n");
548 strbuilder("\n" + pad + "// skip " + k + " - not pipe \n");
551 // function in the format of {type} (args) { .... }
553 var v = item[k].split(/\/*--/);
555 strbuilder("\n" + pad + "// skip " + k + " - could not find seperator\n");
558 var vv = v[1].replace('*/', "");
559 //print(JSON.stringify(vv));Seed.quit();
560 vv = vv.replace(/^\n+/,'');
561 vv = vv.replace(/\n+$/,'');
562 vv = vv.replace(/\n/g,"\n" + ipad);
565 var rtype = vva.shift();
566 var body = vva.join(' ');
569 strbuilder(pad + "public " + rtype + " " + k.substring(1) +body + "\n");
578 strbuilder(inpad + "}\n");
582 // next loop throug children..
583 if (typeof(item.items) != 'undefined') {
584 for(var i =0;i<item.items.length;i++) {
585 this.toValaItem(item.items[i], 1, strbuilder);
589 strbuilder(inpad + "}\n");