1 //<Script type="text/javascript">
4 GLib = imports.gi.GLib;
7 console = imports.console;
8 XObject = imports.XObject.XObject;
10 ProjectManager = imports.Builder.Provider.ProjectManager.ProjectManager;
11 Observable = imports.Observable.Observable;
13 Base = XObject.define(
17 this.addEvents({ 'changed' : true });
19 this.on('changed' , function() {
20 Seed.print("Calling PM - changed");
22 ProjectManager.fireEvent('changed');
24 XObject.extend(this, cfg);
28 for (var f in this.files) {
30 var cls = imports.Builder.Provider.File[xt][xt];
31 this.files[f] = cls(this.files[f]);
50 if (!this.fetchTree) {
51 console.log("Project.getTree tree called on base object?!?!");
56 return o.success.apply(o.scope || this, [this]);
58 return this.fetchTree(o);
66 ['id', 'fn', 'paths', 'xtype', 'name'].forEach( function(k) {
72 for (var f in this.files) {
74 ret.files[f] = this.files[f].toJsonArray();
78 return JSON.stringify(ret);
86 // normally this will build tree's based on info in the file stuff..
87 // but for the time being, we just return an array of all the files.
97 for (var f in this.files) {
98 this.tree.push(this.files[f]);
103 // have parents -> add them to parent...
106 for (var k in this.files) {
107 var f = this.files[k];
110 //console.log(f.name);
112 files[f.fullname] = f;
116 // add Parent pointer..
117 for (var k in this.files) {
118 var f = this.files[k];
119 console.log(f.parent + ":" + f.name);
120 if (f.parent && typeof(files[f.parent]) != 'undefined') {
123 files[f.parent].cn.push(f);
134 for (var k in this.files) {
135 var f = this.files[k];
141 if (typeof(files[f.fullname]) != 'undefined') {
148 ret.sort(function(a,b) {
149 return a.path > b.path ? 1 : -1;
156 getById : function(id)
159 for (var k in this.files) {
160 var f = this.files[k];
162 console.log(f.id + '?=' + id);
170 loadFileOnly : function(path)
174 var cls = imports.Builder.Provider.File[xt][xt];
180 create : function(filename)
182 var ret = this.loadFileOnly(filename);
190 addFile: function(pfile) { // add a single file, and trigger changed.
191 this.files[pfile.path] = pfile
192 this.fireEvent('changed', this);
195 add: function(path, type)
197 this.paths = this.paths || { };
198 this.paths[path] = type;
199 //Seed.print(" type is '" + type + "'");
202 // console.dump(this.files);
204 if (type == 'file' ) {
206 this.files[path] = this.loadFileOnly( path );
209 console.dump(this.files);
210 this.fireEvent('changed', this);
216 this.files = this.files || { };
217 for (var d in this.paths) {
218 if (this.paths[d] == 'dir') {
221 // otherwise add a file..
223 //console.dump(this.files);
229 scanDir : function(dir, dp)
232 Seed.print("Running scandir on " + dir);
233 if (dp > 5) { // no more than 5 deep?
236 // this should be done async -- but since we are getting the protvgo up..
237 var gdir = GLib.dir_open(dir,0);
241 var fn = GLib.dir_read_name(gdir);
242 //console.log('trying ' + path + '/' + fn);
244 GLib.dir_close(gdir);
245 subs.forEach( function(s) {
246 _this.scanDir(s, dp+1);
250 if (fn[0] == '.') { // skip hidden
254 if (GLib.file_test(dir + '/' + fn, GLib.FileTest.IS_DIR)) {
255 subs.push(dir + '/' + fn);
259 if (!fn.match(/.js$/)) {
264 var sp = dir.split('/');
265 sp = sp.splice(sp.length - (dp +1), (dp +1));
266 parent = sp.join('.');
269 if (typeof(this.files[dir + '/' + fn]) != 'undefined') {
270 // we already have it..
271 this.files[dir + '/' + fn].parent = parent;
275 var cls = imports.Builder.Provider.File[xt][xt];
277 Seed.print("Adding file " + dir + '/' + fn);
278 this.files[dir + '/' + fn] = new cls({
279 path : dir + '/' + fn,
283 var f = Gio.file_new_for_path(dir + '/' + fn);
284 var inf = f.query_info('standard::*');
285 var tv = new GLib.TimeVal();
286 inf.get_modification_time(tv);
288 // should it do something about this information..
289 // fixme... time data is busted..
290 this.files[dir + '/' + fn] = '' + tv.tv_sec + '.' + tv.tv_usec;