1 //<Script type="text/javascript">
6 * Projects can only contain one directory... - it can import other projects..
14 GLib = imports.gi.GLib;
17 console = imports.console;
18 XObject = imports.XObject.XObject;
20 ProjectManager = imports.Builder.Provider.ProjectManager.ProjectManager;
21 Observable = imports.Observable.Observable;
23 Base = XObject.define(
27 this.addEvents({ 'changed' : true });
29 this.on('changed' , function() {
30 Seed.print("Calling PM - changed");
32 ProjectManager.fireEvent('changed');
34 XObject.extend(this, cfg);
38 for (var f in this.files) {
40 var cls = imports.Builder.Provider.File[xt][xt];
41 this.files[f] = cls(this.files[f]);
61 if (!this.fetchTree) {
62 console.log("Project.getTree tree called on base object?!?!");
67 return o.success.apply(o.scope || this, [this]);
69 return this.fetchTree(o);
72 getPalete : function()
74 print("GET PROVIDER FOR " + this.xtype);
75 return ProjectManager.getPalete(this.xtype);
81 ['id', 'fn', 'paths', 'xtype', 'name'].forEach( function(k) {
87 for (var f in this.files) {
89 ret.files[f] = this.files[f].toJsonArray();
93 return JSON.stringify(ret);
101 // normally this will build tree's based on info in the file stuff..
102 // but for the time being, we just return an array of all the files.
112 for (var f in this.files) {
113 this.tree.push(this.files[f]);
118 // have parents -> add them to parent...
121 for (var k in this.files) {
123 var f = this.files[k];
130 //console.log(f.name);
132 files[f.fullname] = f;
136 // add Parent pointer..
137 for (var k in this.files) {
138 var f = this.files[k];
139 console.log(f.parent + ":" + f.name);
140 if (f.parent && typeof(files[f.parent]) != 'undefined') {
143 files[f.parent].cn.push(f);
154 for (var k in this.files) {
155 var f = this.files[k];
161 if (typeof(files[f.fullname]) != 'undefined') {
168 ret.sort(function(a,b) {
169 return a.path > b.path ? 1 : -1;
176 getById : function(id)
179 for (var k in this.files) {
180 var f = this.files[k];
182 console.log(f.id + '?=' + id);
190 loadFileOnly : function(path)
194 var cls = imports.Builder.Provider.File[xt][xt];
200 create : function(filename)
202 var ret = this.loadFileOnly(filename);
210 addFile: function(pfile) { // add a single file, and trigger changed.
211 this.files[pfile.path] = pfile
212 this.fireEvent('changed', this);
215 add: function(path, type)
217 this.paths = this.paths || { };
218 this.paths[path] = type;
219 //Seed.print(" type is '" + type + "'");
222 // console.dump(this.files);
224 if (type == 'file' ) {
226 this.files[path] = this.loadFileOnly( path );
229 console.dump(this.files);
230 this.fireEvent('changed', this);
236 this.files = this.files || { };
237 for (var d in this.paths) {
238 if (this.paths[d] == 'dir') {
241 // otherwise add a file..
243 //console.dump(this.files);
249 scanDir : function(dir, dp)
252 Seed.print("Running scandir on " + dir);
253 if (dp > 5) { // no more than 5 deep?
256 // this should be done async -- but since we are getting the proto up ...
257 var gdir = GLib.dir_open(dir,0);
261 var fn = GLib.dir_read_name(gdir);
262 console.log('trying ' + dir + '/' + fn);
264 GLib.dir_close(gdir);
265 subs.forEach( function(s) {
266 _this.scanDir(s, dp+1);
270 if (fn[0] == '.') { // skip hidden
274 if (GLib.file_test(dir + '/' + fn, GLib.FileTest.IS_DIR)) {
275 subs.push(dir + '/' + fn);
279 if (!fn.match(/\.bjs$/)) {
284 var sp = dir.split('/');
285 sp = sp.splice(sp.length - (dp +1), (dp +1));
286 parent = sp.join('.');
289 if (typeof(this.files[dir + '/' + fn]) != 'undefined') {
290 // we already have it..
291 this.files[dir + '/' + fn].parent = parent;
295 var cls = imports.Builder.Provider.File[xt][xt];
297 Seed.print("Adding file " + dir + '/' + fn);
298 this.files[dir + '/' + fn] = new cls({
299 path : dir + '/' + fn,
302 console.log(this.files[dir + '/' + fn] );
304 var f = Gio.file_new_for_path(dir + '/' + fn);
305 var inf = f.query_info('standard::*');
306 var tv = new GLib.TimeVal();
307 inf.get_modification_time(tv);
309 // should it do something about this information..
310 // fixme... time data is busted..
311 this.files[dir + '/' + fn] = '' + tv.tv_sec + '.' + tv.tv_usec;