-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathstorage.js
More file actions
119 lines (97 loc) · 2.97 KB
/
Copy pathstorage.js
File metadata and controls
119 lines (97 loc) · 2.97 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
110
111
112
113
114
115
116
117
118
119
CodeBoot.prototype.clearSession = function () {
localStorage.removeItem('codeboot');
};
CodeBoot.prototype.saveSession = function () {
cb.fs = cb.savedFs;
var state = cb.serializeState();
localStorage['codeboot'] = JSON.stringify(state);
};
CodeBoot.prototype.loadSession = function () {
var state = localStorage['codeboot'];
if (state) {
cb.fs.init();
cb.restoreState(JSON.parse(state));
}
};
CodeBoot.prototype.serializeState = function () {
var state = {
tabs: [],
repl: {
history: undefined
},
languageLevel: cb.languageLevel,
devMode: cb.devMode,
animationSpeed: cb.animationSpeed,
options: cb.options,
macros: cb.mm.macros // Save binded macros
};
state.repl.history = cb.repl.cb.history.serializeState();
state.files = cb.fs.serialize();
state.openEditors = [];
cb.fs.forEachEditor(function (editor) {
state.openEditors.push(editor.file.filename);
});
state.activeEditor = null;
if (cb.fs.editorManager.activated >= 0) {
state.activeEditor = cb.fs.editorManager.editors[cb.fs.editorManager.activated].file.filename;
}
return state;
};
function cb_internal_attempt(operation) {
try {
operation();
return true;
} catch (e) {
return false;
}
}
CodeBoot.prototype.restoreState = function (state) {
if (state === undefined) return;
var failed = false;
if (state.options) {
cb.options = state.options;
}
if (state.macros) {
cb.mm.macros = state.macros;
}
failed = cb_internal_attempt(function () {
cb.repl.cb.history.restoreState(state.repl.history);
}) || failed;
failed = cb_internal_attempt(function () {
cb.setLanguageLevel(state.languageLevel || 'novice');
}) || failed;
failed = cb_internal_attempt(function () {
cb.setDevMode(!!state.devMode);
}) || failed;
failed = cb_internal_attempt(function () {
cb.setAnimationSpeed(state.animationSpeed);
}) || failed;
failed = cb_internal_attempt(function () {
cb.setShowLineNumbers(!!state.options.showLineNumbers);
}) || failed;
failed = cb_internal_attempt(function () {
cb.setLargeFont(!!state.options.largeFont);
}) || failed;
if (state.files) {
failed = cb_internal_attempt(function () {
cb.fs.restore(state.files);
cb.fs.rebuildFileMenu();
}) || failed;
}
if (state.openEditors) {
failed = cb_internal_attempt(function () {
state.openEditors.forEach(function (filename) {
cb.fs.openFile(filename);
});
}) || failed;
}
if (state.activeEditor) {
failed = cb_internal_attempt(function () {
var file = cb.fs._asFile(state.activeEditor);
file.editor.activate();
}) || failed;
}
if (failed) {
cb.reportError('Failed to restore state');
}
};