Permalink
Browse files

save indentation preferences. add new default prefs when missing

  • Loading branch information...
1 parent 6f38c6a commit 03b949b74e4d1beca1260b15e1f08cbd55c8dd08 @jasonsanjose jasonsanjose committed Oct 8, 2012
Showing with 22 additions and 20 deletions.
  1. +15 −20 src/editor/EditorManager.js
  2. +7 −0 src/preferences/PreferencesManager.js
@@ -588,30 +588,24 @@ define(function (require, exports, module) {
$fileInfo.text(StringUtils.format(Strings.STATUSBAR_LINE_COUNT, editor.lineCount()));
}
- function _updateIndentInfo(editor) {
- var indentWithTabs = editor._codeMirror.getOption("indentWithTabs");
+ function _updateIndentType() {
+ var indentWithTabs = Editor.getUseTabChar();
$indentType.text(indentWithTabs ? Strings.STATUSBAR_TAB_SIZE : Strings.STATUSBAR_SPACES);
$indentType.attr("title", indentWithTabs ? Strings.STATUSBAR_INDENT_TOOLTIP_SPACES : Strings.STATUSBAR_INDENT_TOOLTIP_TABS);
-
- $indentWidth.text(editor._codeMirror.getOption("tabSize"));
+ }
+
+ function _updateIndentSize(inc) {
+ $indentWidth.text(Editor.getTabSize());
}
function _toggleIndentType() {
- var editor = getFocusedEditor(),
- indentWithTabs = editor._codeMirror.getOption("indentWithTabs");
-
- editor._codeMirror.setOption("indentWithTabs", !indentWithTabs);
-
- _updateIndentInfo(editor);
+ Editor.setUseTabChar(!Editor.getUseTabChar());
+ _updateIndentType();
}
- function _updateIndentSize(inc) {
- var editor = getFocusedEditor(),
- size = editor._codeMirror.getOption("tabSize");
-
- editor._codeMirror.setOption("tabSize", size + inc);
-
- _updateIndentInfo(editor);
+ function _changeIndentSize(inc) {
+ Editor.setTabSize(Editor.getTabSize() + inc);
+ _updateIndentSize();
}
function _updateCursorInfo(event, editor) {
@@ -643,7 +637,8 @@ define(function (require, exports, module) {
_updateCursorInfo(null, current);
_updateModeInfo(current);
_updateFileInfo(current);
- _updateIndentInfo(current);
+ _updateIndentType();
+ _updateIndentSize();
}
}
@@ -672,8 +667,8 @@ define(function (require, exports, module) {
// indentation event handlers
$indentType.on("click", _toggleIndentType);
- $indentDecrement.on("click", function () { _updateIndentSize(-1); });
- $indentIncrement.on("click", function () { _updateIndentSize(1); });
+ $indentDecrement.on("click", function () { _changeIndentSize(-1); });
+ $indentIncrement.on("click", function () { _changeIndentSize(1); });
StatusBar.hide();
_onFocusedEditorChange(null, getFocusedEditor(), null);
@@ -60,6 +60,13 @@ define(function (require, exports, module) {
// create a new empty preferences object
prefs = (defaults && JSON.stringify(defaults)) ? defaults : {};
prefStorage[clientID] = prefs;
+ } else if (defaults) {
+ // add new defaults
+ Object.keys(defaults).forEach(function (key) {
+ if (prefs[key] === undefined) {
+ prefs[key] = defaults[key];
+ }
+ });
}
return new PreferenceStorage(clientID, prefs);

0 comments on commit 03b949b

Please sign in to comment.