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;
21 ProjectManager = imports.Builder.Provider.ProjectManager.ProjectManager;
22 Observable = imports.Observable.Observable;
24 Base = XObject.define(
28 this.addEvents({ 'changed' : true });
30 this.on('changed' , function() {
31 Seed.print("Calling PM - changed");
33 ProjectManager.fireEvent('changed');
35 XObject.extend(this, cfg);
39 for (var f in this.files) {
41 var cls = imports.Builder.Provider.File[xt][xt];
42 this.files[f] = cls(this.files[f]);
54 fn: false, // the md5 sum for this one..
60 load : function (o) // is this used??
62 if (!this.fetchTree) {
63 console.log("Project.getTree tree called on base object?!?!");
68 return o.success.apply(o.scope || this, [this]);
70 return this.fetchTree(o);
73 getPalete : function()
75 print("GET PROVIDER FOR " + this.xtype);
76 return ProjectManager.getPalete(this.xtype);
82 for (var k in _this) {
84 if (['files', 'tree'].indexOf(k) > -1) {
88 if ((typeof(_this[k]) == 'object') ||(typeof(_this[k]) == 'function')) {
92 print("Storing " + k);
99 //for (var f in this.files) {
101 // ret.files[f] = this.files[f].toJsonArray();
105 return JSON.stringify(ret);
111 //returns the basename of the first path..
112 for (var i in this.paths) {
113 return GLib.basename(i);
121 // normally this will build tree's based on info in the file stuff..
122 // but for the time being, we just return an array of all the files.
132 for (var f in this.files) {
133 this.tree.push(this.files[f]);
138 // have parents -> add them to parent...
141 for (var k in this.files) {
143 var f = this.files[k];
150 //console.log(f.name);
152 files[f.fullname] = f;
156 // add Parent pointer..
157 for (var k in this.files) {
158 var f = this.files[k];
159 console.log(f.parent + ":" + f.name);
160 if (f.parent && typeof(files[f.parent]) != 'undefined') {
163 files[f.parent].cn.push(f);
174 for (var k in this.files) {
175 var f = this.files[k];
181 if (typeof(files[f.fullname]) != 'undefined') {
188 ret.sort(function(a,b) {
189 return a.path > b.path ? 1 : -1;
196 getById : function(id)
199 for (var k in this.files) {
200 var f = this.files[k];
202 console.log(f.id + '?=' + id);
210 loadFileOnly : function(path)
214 var cls = imports.Builder.Provider.File[xt][xt];
221 create : function(filename)
223 var ret = this.loadFileOnly(filename);
231 addFile: function(pfile) { // add a single file, and trigger changed.
232 this.files[pfile.path] = pfile
233 this.fireEvent('changed', this);
236 add: function(path, type)
238 this.paths = this.paths || { };
239 this.paths[path] = type;
240 //Seed.print(" type is '" + type + "'");
243 // console.dump(this.files);
245 if (type == 'file' ) {
247 this.files[path] = this.loadFileOnly( path );
250 // console.dump(this.files);
251 this.fireEvent('changed', this);
257 this.files = this.files || { };
258 for (var d in this.paths) {
259 if (this.paths[d] == 'dir') {
262 // otherwise add a file..
264 //console.dump(this.files);
270 scanDir : function(dir, dp)
273 Seed.print("Running scandir on " + dir);
274 if (dp > 5) { // no more than 5 deep?
277 // this should be done async -- but since we are getting the proto up ...
278 var gdir = GLib.dir_open(dir,0);
282 var fn = gdir.read_name();
283 console.log('trying ' + dir + '/' + fn);
286 subs.forEach( function(s) {
287 _this.scanDir(s, dp+1);
291 if (fn[0] == '.') { // skip hidden
295 if (GLib.file_test(dir + '/' + fn, GLib.FileTest.IS_DIR)) {
296 subs.push(dir + '/' + fn);
300 if (!fn.match(/\.bjs$/)) {
305 var sp = dir.split('/');
306 sp = sp.splice(sp.length - (dp +1), (dp +1));
307 parent = sp.join('.');
310 if (typeof(this.files[dir + '/' + fn]) != 'undefined') {
311 // we already have it..
312 this.files[dir + '/' + fn].parent = parent;
316 var cls = imports.Builder.Provider.File[xt][xt];
318 Seed.print("Adding file " + dir + '/' + fn);
319 this.files[dir + '/' + fn] = new cls({
320 path : dir + '/' + fn,
324 //console.log(this.files[dir + '/' + fn] );
326 var f = Gio.file_new_for_path(dir + '/' + fn);
327 var inf = f.query_info('standard::*');
328 var tv = new GLib.TimeVal();
329 inf.get_modification_time(tv);
331 // should it do something about this information..
332 // fixme... time data is busted..
333 this.files[dir + '/' + fn] = '' + tv.tv_sec + '.' + tv.tv_usec;