forked from humphd/brackets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStateManager.js
More file actions
109 lines (100 loc) · 3.58 KB
/
Copy pathStateManager.js
File metadata and controls
109 lines (100 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*global define*/
/*jslint bitwise: true */
define(function() {
"use strict";
var memoryStorage = {
_items: {},
getItem: function(key) {
return memoryStorage._items[key];
},
setItem: function(key, value) {
// Mimic localStorage string storage
value = "" + value;
memoryStorage._items[key] = value;
},
clear: function() {
memoryStorage._items = {};
}
};
var localStorage = (function(window) {
if(typeof window.localStorage === 'undefined') {
return memoryStorage;
}
return window.localStorage;
}(window));
function prefix(name) {
return "bramble-property::" + name;
}
function getString(storage, property) {
var val = storage.getItem(prefix(property));
return val || null;
}
function getBool(storage, property) {
var str = getString(storage, property);
if(str === "true") {
return true;
} else if(str === "false") {
return false;
} else {
// not set
return null;
}
}
function getInt(storage, property) {
var str = getString(storage, property);
return str|0;
}
function StateManager(disableStorage) {
var storage;
if(disableStorage) {
// Wipe any data we have in storage now and use memory
localStorage.clear();
storage = memoryStorage;
} else {
storage = localStorage;
}
Object.defineProperties(this, {
fontSize: {
get: function() { return getString(storage, "fontSize"); },
set: function(v) { storage.setItem(prefix("fontSize"), v); }
},
theme: {
get: function() { return getString(storage, "theme"); } ,
set: function(v) { storage.setItem(prefix("theme"), v); }
},
sidebarVisible: {
get: function() { return getBool(storage, "sidebarVisible"); },
set: function(v) { storage.setItem(prefix("sidebarVisible"), v); }
},
sidebarWidth: {
get: function() { return getInt(storage, "sidebarWidth"); },
set: function(v) { storage.setItem(prefix("sidebarWidth"), v); }
},
firstPaneWidth: {
get: function() { return getInt(storage, "firstPaneWidth"); },
set: function(v) { storage.setItem(prefix("firstPaneWidth"), v); }
},
secondPaneWidth: {
get: function() { return getInt(storage, "secondPaneWidth"); },
set: function(v) { storage.setItem(prefix("secondPaneWidth"), v); }
},
previewMode: {
get: function() { return getString(storage, "previewMode"); },
set: function(v) { storage.setItem(prefix("previewMode"), v); }
},
filename: {
get: function() { return getString(storage, "filename"); },
set: function(v) { storage.setItem(prefix("filename"), v); }
},
fullPath: {
get: function() { return getString(storage, "fullPath"); },
set: function(v) { storage.setItem(prefix("fullPath"), v); }
},
wordWrap: {
get: function() { return getBool(storage, "wordWrap"); },
set: function(v) { storage.setItem(prefix("wordWrap"), v); }
}
});
}
return StateManager;
});