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);
61 getPalete : function()
63 print("GET PROVIDER FOR " + this.xtype);
64 return ProjectManager.getPalete(this.xtype);
70 ['id', 'fn', 'paths', 'xtype', 'name'].forEach( function(k) {
76 for (var f in this.files) {
78 ret.files[f] = this.files[f].toJsonArray();
82 return JSON.stringify(ret);
90 // normally this will build tree's based on info in the file stuff..
91 // but for the time being, we just return an array of all the files.
101 for (var f in this.files) {
102 this.tree.push(this.files[f]);
107 // have parents -> add them to parent...
110 for (var k in this.files) {
111 var f = this.files[k];
114 //console.log(f.name);
116 files[f.fullname] = f;
120 // add Parent pointer..
121 for (var k in this.files) {
122 var f = this.files[k];
123 console.log(f.parent + ":" + f.name);
124 if (f.parent && typeof(files[f.parent]) != 'undefined') {
127 files[f.parent].cn.push(f);
138 for (var k in this.files) {
139 var f = this.files[k];
145 if (typeof(files[f.fullname]) != 'undefined') {
152 ret.sort(function(a,b) {
153 return a.path > b.path ? 1 : -1;
160 getById : function(id)
163 for (var k in this.files) {
164 var f = this.files[k];
166 console.log(f.id + '?=' + id);
174 loadFileOnly : function(path)
178 var cls = imports.Builder.Provider.File[xt][xt];
184 create : function(filename)
186 var ret = this.loadFileOnly(filename);
194 addFile: function(pfile) { // add a single file, and trigger changed.
195 this.files[pfile.path] = pfile
196 this.fireEvent('changed', this);
199 add: function(path, type)
201 this.paths = this.paths || { };
202 this.paths[path] = type;
203 //Seed.print(" type is '" + type + "'");
206 // console.dump(this.files);
208 if (type == 'file' ) {
210 this.files[path] = this.loadFileOnly( path );
213 console.dump(this.files);
214 this.fireEvent('changed', this);
220 this.files = this.files || { };
221 for (var d in this.paths) {
222 if (this.paths[d] == 'dir') {
225 // otherwise add a file..
227 //console.dump(this.files);
233 scanDir : function(dir, dp)
236 Seed.print("Running scandir on " + dir);
237 if (dp > 5) { // no more than 5 deep?
240 // this should be done async -- but since we are getting the proto up ...
241 var gdir = GLib.dir_open(dir,0);
245 var fn = GLib.dir_read_name(gdir);
246 //console.log('trying ' + path + '/' + fn);
248 GLib.dir_close(gdir);
249 subs.forEach( function(s) {
250 _this.scanDir(s, dp+1);
254 if (fn[0] == '.') { // skip hidden
258 if (GLib.file_test(dir + '/' + fn, GLib.FileTest.IS_DIR)) {
259 subs.push(dir + '/' + fn);
263 if (!fn.match(/.bjs$/)) {
268 var sp = dir.split('/');
269 sp = sp.splice(sp.length - (dp +1), (dp +1));
270 parent = sp.join('.');
273 if (typeof(this.files[dir + '/' + fn]) != 'undefined') {
274 // we already have it..
275 this.files[dir + '/' + fn].parent = parent;
279 var cls = imports.Builder.Provider.File[xt][xt];
281 Seed.print("Adding file " + dir + '/' + fn);
282 this.files[dir + '/' + fn] = new cls({
283 path : dir + '/' + fn,
287 var f = Gio.file_new_for_path(dir + '/' + fn);
288 var inf = f.query_info('standard::*');
289 var tv = new GLib.TimeVal();
290 inf.get_modification_time(tv);
292 // should it do something about this information..
293 // fixme... time data is busted..
294 this.files[dir + '/' + fn] = '' + tv.tv_sec + '.' + tv.tv_usec;