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));
78 this.projects.sort(function(a,b) {
79 if (a.getName() == b.getName()) {
82 return a.getName() > b.getName() ? 1 : -1;
98 saveConfig : function()
101 this.projects.forEach( 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);
114 File.write(_this.dirname + '/' + p.fn + '.json', s);
123 update : function(proj) {
125 Seed.print(JSON.stringify(proj));
127 this.projects.forEach( function(p) {
134 this.fireEvent('changed', this);
138 var cls = imports.Project[proj.xtype][proj.xtype];
139 var pr = new cls(proj);
140 this.projects.push(pr );
141 this.fireEvent('changed', this);
147 deleteProject : function (fn)
151 this.projects.forEach(function(p) {
156 var file = _this.dirname + '/' + p.fn + '.json';
157 if (File.exists(file)) {
162 this.projects = newplist;
163 this.fireEvent('changed', this);
167 getByFn : function (fn) {
169 this.projects.forEach(function(p) {
178 getPalete: function(type) {
179 if (typeof(ProjectManager.palete[type]) != 'undefined') {
180 //print ("ALREADY GOT " + type);
181 return ProjectManager.palete[type];
183 var cls = imports.Palete[type][type];
185 ProjectManager.palete[type] = new cls();
186 print (typeof(ProjectManager.palete[type]));
187 return ProjectManager.palete[type];