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) {
112 var f = this.files[k];
119 //console.log(f.name);
121 files[f.fullname] = f;
125 // add Parent pointer..
126 for (var k in this.files) {
127 var f = this.files[k];
128 console.log(f.parent + ":" + f.name);
129 if (f.parent && typeof(files[f.parent]) != 'undefined') {
132 files[f.parent].cn.push(f);
143 for (var k in this.files) {
144 var f = this.files[k];
150 if (typeof(files[f.fullname]) != 'undefined') {
157 ret.sort(function(a,b) {
158 return a.path > b.path ? 1 : -1;
165 getById : function(id)
168 for (var k in this.files) {
169 var f = this.files[k];
171 console.log(f.id + '?=' + id);
179 loadFileOnly : function(path)
183 var cls = imports.Builder.Provider.File[xt][xt];
189 create : function(filename)
191 var ret = this.loadFileOnly(filename);
199 addFile: function(pfile) { // add a single file, and trigger changed.
200 this.files[pfile.path] = pfile
201 this.fireEvent('changed', this);
204 add: function(path, type)
206 this.paths = this.paths || { };
207 this.paths[path] = type;
208 //Seed.print(" type is '" + type + "'");
211 // console.dump(this.files);
213 if (type == 'file' ) {
215 this.files[path] = this.loadFileOnly( path );
218 console.dump(this.files);
219 this.fireEvent('changed', this);
225 this.files = this.files || { };
226 for (var d in this.paths) {
227 if (this.paths[d] == 'dir') {
230 // otherwise add a file..
232 //console.dump(this.files);
238 scanDir : function(dir, dp)
241 Seed.print("Running scandir on " + dir);
242 if (dp > 5) { // no more than 5 deep?
245 // this should be done async -- but since we are getting the proto up ...
246 var gdir = GLib.dir_open(dir,0);
250 var fn = GLib.dir_read_name(gdir);
251 console.log('trying ' + dir + '/' + fn);
253 GLib.dir_close(gdir);
254 subs.forEach( function(s) {
255 _this.scanDir(s, dp+1);
259 if (fn[0] == '.') { // skip hidden
263 if (GLib.file_test(dir + '/' + fn, GLib.FileTest.IS_DIR)) {
264 subs.push(dir + '/' + fn);
268 if (!fn.match(/\.bjs$/)) {
273 var sp = dir.split('/');
274 sp = sp.splice(sp.length - (dp +1), (dp +1));
275 parent = sp.join('.');
278 if (typeof(this.files[dir + '/' + fn]) != 'undefined') {
279 // we already have it..
280 this.files[dir + '/' + fn].parent = parent;
284 var cls = imports.Builder.Provider.File[xt][xt];
286 Seed.print("Adding file " + dir + '/' + fn);
287 this.files[dir + '/' + fn] = new cls({
288 path : dir + '/' + fn,
291 console.log(this.files[dir + '/' + fn] );
293 var f = Gio.file_new_for_path(dir + '/' + fn);
294 var inf = f.query_info('standard::*');
295 var tv = new GLib.TimeVal();
296 inf.get_modification_time(tv);
298 // should it do something about this information..
299 // fixme... time data is busted..
300 this.files[dir + '/' + fn] = '' + tv.tv_sec + '.' + tv.tv_usec;