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 ['id', 'fn', 'paths', 'xtype', 'name'].forEach( function(k) {
88 for (var f in this.files) {
90 ret.files[f] = this.files[f].toJsonArray();
94 return JSON.stringify(ret);
102 // normally this will build tree's based on info in the file stuff..
103 // but for the time being, we just return an array of all the files.
113 for (var f in this.files) {
114 this.tree.push(this.files[f]);
119 // have parents -> add them to parent...
122 for (var k in this.files) {
124 var f = this.files[k];
131 //console.log(f.name);
133 files[f.fullname] = f;
137 // add Parent pointer..
138 for (var k in this.files) {
139 var f = this.files[k];
140 console.log(f.parent + ":" + f.name);
141 if (f.parent && typeof(files[f.parent]) != 'undefined') {
144 files[f.parent].cn.push(f);
155 for (var k in this.files) {
156 var f = this.files[k];
162 if (typeof(files[f.fullname]) != 'undefined') {
169 ret.sort(function(a,b) {
170 return a.path > b.path ? 1 : -1;
177 getById : function(id)
180 for (var k in this.files) {
181 var f = this.files[k];
183 console.log(f.id + '?=' + id);
191 loadFileOnly : function(path)
195 var cls = imports.Builder.Provider.File[xt][xt];
202 create : function(filename)
204 var ret = this.loadFileOnly(filename);
212 addFile: function(pfile) { // add a single file, and trigger changed.
213 this.files[pfile.path] = pfile
214 this.fireEvent('changed', this);
217 add: function(path, type)
219 this.paths = this.paths || { };
220 this.paths[path] = type;
221 //Seed.print(" type is '" + type + "'");
224 // console.dump(this.files);
226 if (type == 'file' ) {
228 this.files[path] = this.loadFileOnly( path );
231 // console.dump(this.files);
232 this.fireEvent('changed', this);
238 this.files = this.files || { };
239 for (var d in this.paths) {
240 if (this.paths[d] == 'dir') {
243 // otherwise add a file..
245 //console.dump(this.files);
251 scanDir : function(dir, dp)
254 Seed.print("Running scandir on " + dir);
255 if (dp > 5) { // no more than 5 deep?
258 // this should be done async -- but since we are getting the proto up ...
259 var gdir = GLib.dir_open(dir,0);
263 var fn = GLib.dir_read_name(gdir);
264 console.log('trying ' + dir + '/' + fn);
266 GLib.dir_close(gdir);
267 subs.forEach( function(s) {
268 _this.scanDir(s, dp+1);
272 if (fn[0] == '.') { // skip hidden
276 if (GLib.file_test(dir + '/' + fn, GLib.FileTest.IS_DIR)) {
277 subs.push(dir + '/' + fn);
281 if (!fn.match(/\.bjs$/)) {
286 var sp = dir.split('/');
287 sp = sp.splice(sp.length - (dp +1), (dp +1));
288 parent = sp.join('.');
291 if (typeof(this.files[dir + '/' + fn]) != 'undefined') {
292 // we already have it..
293 this.files[dir + '/' + fn].parent = parent;
297 var cls = imports.Builder.Provider.File[xt][xt];
299 Seed.print("Adding file " + dir + '/' + fn);
300 this.files[dir + '/' + fn] = new cls({
301 path : dir + '/' + fn,
305 console.log(this.files[dir + '/' + fn] );
307 var f = Gio.file_new_for_path(dir + '/' + fn);
308 var inf = f.query_info('standard::*');
309 var tv = new GLib.TimeVal();
310 inf.get_modification_time(tv);
312 // should it do something about this information..
313 // fixme... time data is busted..
314 this.files[dir + '/' + fn] = '' + tv.tv_sec + '.' + tv.tv_usec;