Builder/Provider/File/Gtk.js
[app.Builder.js] / Builder / Provider / File / Gtk.js
index f03abdc..b1ed333 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;
@@ -22,7 +23,10 @@ Gtk = XObject.define(
         //console.dump(cfg);
         cfg.parent = cfg.parent || '';
         if (!cfg.name || !cfg.fullname ) {
-            cfg.name = cfg.path.split('/').pop().replace(/\.js$/, '');
+            
+            // name is in theory filename without .bjs (or .js eventually...)
+            cfg.name = cfg.path.split('/').pop().replace(/\.(bjs|js)$/, '');
+            
             cfg.fullname = (cfg.parent.length ? (cfg.parent + '.') : '' ) + cfg.name;
         }
         
@@ -54,6 +58,7 @@ Gtk = XObject.define(
         
         // super?!?!
         this.id = 'file-gtk-' + gid++;
+        //console.dump(this);
         // various loader methods..
        
     },
@@ -78,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);
             
@@ -91,13 +99,16 @@ 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 || []; 
-            cb();
+           
+                cb();
+             
+            
                 
                 // update to new JSDOC api!?
                 /*
@@ -136,119 +147,53 @@ Gtk = XObject.define(
             
             
         },
-        /** 
-         * fixme - update to new style
-         * 
-         * 
+        /**
+         * convert xtype for munged output..
          * 
          */
-        
-        toSourceStdClass: function()
+        mungeXtype : function(xtype, els)
         {
-            var cfg = this.items[0]
-            var fcfg = XObject.extend({ },  this.items[0]);
-            delete fcfg['*class'];
-            delete fcfg['*extends'];
-            delete fcfg['*static'];
-            delete fcfg['|constructor'];
-            
-            var hasExtends = (typeof(cfg['*extends']) != 'undefined') && cfg['*extends'].length;
-            var hasConstructor = (typeof(cfg['|constructor']) != 'undefined');
-            var isStatic = (typeof(cfg['*static']) == '*static');
-            
-            var newline = '';
-            var endline = '';
-            if (hasExtends) {
-                newline =  hasConstructor ? 
-                
-                 
-                    cfg['//constructor'] + "\n" + 
-                    cfg['*class'] + " = " + cfg['|constructor'] + "\n\n"+ 
-                    "Roo.extend(" + cfg['*class'] + ":, " + cfg['*extends'] + ", " :
-                    
-                    cfg['//*class'] + "\n" + 
-                    cfg['*class'] + " = new " + cfg['*extends'] + "(" ;
-                
-                endline = ');';
-            } else {
-                
-                
-                
-                newline  = hasConstructor ? 
-                
-                    cfg['//constructor'] + "\n" + 
-                    cfg['*class'] + " = " + cfg['|constructor'] + "\n\n"+ 
-                    'Roo.apply( ' +  cfg['*class'] + ".prototype , " :
-                    
-                    cfg['//*class'] + "\n" + 
-                    cfg['*class'] + " = ";
-                
-                    
-                endline = hasConstructor ? ');' : ';';
-            }
-                  
-            return this.outputHeader() + 
-                    newline + 
-                    this.objectToJsString(fcfg,1) +
-                    endline;
-            
-            
-            
-         
+            els.push('xtype: '+ xtype);
         },
         
         
-        toSource: function()
+        /** 
+         *  saveJS
+         * 
+         * save as a javascript file.
+         * 
+         * 
+         * 
+         */
+        saveJS: function()
         {
-            // dump the file tree back out to a string.
-            
-            if (typeof(this.items[0]['*class']) != 'undefined') {
-                return this.toSourceStdClass();
+            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' , 'GtkClutter' , 'Gdl'];
+            var src = "";
+            i.forEach(function(e) {
+                src += e+" = imports.gi." + e +";\n";
+            });
             
+            src += "console = imports.console;\n"; // path?!!?
+            src += "XObject = imports.XObject.XObject;\n"; // path?!!?
             
-            // technically there will be different versions of this.
-            var o = this.mungePropObj(this.items[0]);
-            //console.dump(o);
-            //Seed.quit();
             
-            return this.outputHeader() + 
-                [
-                    "function create()",
-                    "{",
-                    "    return "
-                ].join("\n") +
-                this.objectToJsString(o,2) +
-                [
-                    ";", // end return value..
-                    "}"
-                ].join("\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;
         },
-       
-        outputHeader : function()
-        {
-            var ret = '//<script type="text/javascript">' + "\n";
-            ret += "\n\n// gi imports\n";
-            Roo.each(this.giImports, function(i) {
-                ret += i + " =  imports.gi." + i + ";\n";
-            });
-            ret += "\n\n// file imports\n";
-            for(var k in this.imports) {
-                ret += k + " =  imports[" + JSON.stringify(this.imports[k]) + "];\n";
-            }
-            
-            return ret + "\n\n";
-        }
-        
         /*
         getTree : function( o ) {
             
@@ -256,5 +201,9 @@ Gtk = XObject.define(
             
         }
         */
+        getHelpUrl : function(cls)
+        {
+            return 'http://devel.akbkhome.com/seed/' + cls + '.html';
+        }
         
     });
\ No newline at end of file