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) {
73 ret.files[f] = this.files[f].toJsonArray();
77 return JSON.stringify(ret);
85 // normally this will build tree's based on info in the file stuff..
86 // but for the time being, we just return an array of all the files.
96 for (var f in this.files) {
97 this.tree.push(this.files[f]);
102 // have parents -> add them to parent...
105 for (var k in this.files) {
106 var f = this.files[k];
109 //console.log(f.name);
111 files[f.fullname] = f;
115 // add Parent pointer..
116 for (var k in this.files) {
117 var f = this.files[k];
118 console.log(f.parent + ":" + f.name);
119 if (f.parent && typeof(files[f.parent]) != 'undefined') {
122 files[f.parent].cn.push(f);
133 for (var k in this.files) {
134 var f = this.files[k];
140 if (typeof(files[f.fullname]) != 'undefined') {
147 ret.sort(function(a,b) {
148 return a.path > b.path ? 1 : -1;
155 getById : function(id)
158 for (var k in this.files) {
159 var f = this.files[k];
161 console.log(f.id + '?=' + id);
169 loadFileOnly : function(path)
173 var cls = imports.Builder.Provider.File[xt][xt];
179 create : function(filename)
181 var ret = this.loadFileOnly(filename);
189 addFile: function(pfile) { // add a single file, and trigger changed.
190 this.files[pfile.path] = pfile
191 this.fireEvent('changed', this);
194 add: function(path, type)
196 this.paths = this.paths || { };
197 this.paths[path] = type;
198 //Seed.print(" type is '" + type + "'");
201 // console.dump(this.files);
203 if (type == 'file' ) {
205 this.files[path] = this.loadFileOnly( path );
208 console.dump(this.files);
209 this.fireEvent('changed', this);
215 this.files = this.files || { };
216 for (var d in this.paths) {
217 if (this.paths[d] == 'dir') {
220 // otherwise add a file..
222 //console.dump(this.files);
228 scanDir : function(dir, dp)
231 Seed.print("Running scandir on " + dir);
232 if (dp > 5) { // no more than 5 deep?
235 // this should be done async -- but since we are getting the protvgo up..
236 var gdir = GLib.dir_open(dir,0);
240 var fn = GLib.dir_read_name(gdir);
241 //console.log('trying ' + path + '/' + fn);
243 GLib.dir_close(gdir);
244 subs.forEach( function(s) {
245 _this.scanDir(s, dp+1);
249 if (fn[0] == '.') { // skip hidden
253 if (GLib.file_test(dir + '/' + fn, GLib.FileTest.IS_DIR)) {
254 subs.push(dir + '/' + fn);
258 if (!fn.match(/.js$/)) {
263 var sp = dir.split('/');
264 sp = sp.splice(sp.length - (dp +1), (dp +1));
265 parent = sp.join('.');
268 if (typeof(this.files[dir + '/' + fn]) != 'undefined') {
269 // we already have it..
270 this.files[dir + '/' + fn].parent = parent;
274 var cls = imports.Builder.Provider.File[xt][xt];
276 Seed.print("Adding file " + dir + '/' + fn);
277 this.files[dir + '/' + fn] = new cls({
278 path : dir + '/' + fn,
282 var f = Gio.file_new_for_path(dir + '/' + fn);
283 var inf = f.query_info('standard::*');
284 var tv = new GLib.TimeVal();
285 inf.get_modification_time(tv);
287 // should it do something about this information..
288 // fixme... time data is busted..
289 this.files[dir + '/' + fn] = '' + tv.tv_sec + '.' + tv.tv_usec;