Builder/Provider/RooUsage.txt
[app.Builder.js] / Builder / Provider / Project / Base.js
index 6fe6341..21f938c 100644 (file)
@@ -1,13 +1,26 @@
 //<Script type="text/javascript">
 
+/**
+ * Project Object
+ * 
+ * Projects can only contain one directory... - it can import other projects..(later)
+ * 
+ * we need to sort out that - paths is currently a key/value array..
+ * 
+ * 
+ * 
+ */
+
 Gio = imports.gi.Gio;
 GLib = imports.gi.GLib; 
 
 
 console = imports.console;
 XObject = imports.XObject.XObject;
+File = imports.File.File;
 
-ProjectManager = imports.Builder.Provider.ProjectManager;
+ProjectManager = imports.Builder.Provider.ProjectManager.ProjectManager;
+Observable = imports.Observable.Observable;
 
 Base = XObject.define( 
     function(cfg) {
@@ -18,11 +31,11 @@ Base = XObject.define(
         this.on('changed' , function() {
             Seed.print("Calling PM - changed");
             
-            ProjectManager.onChanged();
+            ProjectManager.fireEvent('changed');
         });
         XObject.extend(this, cfg);
-        
-        /
+        this.files = { }; 
+        /*
         if (this.files ){
             for (var f in this.files) {
                 var xt = this.xtype;
@@ -30,21 +43,22 @@ Base = XObject.define(
                 this.files[f] = cls(this.files[f]);
             }
         }
+        */
         
         
         this.scanDirs();
         
     },
-    Object
+    Observable
     {
         id : false,
-        fn:  false,
+        fn:  false, // the md5 sum for this one..
         paths : false,
         files : false,
         tree : false,
         xtype : false,
         
-        load : function (o) 
+        load : function (o)  // is this used??
         {
             if (!this.fetchTree) {
                 console.log("Project.getTree tree called on base object?!?!");
@@ -57,26 +71,50 @@ Base = XObject.define(
             return this.fetchTree(o);
             
         },
-        
+        getPalete : function()
+        {
+            print("GET PROVIDER FOR " + this.xtype);
+            return  ProjectManager.getPalete(this.xtype);
+        },
         toJSON : function()
         {
             var ret = { };
             var _this = this;
-            ['id', 'fn', 'paths', 'xtype', 'name'].forEach(  function(k) {
+            for (var k in _this) {
+                
+                if (['files', 'tree'].indexOf(k) > -1) {
+                    continue;
+                }
+                if (k != 'paths') {
+                    if ((typeof(_this[k]) == 'object') ||(typeof(_this[k]) == 'function')) {
+                        continue;
+                    }
+                }
+                print("Storing " + k);
                 ret[k] = _this[k];
                 
-            });
-            ret.files = { }; 
-            // deal with files..
-            for (var f in this.files) {
-                ret.files[f] = this.files[f].toJsonArray();
             }
             
             
+            // deal with files..
+            //for (var f in this.files) {
+            //    print(f);
+            //    ret.files[f] = this.files[f].toJsonArray();
+           // }
+            
+            
             return JSON.stringify(ret);
           
           
         },
+        getName :function()
+        {
+            //returns the basename of the first path..
+            for (var i in this.paths) {
+                return GLib.basename(i);
+            }
+        },
+        
         toTree : function()
         {
             
@@ -102,7 +140,12 @@ Base = XObject.define(
             var files = {};
             var parents = {};
             for (var k in this.files) {
+                
                 var f = this.files[k];
+                if (!f) {
+                    continue;
+                   }
+                ///console.dump(f);
                 f.hasParent = false;
                 f.cn = [];
                 //console.log(f.name);
@@ -172,10 +215,20 @@ Base = XObject.define(
             var cls = imports.Builder.Provider.File[xt][xt];
             return  new cls({
                 path : path,
-                parent : ''
+                parent : '',
+                project : this
             });
         },
+        create : function(filename)
+        {
+            var ret = this.loadFileOnly(filename);
+            ret.save();
+            this.addFile(ret);
+            return ret;
+            
+        },
         
+         
         addFile: function(pfile) { // add a single file, and trigger changed.
             this.files[pfile.path] = pfile
             this.fireEvent('changed', this);
@@ -195,7 +248,7 @@ Base = XObject.define(
                 this.files[path] = this.loadFileOnly( path );
             }
             
-             console.dump(this.files);
+            // console.dump(this.files);
             this.fireEvent('changed', this);
             
         },
@@ -222,30 +275,30 @@ Base = XObject.define(
             if (dp > 5) { // no more than 5 deep?
                 return;
             }
-            // this should be done async -- but since we are getting the protvgo up..
-            var gdir = GLib.dir_open(dir,0);
+            // this should be done async -- but since we are getting the proto up ...
+            var dirs = File.list(dir);
             var subs = [];
-            while (true) {
-                var fn = GLib.dir_read_name(gdir);
-                //console.log('trying ' + path + '/' + fn);
+            var _this = this;
+            dirs.forEach(function( fn ){ 
+                 
+                console.log('trying ' + dir + '/' + fn);
                 if (!fn) {
-                    GLib.dir_close(gdir);
-                    Roo.each(subs, function(s) {
-                        this.scanDir(s, dp+1);
-                    },this);
+                    subs.forEach( function(s) {
+                        _this.scanDir(s, dp+1);
+                    });
                     return;
                 }
                 if (fn[0] == '.') { // skip hidden
-                    continue;
+                    return;
                 }
                 
                 if (GLib.file_test(dir  + '/' + fn, GLib.FileTest.IS_DIR)) {
                     subs.push(dir  + '/' + fn);
-                    continue;
+                    return;
                 }
                 
-                if (!fn.match(/.js$/)) {
-                    continue;
+                if (!fn.match(/\.bjs$/)) {
+                    return;
                 }
                 var parent = '';
                 //if (dp > 0 ) {
@@ -254,19 +307,21 @@ Base = XObject.define(
                 parent = sp.join('.');
                 
                 
-                if (typeof(this.files[dir  + '/' + fn]) != 'undefined') {
+                if (typeof(_this.files[dir  + '/' + fn]) != 'undefined') {
                     // we already have it..
-                    this.files[dir  + '/' + fn].parent = parent;
-                    continue;
+                    _this.files[dir  + '/' + fn].parent = parent;
+                    return;
                 }
-                var xt = this.xtype;
+                var xt = _this.xtype;
                 var cls = imports.Builder.Provider.File[xt][xt];
                 
                 Seed.print("Adding file " + dir  + '/' + fn);
-                this.files[dir  + '/' + fn] = new cls({
+                _this.files[dir  + '/' + fn] = new cls({
                     path : dir  + '/' + fn,
-                    parent : parent
+                    parent : parent,
+                    project : _this
                 });
+                //console.log(this.files[dir  + '/' + fn] );
                 /*
                 var f = Gio.file_new_for_path(dir + '/' + fn);
                 var inf = f.query_info('standard::*');
@@ -277,7 +332,7 @@ Base = XObject.define(
                 // fixme... time data is busted..
                 this.files[dir  + '/' + fn] = '' + tv.tv_sec + '.' + tv.tv_usec;
                 */
-            }
+            });
              
             
         }