Builder/Provider/File/Gtk.js
[app.Builder.js] / Builder / Provider / File / Gtk.js
index 9cb324b..b77ca10 100755 (executable)
@@ -1,6 +1,7 @@
 //<Script type="text/javascript">
  
 Gio = imports.gi.Gio;
+GLib = imports.gi.GLib;
 console = imports.console;
 XObject = imports.XObject.XObject;
 File = imports.File.File;
@@ -57,6 +58,7 @@ Gtk = XObject.define(
         
         // super?!?!
         this.id = 'file-gtk-' + gid++;
+        //console.dump(this);
         // various loader methods..
        
     },
@@ -81,8 +83,11 @@ Gtk = XObject.define(
             if (this.items !== false) {
                 return false;
             }
-            if (!cb) {
-                throw "no callback for loadItems";
+            if (!cb) {  
+                throw {
+                    name: "ArgumentError", 
+                    message : "no callback for loadItems"
+                };
             }
             Seed.print("load: " + this.path);
             
@@ -94,15 +99,15 @@ Gtk = XObject.define(
             
             var cfg = JSON.parse(src);
             print("loaded data");
-            console.dump(cfg);
+            //console.dump(cfg);
             
-            _this.name = cfg.name;
+            //_this.name = cfg.name; -- this should not happen - name should always match filename!!
             _this.parent =  cfg.parent;
             _this.title =  cfg.title;
             _this.items = cfg.items || []; 
-            if (cb) {
+           
                 cb();
-               }
+             
             
                 
                 // update to new JSDOC api!?
@@ -142,6 +147,16 @@ Gtk = XObject.define(
             
             
         },
+        /**
+         * convert xtype for munged output..
+         * 
+         */
+        mungeXtype : function(xtype, els)
+        {
+            els.push('xtype: '+ xtype);
+        },
+        
+        
         /** 
          *  saveJS
          * 
@@ -152,9 +167,11 @@ Gtk = XObject.define(
          */
         saveJS: function()
         {
-             
+            if (!this.items[0]) {
+                return false;
+            }
             var data = JSON.parse(JSON.stringify(this.items[0]));
-            var i = [ 'Gtk', 'Gdk', 'Pango', 'GLib', 'Gio', 'GObject', 'GtkSource', 'WebKit', 'Vte' ];
+            var i = [ 'Gtk', 'Gdk', 'Pango', 'GLib', 'Gio', 'GObject', 'GtkSource', 'WebKit', 'Vte' , 'GtkClutter' , 'Gdl'];
             var src = "";
             i.forEach(function(e) {
                 src += e+" = imports.gi." + e +";\n";
@@ -164,14 +181,18 @@ Gtk = XObject.define(
             src += "XObject = imports.XObject.XObject;\n"; // path?!!?
             
             
-            src += this.name + '=new XObject('+ this.mungeToString(data) + ')\n;';
+            src += this.name + '=new XObject('+ this.mungeToString(data) + ");\n";
             src += this.name + '.init();\n';
+            // register it in the cache
+            src += "XObject.cache['/" + this.name + "'] = " + this.name + ";\n";
+            
             
             var fn = GLib.path_get_dirname(this.path) + '/' + this.name + '.js';
+            print("WRITE : " + fn);
             File.write(fn, src);
             
             return fn;
-        }
+        },
         /*
         getTree : function( o ) {
             
@@ -179,5 +200,9 @@ Gtk = XObject.define(
             
         }
         */
+        getHelpUrl : function(cls)
+        {
+            return 'http://devel.akbkhome.com/seed/' + cls + '.html';
+        }
         
     });
\ No newline at end of file