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);
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.
131 //console.dump(this.files);
134 for (var f in this.files) {
135 this.tree.push(this.files[f]);
140 // have parents -> add them to parent...
143 for (var k in this.files) {
145 var f = this.files[k];
152 //console.log(f.name);
154 files[f.fullname] = f;
158 // add Parent pointer..
159 for (var k in this.files) {
160 var f = this.files[k];
161 console.log(f.parent + ":" + f.name);
162 if (f.parent && typeof(files[f.parent]) != 'undefined') {
165 files[f.parent].cn.push(f);
176 for (var k in this.files) {
177 var f = this.files[k];
183 if (typeof(files[f.fullname]) != 'undefined') {
190 ret.sort(function(a,b) {
191 return a.path > b.path ? 1 : -1;
198 getById : function(id)
201 for (var k in this.files) {
202 var f = this.files[k];
204 console.log(f.id + '?=' + id);
212 loadFileOnly : function(path)
216 var cls = imports.Builder.Provider.File[xt][xt];
223 create : function(filename)
225 var ret = this.loadFileOnly(filename);
233 addFile: function(pfile) { // add a single file, and trigger changed.
234 this.files[pfile.path] = pfile
235 this.fireEvent('changed', this);
238 add: function(path, type)
240 this.paths = this.paths || { };
241 this.paths[path] = type;
242 //Seed.print(" type is '" + type + "'");
245 // console.dump(this.files);
247 if (type == 'file' ) {
249 this.files[path] = this.loadFileOnly( path );
252 // console.dump(this.files);
253 this.fireEvent('changed', this);
259 this.files = this.files || { };
260 for (var d in this.paths) {
261 if (this.paths[d] == 'dir') {
264 // otherwise add a file..
266 //console.dump(this.files);
272 scanDir : function(dir, dp)
275 Seed.print("Running scandir on " + dir);
276 if (dp > 5) { // no more than 5 deep?
279 // this should be done async -- but since we are getting the proto up ...
280 var dirs = File.list(dir);
283 dirs.forEach(function( fn ){
285 console.log('trying ' + dir + '/' + fn);
287 subs.forEach( function(s) {
288 _this.scanDir(s, dp+1);
292 if (fn[0] == '.') { // skip hidden
296 if (GLib.file_test(dir + '/' + fn, GLib.FileTest.IS_DIR)) {
297 subs.push(dir + '/' + fn);
301 if (!fn.match(/\.bjs$/)) {
306 var sp = dir.split('/');
307 sp = sp.splice(sp.length - (dp +1), (dp +1));
308 parent = sp.join('.');
311 if (typeof(_this.files[dir + '/' + fn]) != 'undefined') {
312 // we already have it..
313 _this.files[dir + '/' + fn].parent = parent;
316 var xt = _this.xtype;
317 var cls = imports.Builder.Provider.File[xt][xt];
319 Seed.print("Adding file " + dir + '/' + fn);
320 _this.files[dir + '/' + fn] = new cls({
321 path : dir + '/' + fn,
325 //console.log(this.files[dir + '/' + fn] );
327 var f = Gio.file_new_for_path(dir + '/' + fn);
328 var inf = f.query_info('standard::*');
329 var tv = new GLib.TimeVal();
330 inf.get_modification_time(tv);
332 // should it do something about this information..
333 // fixme... time data is busted..
334 this.files[dir + '/' + fn] = '' + tv.tv_sec + '.' + tv.tv_usec;