1 //<Script type="text/javascript">
6 * Projects can only contain one directory... - it can import other projects..(later)
8 * we need to sort out that - paths is currently a key/value array..
15 GLib = imports.gi.GLib;
18 console = imports.console;
19 XObject = imports.XObject.XObject;
20 File = imports.File.File;
22 ProjectManager = imports.ProjectManager.ProjectManager;
23 Observable = imports.Observable.Observable;
25 Base = XObject.define(
29 this.addEvents({ 'changed' : true });
31 this.on('changed' , function() {
32 Seed.print("Project.Base: Calling PM - changed");
34 ProjectManager.fireEvent('changed');
36 XObject.extend(this, cfg);
40 for (var f in this.files) {
42 var cls = imports.Builder.Provider.File[xt][xt];
43 this.files[f] = cls(this.files[f]);
55 fn: false, // the md5 sum for this one..
61 load : function (o) // is this used??
63 if (!this.fetchTree) {
64 console.log("Project.getTree tree called on base object?!?!");
69 return o.success.apply(o.scope || this, [this]);
71 return this.fetchTree(o);
74 getPalete : function()
76 print("Project.Base: GET PROVIDER FOR " + this.xtype);
77 return ProjectManager.getPalete(this.xtype);
83 for (var k in _this) {
85 if (['files', 'tree'].indexOf(k) > -1) {
89 if ((typeof(_this[k]) == 'object') ||(typeof(_this[k]) == 'function')) {
93 print("Project.Base: Storing " + k);
100 //for (var f in this.files) {
102 // ret.files[f] = this.files[f].toJsonArray();
106 return JSON.stringify(ret);
112 //returns the basename of the first path..
113 for (var i in this.paths) {
114 return GLib.basename(i);
123 // normally this will build tree's based on info in the file stuff..
124 // but for the time being, we just return an array of all the files.
134 for (var f in this.files) {
135 this.tree.push(this.files[f]);
139 print(JSON.stringify(this.files,null,4));
141 // have parents -> add them to parent...
144 for (var k in this.files) {
146 var f = this.files[k];
153 //console.log(f.name);
155 files[f.fullname] = f;
159 // add Parent pointer..
160 for (var k in this.files) {
161 var f = this.files[k];
162 console.log(f.parent + ":" + f.name);
163 if (f.parent && typeof(files[f.parent]) != 'undefined') {
166 files[f.parent].cn.push(f);
177 for (var k in this.files) {
178 var f = this.files[k];
184 if (typeof(files[f.fullname]) != 'undefined') {
191 ret.sort(function(a,b) {
192 return a.path > b.path ? 1 : -1;
195 print(JSON.stringify(ret,null,4));
203 getById : function(id)
206 for (var k in this.files) {
207 var f = this.files[k];
209 console.log(f.id + '?=' + id);
217 loadFileOnly : function(path)
221 var cls = imports.JsRender[xt][xt];
228 create : function(filename)
230 var ret = this.loadFileOnly(filename);
238 addFile: function(pfile) { // add a single file, and trigger changed.
239 this.files[pfile.path] = pfile
240 this.fireEvent('changed', this);
243 add: function(path, type)
245 this.paths = this.paths || { };
246 this.paths[path] = type;
247 //Seed.print(" type is '" + type + "'");
250 // console.dump(this.files);
252 if (type == 'file' ) {
254 this.files[path] = this.loadFileOnly( path );
257 // console.dump(this.files);
258 this.fireEvent('changed', this);
264 this.files = this.files || { };
265 for (var d in this.paths) {
266 if (this.paths[d] == 'dir') {
269 // otherwise add a file..
271 //console.dump(this.files);
277 scanDir : function(dir, dp)
280 Seed.print("Project.Base: Running scandir on " + dir);
281 if (dp > 5) { // no more than 5 deep?
284 // this should be done async -- but since we are getting the proto up ...
285 var dirs = File.list(dir);
287 ///print(dirs); Seed.exit();
291 dirs.forEach(function( fn ){
293 //console.log('trying ' + dir + '/' + fn);
295 subs.forEach( function(s) {
296 _this.scanDir(s, dp+1);
300 if (fn[0] == '.') { // skip hidden
304 if (GLib.file_test(dir + '/' + fn, GLib.FileTest.IS_DIR)) {
305 subs.push(dir + '/' + fn);
309 if (!fn.match(/\.bjs$/)) {
314 var sp = dir.split('/');
315 sp = sp.splice(sp.length - (dp +1), (dp +1));
316 parent = sp.join('.');
319 if (typeof(_this.files[dir + '/' + fn]) != 'undefined') {
320 // we already have it..
321 _this.files[dir + '/' + fn].parent = parent;
324 var xt = _this.xtype;
325 var cls = imports.JsRender[xt][xt];
327 //Seed.print("Adding file " + dir + '/' + fn);
328 _this.files[dir + '/' + fn] = new cls({
329 path : dir + '/' + fn,
333 //console.log(this.files[dir + '/' + fn] );
335 var f = Gio.file_new_for_path(dir + '/' + fn);
336 var inf = f.query_info('standard::*');
337 var tv = new GLib.TimeVal();
338 inf.get_modification_time(tv);
340 // should it do something about this information..
341 // fixme... time data is busted..
342 this.files[dir + '/' + fn] = '' + tv.tv_sec + '.' + tv.tv_usec;