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) {
61 continue; // empty file.
65 var ar = JSON.parse(str);
69 var cls = imports.Project[ar.xtype][ar.xtype];
70 this.projects.push( new cls(ar));
78 // print(JSON.stringify(this.projects.length));Seed.quit();
80 this.projects.sort(function(a,b) {
81 if (a.getName() == b.getName()) {
84 return a.getName() > b.getName() ? 1 : -1;
100 saveConfig : function()
103 this.projects.forEach( function(p) {
106 // make the filename..
107 var t = new GLib.TimeVal();
108 GLib.get_current_time(t);
109 var str = '' + t.tv_sec + ':' + t.tv_usec;
111 p.fn = GLib.compute_checksum_for_string(GLib.ChecksumType.MD5, str, str.length);
116 File.write(_this.dirname + '/' + p.fn + '.json', s);
125 update : function(proj) {
127 //Seed.print(JSON.stringify(proj));
129 this.projects.forEach( function(p) {
136 this.fireEvent('changed', this);
140 var cls = imports.Project[proj.xtype][proj.xtype];
141 var pr = new cls(proj);
142 this.projects.push(pr );
143 this.fireEvent('changed', this);
149 deleteProject : function (fn)
153 this.projects.forEach(function(p) {
158 var file = _this.dirname + '/' + p.fn + '.json';
159 if (File.exists(file)) {
164 this.projects = newplist;
165 this.fireEvent('changed', this);
169 getByFn : function (fn) {
171 this.projects.forEach(function(p) {
180 getPalete: function(type) {
181 if (typeof(ProjectManager.palete[type]) != 'undefined') {
182 //print ("ALREADY GOT " + type);
183 return ProjectManager.palete[type];
185 var cls = imports.Palete[type][type];
187 ProjectManager.palete[type] = new cls();
188 print (typeof(ProjectManager.palete[type]));
189 return ProjectManager.palete[type];