|
|
@@ -4,47 +4,41 @@ class Preferences {
|
|
|
private fileSystem: Atomic.FileSystem;
|
|
|
|
|
|
private static instance: Preferences;
|
|
|
- private _androidSDKPath: string;
|
|
|
- private _jdkRootPath: string;
|
|
|
- private _antPath: string;
|
|
|
-
|
|
|
- private _recentProjects: [string];
|
|
|
+ private _prefs: PreferencesFormat;
|
|
|
|
|
|
constructor() {
|
|
|
this.fileSystem = Atomic.getFileSystem();
|
|
|
Preferences.instance = this;
|
|
|
-
|
|
|
- this._recentProjects = [""];
|
|
|
}
|
|
|
|
|
|
registerRecentProject(path: string): void {
|
|
|
- var index = this._recentProjects.indexOf(path);
|
|
|
+ var index = this._prefs.recentProjects.indexOf(path);
|
|
|
if (index >= 0) {
|
|
|
- this._recentProjects.splice(index, 1);
|
|
|
+ this._prefs.recentProjects.splice(index, 1);
|
|
|
}
|
|
|
- this._recentProjects.unshift(path);
|
|
|
+ this._prefs.recentProjects.unshift(path);
|
|
|
this.updateRecentProjects();
|
|
|
}
|
|
|
|
|
|
unRegisterRecentProject(path: string): void {
|
|
|
- var index = this._recentProjects.indexOf(path);
|
|
|
+ var index = this._prefs.recentProjects.indexOf(path);
|
|
|
if (index >= 0) {
|
|
|
- this._recentProjects.splice(index, 1);
|
|
|
+ this._prefs.recentProjects.splice(index, 1);
|
|
|
}
|
|
|
this.updateRecentProjects();
|
|
|
}
|
|
|
|
|
|
updateRecentProjects(): void {
|
|
|
- for (var i in this._recentProjects) {
|
|
|
- var path = this._recentProjects[i];
|
|
|
+ for (var i in this._prefs.recentProjects) {
|
|
|
+ var path = this._prefs.recentProjects[i];
|
|
|
if (!this.fileSystem.exists(path)) {
|
|
|
- this._recentProjects.splice(i, 1);
|
|
|
+ this._prefs.recentProjects.splice(i, 1);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
deleteRecentProjects(): void {
|
|
|
- this._recentProjects.length = 0;
|
|
|
+ this._prefs.recentProjects.length = 0;
|
|
|
}
|
|
|
|
|
|
getPreferencesFullPath(): string {
|
|
|
@@ -58,18 +52,16 @@ class Preferences {
|
|
|
var jsonFile = new Atomic.File(filePath, Atomic.FILE_READ);
|
|
|
if (!jsonFile.isOpen()) return;
|
|
|
var prefs = <PreferencesFormat> JSON.parse(jsonFile.readText());
|
|
|
- this._recentProjects = prefs.recentFiles || [""];
|
|
|
- this._androidSDKPath = prefs.androidSdkPath;
|
|
|
- this._jdkRootPath = prefs.jdkRootPath;
|
|
|
- this._antPath = prefs.antPath;
|
|
|
+ if (prefs) {
|
|
|
+ if(!prefs.recentProjects) prefs.recentProjects = [""];
|
|
|
+ this._prefs = prefs;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
write(): void {
|
|
|
var filePath = this.getPreferencesFullPath();
|
|
|
var jsonFile = new Atomic.File(filePath, Atomic.FILE_WRITE);
|
|
|
if (!jsonFile.isOpen()) return;
|
|
|
- var prefs = new PreferencesFormat();
|
|
|
- prefs.recentFiles = this._recentProjects;
|
|
|
var graphics = Atomic.getGraphics();
|
|
|
var pos, width, height;
|
|
|
if (graphics && !graphics.getFullscreen()) {
|
|
|
@@ -77,41 +69,38 @@ class Preferences {
|
|
|
width = graphics.getWidth();
|
|
|
height = graphics.getHeight();
|
|
|
}
|
|
|
- prefs.window = { x: pos[0], y: pos[1], width: width, height: height };
|
|
|
- prefs.androidSdkPath = this._androidSDKPath;
|
|
|
- prefs.jdkRootPath = this._jdkRootPath;
|
|
|
- prefs.antPath = this._antPath;
|
|
|
- jsonFile.writeString(JSON.stringify(prefs, null, 2));
|
|
|
+ this._prefs.window = { x: pos[0], y: pos[1], width: width, height: height };
|
|
|
+ jsonFile.writeString(JSON.stringify(this._prefs, null, 2));
|
|
|
}
|
|
|
|
|
|
get recentProjects(): [string] {
|
|
|
- return this._recentProjects;
|
|
|
+ return this._prefs.recentProjects;
|
|
|
}
|
|
|
|
|
|
- get androidSdkPath(): string {
|
|
|
- return Atomic.addTrailingSlash(this._androidSDKPath);
|
|
|
+ get androidSDKPath(): string {
|
|
|
+ return Atomic.addTrailingSlash(this._prefs.androidSDKPath);
|
|
|
}
|
|
|
|
|
|
- set androidSdkPath(path: string) {
|
|
|
- this._androidSDKPath = path;
|
|
|
+ set androidSDKPath(path: string) {
|
|
|
+ this._prefs.androidSDKPath = path;
|
|
|
this.write()
|
|
|
}
|
|
|
|
|
|
get jdkRootPath(): string {
|
|
|
- return Atomic.addTrailingSlash(this._jdkRootPath);
|
|
|
+ return Atomic.addTrailingSlash(this._prefs.jdkRootPath);
|
|
|
}
|
|
|
|
|
|
set jdkRootPath(path: string) {
|
|
|
- this._jdkRootPath = path;
|
|
|
+ this._prefs.jdkRootPath = path;
|
|
|
this.write();
|
|
|
}
|
|
|
|
|
|
get antPath(): string {
|
|
|
- return Atomic.addTrailingSlash(this._antPath);
|
|
|
+ return Atomic.addTrailingSlash(this._prefs.antPath);
|
|
|
}
|
|
|
|
|
|
- set andPath(path: string) {
|
|
|
- this._antPath = path;
|
|
|
+ set antPath(path: string) {
|
|
|
+ this._prefs.antPath = path;
|
|
|
this.write();
|
|
|
}
|
|
|
|
|
|
@@ -121,8 +110,8 @@ class Preferences {
|
|
|
}
|
|
|
|
|
|
class PreferencesFormat {
|
|
|
- recentFiles: [string];
|
|
|
- androidSdkPath: string;
|
|
|
+ recentProjects: [string];
|
|
|
+ androidSDKPath: string;
|
|
|
jdkRootPath: string;
|
|
|
antPath: string;
|
|
|
window: { x: number, y: number, width: number, height: number };
|