Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
save indentation preferences. add new default prefs when missing
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonsanjose committed Oct 8, 2012
1 parent 6f38c6a commit 03b949b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
35 changes: 15 additions & 20 deletions src/editor/EditorManager.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -643,7 +637,8 @@ define(function (require, exports, module) {
_updateCursorInfo(null, current);
_updateModeInfo(current);
_updateFileInfo(current);
_updateIndentInfo(current);
_updateIndentType();
_updateIndentSize();
}
}

Expand Down Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions src/preferences/PreferencesManager.js
Expand Up @@ -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);
Expand Down

0 comments on commit 03b949b

Please sign in to comment.