1 //<Script type="text/javascript">
3 GLib = imports.gi.GLib;
4 console = imports['console.js'];
6 Roo = imports['Roo.js'];
10 Builder = imports['Builder.js']
15 * /home/alan/.BuilderConfig/*
20 Builder.Provider.ProjectManager = new Roo.Observable({
28 'changed' : function() {
38 loadConfig : function ()
40 // we can not do this async....
41 this.dirname = GLib.get_home_dir() + '/.Builder';
43 var dir = Gio.file_new_for_path(this.dirname);
44 if (!dir.query_exists()) {
52 var gdir = GLib.dir_open(this.dirname,0);
55 var fn = GLib.dir_read_name(gdir);
60 if (!fn.match(/.json$/)) {
63 var file = Gio.file_new_for_path(this.dirname + '/' + fn);
64 Seed.print(this.dirname + '/' + fn);
65 var stream = file.read();
66 var dstream = new Gio.DataInputStream.c_new(stream);
69 str = dstream.read_until("");
70 if (!str || !str.length) {
71 continue; // empty file.
75 var ar = JSON.parse(str);
80 this.projects.push( new Builder.Provider.Project[ar.xtype](ar));
99 saveConfig : function()
101 Roo.each(this.projects, function(p) {
104 // make the filename..
105 var t = new GLib.TimeVal();
106 GLib.get_current_time(t);
107 var str = '' + t.tv_sec + ':' + t.tv_usec;
109 p.fn = GLib.compute_checksum_for_string(GLib.ChecksumType.MD5, str, str.length);
115 var file = Gio.file_new_for_path(this.dirname + '/' + p.fn + '.json');
117 var stream = file.replace(null,false,0);
119 stream.write(s, s.length);
129 update : function(proj) {
131 Seed.print(JSON.stringify(proj));
133 Roo.each(this.projects , function(p) {
140 this.fireEvent('changed', this);
144 var pr = new Builder.Provider.Project[proj.xtype](proj);
145 this.projects.push(pr );
146 this.fireEvent('changed', this);
151 getByFn : function (fn) {
153 Roo.each(this.projects, function(p) {