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;
12 Base = XObject.define(
16 this.addEvents({ 'changed' : true });
18 this.on('changed' , function() {
19 Seed.print("Calling PM - changed");
21 ProjectManager.onChanged();
23 XObject.extend(this, cfg);
27 for (var f in this.files) {
29 var cls = imports.Builder.Provider.File[xt][xt];
30 this.files[f] = cls(this.files[f]);
49 if (!this.fetchTree) {
50 console.log("Project.getTree tree called on base object?!?!");
55 return o.success.apply(o.scope || this, [this]);
57 return this.fetchTree(o);
65 ['id', 'fn', 'paths', 'xtype', 'name'].forEach( function(k) {
71 for (var f in this.files) {
72 ret.files[f] = this.files[f].toJsonArray();
76 return JSON.stringify(ret);
84 // normally this will build tree's based on info in the file stuff..
85 // but for the time being, we just return an array of all the files.
95 for (var f in this.files) {
96 this.tree.push(this.files[f]);
101 // have parents -> add them to parent...
104 for (var k in this.files) {
105 var f = this.files[k];
108 //console.log(f.name);
110 files[f.fullname] = f;
114 // add Parent pointer..
115 for (var k in this.files) {
116 var f = this.files[k];
117 console.log(f.parent + ":" + f.name);
118 if (f.parent && typeof(files[f.parent]) != 'undefined') {
121 files[f.parent].cn.push(f);
132 for (var k in this.files) {
133 var f = this.files[k];
139 if (typeof(files[f.fullname]) != 'undefined') {
146 ret.sort(function(a,b) {
147 return a.path > b.path ? 1 : -1;
154 getById : function(id)
157 for (var k in this.files) {
158 var f = this.files[k];
160 console.log(f.id + '?=' + id);
168 loadFileOnly : function(path)
172 var cls = imports.Builder.Provider.File[xt][xt];
179 addFile: function(pfile) { // add a single file, and trigger changed.
180 this.files[pfile.path] = pfile
181 this.fireEvent('changed', this);
184 add: function(path, type)
186 this.paths = this.paths || { };
187 this.paths[path] = type;
188 //Seed.print(" type is '" + type + "'");
191 // console.dump(this.files);
193 if (type == 'file' ) {
195 this.files[path] = this.loadFileOnly( path );
198 console.dump(this.files);
199 this.fireEvent('changed', this);
205 this.files = this.files || { };
206 for (var d in this.paths) {
207 if (this.paths[d] == 'dir') {
210 // otherwise add a file..
212 //console.dump(this.files);
218 scanDir : function(dir, dp)
221 Seed.print("Running scandir on " + dir);
222 if (dp > 5) { // no more than 5 deep?
225 // this should be done async -- but since we are getting the protvgo up..
226 var gdir = GLib.dir_open(dir,0);
229 var fn = GLib.dir_read_name(gdir);
230 //console.log('trying ' + path + '/' + fn);
232 GLib.dir_close(gdir);
233 Roo.each(subs, function(s) {
234 this.scanDir(s, dp+1);
238 if (fn[0] == '.') { // skip hidden
242 if (GLib.file_test(dir + '/' + fn, GLib.FileTest.IS_DIR)) {
243 subs.push(dir + '/' + fn);
247 if (!fn.match(/.js$/)) {
252 var sp = dir.split('/');
253 sp = sp.splice(sp.length - (dp +1), (dp +1));
254 parent = sp.join('.');
257 if (typeof(this.files[dir + '/' + fn]) != 'undefined') {
258 // we already have it..
259 this.files[dir + '/' + fn].parent = parent;
263 var cls = imports.Builder.Provider.File[xt][xt];
265 Seed.print("Adding file " + dir + '/' + fn);
266 this.files[dir + '/' + fn] = new cls({
267 path : dir + '/' + fn,
271 var f = Gio.file_new_for_path(dir + '/' + fn);
272 var inf = f.query_info('standard::*');
273 var tv = new GLib.TimeVal();
274 inf.get_modification_time(tv);
276 // should it do something about this information..
277 // fixme... time data is busted..
278 this.files[dir + '/' + fn] = '' + tv.tv_sec + '.' + tv.tv_usec;