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);
49 for (var i =0 ; i < files.length;i++) {
52 if (!fn.match(/.json$/)) {
55 var str = File.read(this.dirname + '/' + fn);
56 if (!str || !str.length) {
57 continue; // empty file.
61 var ar = JSON.parse(str);
65 var cls = imports.Project[ar.xtype][ar.xtype];
66 this.projects.push( new cls(ar));
75 this.projects.sort(function(a,b) {
76 if (a.getName() == b.getName()) {
79 return a.getName() > b.getName() ? 1 : -1;
95 saveConfig : function()
98 this.projects.forEach( function(p) {
101 // make the filename..
102 var t = new GLib.TimeVal();
103 GLib.get_current_time(t);
104 var str = '' + t.tv_sec + ':' + t.tv_usec;
106 p.fn = GLib.compute_checksum_for_string(GLib.ChecksumType.MD5, str, str.length);
111 File.write(_this.dirname + '/' + p.fn + '.json', s);
120 update : function(proj) {
122 Seed.print(JSON.stringify(proj));
124 this.projects.forEach( function(p) {
131 this.fireEvent('changed', this);
135 var cls = imports.Project[proj.xtype][proj.xtype];
136 var pr = new cls(proj);
137 this.projects.push(pr );
138 this.fireEvent('changed', this);
144 deleteProject : function (fn)
148 this.projects.forEach(function(p) {
153 var file = _this.dirname + '/' + p.fn + '.json';
154 if (File.exists(file)) {
159 this.projects = newplist;
160 this.fireEvent('changed', this);
164 getByFn : function (fn) {
166 this.projects.forEach(function(p) {
175 getPalete: function(type) {
176 if (typeof(ProjectManager.palete[type]) != 'undefined') {
177 //print ("ALREADY GOT " + type);
178 return ProjectManager.palete[type];
180 var cls = imports.Palete[type][type];
182 ProjectManager.palete[type] = new cls();
183 print (typeof(ProjectManager.palete[type]));
184 return ProjectManager.palete[type];