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.Builder.Provider.ProjectManager.ProjectManager;
23 Observable = imports.Observable.Observable;
25 Base = XObject.define(
29 this.addEvents({ 'changed' : true });
31 this.on('changed' , function() {
32 Seed.print("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("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("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);
122 // normally this will build tree's based on info in the file stuff..
123 // but for the time being, we just return an array of all the files.
133 for (var f in this.files) {
134 this.tree.push(this.files[f]);
139 // have parents -> add them to parent...
142 for (var k in this.files) {
144 var f = this.files[k];
151 //console.log(f.name);
153 files[f.fullname] = f;
157 // add Parent pointer..
158 for (var k in this.files) {
159 var f = this.files[k];
160 console.log(f.parent + ":" + f.name);
161 if (f.parent && typeof(files[f.parent]) != 'undefined') {
164 files[f.parent].cn.push(f);
175 for (var k in this.files) {
176 var f = this.files[k];
182 if (typeof(files[f.fullname]) != 'undefined') {
189 ret.sort(function(a,b) {
190 return a.path > b.path ? 1 : -1;
197 getById : function(id)
200 for (var k in this.files) {
201 var f = this.files[k];
203 console.log(f.id + '?=' + id);
211 loadFileOnly : function(path)
215 var cls = imports.Builder.Provider.File[xt][xt];
222 create : function(filename)
224 var ret = this.loadFileOnly(filename);
232 addFile: function(pfile) { // add a single file, and trigger changed.
233 this.files[pfile.path] = pfile
234 this.fireEvent('changed', this);
237 add: function(path, type)
239 this.paths = this.paths || { };
240 this.paths[path] = type;
241 //Seed.print(" type is '" + type + "'");
244 // console.dump(this.files);
246 if (type == 'file' ) {
248 this.files[path] = this.loadFileOnly( path );
251 // console.dump(this.files);
252 this.fireEvent('changed', this);
258 this.files = this.files || { };
259 for (var d in this.paths) {
260 if (this.paths[d] == 'dir') {
263 // otherwise add a file..
265 //console.dump(this.files);
271 scanDir : function(dir, dp)
274 Seed.print("Running scandir on " + dir);
275 if (dp > 5) { // no more than 5 deep?
278 // this should be done async -- but since we are getting the proto up ...
279 var dirs = File.list(dir);
282 dirs.forEach(function( fn ){
284 console.log('trying ' + dir + '/' + fn);
286 subs.forEach( function(s) {
287 _this.scanDir(s, dp+1);
291 if (fn[0] == '.') { // skip hidden
295 if (GLib.file_test(dir + '/' + fn, GLib.FileTest.IS_DIR)) {
296 subs.push(dir + '/' + fn);
300 if (!fn.match(/\.bjs$/)) {
305 var sp = dir.split('/');
306 sp = sp.splice(sp.length - (dp +1), (dp +1));
307 parent = sp.join('.');
310 if (typeof(_this.files[dir + '/' + fn]) != 'undefined') {
311 // we already have it..
312 _this.files[dir + '/' + fn].parent = parent;
315 var xt = _this.xtype;
316 var cls = imports.Builder.Provider.File[xt][xt];
318 Seed.print("Adding file " + dir + '/' + fn);
319 _this.files[dir + '/' + fn] = new cls({
320 path : dir + '/' + fn,
324 //console.log(this.files[dir + '/' + fn] );
326 var f = Gio.file_new_for_path(dir + '/' + fn);
327 var inf = f.query_info('standard::*');
328 var tv = new GLib.TimeVal();
329 inf.get_modification_time(tv);
331 // should it do something about this information..
332 // fixme... time data is busted..
333 this.files[dir + '/' + fn] = '' + tv.tv_sec + '.' + tv.tv_usec;