1 //<Script type="text/javascript">
3 GLib = imports.gi.GLib;
6 console = imports.console;
7 XObject = imports.XObject.XObject;
9 Observable = imports.Observable.Observable;
10 File = imports.File.File;
13 * /home/alan/.BuilderConfig/*
18 ProjectManager = new Observable({
26 'changed' : function() {
36 loadConfig : function ()
38 // we can not do this async....
39 this.dirname = GLib.get_home_dir() + '/.Builder';
41 var dir = Gio.file_new_for_path(this.dirname);
42 if (!dir.query_exists()) {
48 var files = File.list(this.dirname);
51 //print(files);Seed.quit();
52 for (var i =0 ; i < files.length;i++) {
55 if (!fn.match(/.json$/)) {
58 var str = File.read(this.dirname + '/' + fn);
59 if (!str || !str.length) {
60 continue; // empty file.
64 var ar = JSON.parse(str);
68 var cls = imports.Project[ar.xtype][ar.xtype];
69 this.projects.push( new cls(ar));
77 print(JSON.stringify(this.projects.length));Seed.quit();
79 this.projects.sort(function(a,b) {
80 if (a.getName() == b.getName()) {
83 return a.getName() > b.getName() ? 1 : -1;
99 saveConfig : function()
102 this.projects.forEach( function(p) {
105 // make the filename..
106 var t = new GLib.TimeVal();
107 GLib.get_current_time(t);
108 var str = '' + t.tv_sec + ':' + t.tv_usec;
110 p.fn = GLib.compute_checksum_for_string(GLib.ChecksumType.MD5, str, str.length);
115 File.write(_this.dirname + '/' + p.fn + '.json', s);
124 update : function(proj) {
126 Seed.print(JSON.stringify(proj));
128 this.projects.forEach( function(p) {
135 this.fireEvent('changed', this);
139 var cls = imports.Project[proj.xtype][proj.xtype];
140 var pr = new cls(proj);
141 this.projects.push(pr );
142 this.fireEvent('changed', this);
148 deleteProject : function (fn)
152 this.projects.forEach(function(p) {
157 var file = _this.dirname + '/' + p.fn + '.json';
158 if (File.exists(file)) {
163 this.projects = newplist;
164 this.fireEvent('changed', this);
168 getByFn : function (fn) {
170 this.projects.forEach(function(p) {
179 getPalete: function(type) {
180 if (typeof(ProjectManager.palete[type]) != 'undefined') {
181 //print ("ALREADY GOT " + type);
182 return ProjectManager.palete[type];
184 var cls = imports.Palete[type][type];
186 ProjectManager.palete[type] = new cls();
187 print (typeof(ProjectManager.palete[type]));
188 return ProjectManager.palete[type];