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;
21 ProjectManager = imports.Builder.Provider.ProjectManager.ProjectManager;
22 Observable = imports.Observable.Observable;
24 Base = XObject.define(
28 this.addEvents({ 'changed' : true });
30 this.on('changed' , function() {
31 Seed.print("Calling PM - changed");
33 ProjectManager.fireEvent('changed');
35 XObject.extend(this, cfg);
39 for (var f in this.files) {
41 var cls = imports.Builder.Provider.File[xt][xt];
42 this.files[f] = cls(this.files[f]);
54 fn: false, // the md5 sum for this one..
60 load : function (o) // is this used??
62 if (!this.fetchTree) {
63 console.log("Project.getTree tree called on base object?!?!");
68 return o.success.apply(o.scope || this, [this]);
70 return this.fetchTree(o);
73 getPalete : function()
75 print("GET PROVIDER FOR " + this.xtype);
76 return ProjectManager.getPalete(this.xtype);
82 for (var k in _this) {
84 if (['files', 'tree'].indexOf(k) > -1) {
87 if ((typeof(_this[k]) == 'object') ||(typeof(_this[k]) == 'function')) {
90 print("Storing " + k);
97 //for (var f in this.files) {
99 // ret.files[f] = this.files[f].toJsonArray();
103 return JSON.stringify(ret);
111 // normally this will build tree's based on info in the file stuff..
112 // but for the time being, we just return an array of all the files.
122 for (var f in this.files) {
123 this.tree.push(this.files[f]);
128 // have parents -> add them to parent...
131 for (var k in this.files) {
133 var f = this.files[k];
140 //console.log(f.name);
142 files[f.fullname] = f;
146 // add Parent pointer..
147 for (var k in this.files) {
148 var f = this.files[k];
149 console.log(f.parent + ":" + f.name);
150 if (f.parent && typeof(files[f.parent]) != 'undefined') {
153 files[f.parent].cn.push(f);
164 for (var k in this.files) {
165 var f = this.files[k];
171 if (typeof(files[f.fullname]) != 'undefined') {
178 ret.sort(function(a,b) {
179 return a.path > b.path ? 1 : -1;
186 getById : function(id)
189 for (var k in this.files) {
190 var f = this.files[k];
192 console.log(f.id + '?=' + id);
200 loadFileOnly : function(path)
204 var cls = imports.Builder.Provider.File[xt][xt];
211 create : function(filename)
213 var ret = this.loadFileOnly(filename);
221 addFile: function(pfile) { // add a single file, and trigger changed.
222 this.files[pfile.path] = pfile
223 this.fireEvent('changed', this);
226 add: function(path, type)
228 this.paths = this.paths || { };
229 this.paths[path] = type;
230 //Seed.print(" type is '" + type + "'");
233 // console.dump(this.files);
235 if (type == 'file' ) {
237 this.files[path] = this.loadFileOnly( path );
240 // console.dump(this.files);
241 this.fireEvent('changed', this);
247 this.files = this.files || { };
248 for (var d in this.paths) {
249 if (this.paths[d] == 'dir') {
252 // otherwise add a file..
254 //console.dump(this.files);
260 scanDir : function(dir, dp)
263 Seed.print("Running scandir on " + dir);
264 if (dp > 5) { // no more than 5 deep?
267 // this should be done async -- but since we are getting the proto up ...
268 var gdir = GLib.dir_open(dir,0);
272 var fn = GLib.dir_read_name(gdir);
273 console.log('trying ' + dir + '/' + fn);
275 GLib.dir_close(gdir);
276 subs.forEach( function(s) {
277 _this.scanDir(s, dp+1);
281 if (fn[0] == '.') { // skip hidden
285 if (GLib.file_test(dir + '/' + fn, GLib.FileTest.IS_DIR)) {
286 subs.push(dir + '/' + fn);
290 if (!fn.match(/\.bjs$/)) {
295 var sp = dir.split('/');
296 sp = sp.splice(sp.length - (dp +1), (dp +1));
297 parent = sp.join('.');
300 if (typeof(this.files[dir + '/' + fn]) != 'undefined') {
301 // we already have it..
302 this.files[dir + '/' + fn].parent = parent;
306 var cls = imports.Builder.Provider.File[xt][xt];
308 Seed.print("Adding file " + dir + '/' + fn);
309 this.files[dir + '/' + fn] = new cls({
310 path : dir + '/' + fn,
314 //console.log(this.files[dir + '/' + fn] );
316 var f = Gio.file_new_for_path(dir + '/' + fn);
317 var inf = f.query_info('standard::*');
318 var tv = new GLib.TimeVal();
319 inf.get_modification_time(tv);
321 // should it do something about this information..
322 // fixme... time data is busted..
323 this.files[dir + '/' + fn] = '' + tv.tv_sec + '.' + tv.tv_usec;