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

Fix #6558. Resurrect language layer #7889

Merged
merged 28 commits into from
Dec 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5f46a5e
First approximation of LanguageLayer in prefs.
busykai May 19, 2014
f12ca5d
Remove dead code.
busykai May 19, 2014
a48d619
Some tests and re-work of the implementation.
busykai May 19, 2014
2106d61
Document/Clean up.
busykai May 20, 2014
9c48410
Merge remote-tracking branch 'upstream/master' into kai/fix-6558-lang…
busykai May 27, 2014
ef38bec
Address review comments.
busykai Jun 4, 2014
7f37928
Merge remote-tracking branch 'upstream/master' into kai/fix-6558-lang…
busykai Jun 24, 2014
61940bd
Merge remote-tracking branch 'upstream/master' into kai/fix-6558-lang…
busykai Jul 12, 2014
b58c489
Merge remote-tracking branch 'upstream/master' into kai/fix-6558-lang…
busykai Sep 12, 2014
e891b49
Fix language layer after merge.
busykai Sep 12, 2014
afeb0ce
Fix CC annotation in JSDoc.
busykai Sep 12, 2014
29774fe
Make PreferencesBase stateles.
busykai Sep 16, 2014
ac706c6
Documentation and clean up.
busykai Sep 17, 2014
3c81509
Fix tests.
busykai Sep 17, 2014
4de1e6d
Merge remote-tracking branch 'upstream/master' into kai/fix-6558-lang…
busykai Sep 17, 2014
13f3594
Fix leftover call to _manager.
busykai Sep 17, 2014
52959c7
Merge remote-tracking branch 'upstream/master' into kai/fix-6558-lang…
busykai Sep 17, 2014
3da9e29
Fix JSHint issue (unused var).
busykai Sep 17, 2014
f28091a
Merge remote-tracking branch 'upstream/master' into kai/fix-6558-lang…
busykai Sep 19, 2014
ba62690
Merge remote-tracking branch 'upstream/master' into kai/fix-6558-lang…
busykai Sep 19, 2014
dd0fcca
Fix the issue with context override.
busykai Sep 26, 2014
5b340ee
Install path and language layers for testing.
busykai Sep 26, 2014
997bf2c
Merge remote-tracking branch 'upstream/master' into kai/fix-6558-lang…
busykai Sep 26, 2014
881427e
Fix merge issue with ProjectManager.
busykai Sep 26, 2014
7bf5da1
Merge remote-tracking branch 'upstream/master' into kai/fix-6558-lang…
busykai Nov 23, 2014
01e7548
Handle boolean properties properly.
busykai Dec 2, 2014
dde2613
Fix eventing for currentDocumentLanguageChanged.
busykai Dec 2, 2014
b71b8c9
Make PrefixedPreferencesSystem context aware.
busykai Dec 2, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/document/DocumentManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -695,17 +695,21 @@ define(function (require, exports, module) {
oldDoc.off("languageChanged.DocumentManager");
}

if (newDoc) {
PreferencesManager._setCurrentLanguage(newDoc.getLanguage().getId());
newDoc.on("languageChanged.DocumentManager", function (e, oldLang, newLang) {
PreferencesManager._setCurrentLanguage(newLang.getId());
exports.trigger("currentDocumentLanguageChanged", [oldLang, newLang]);
});
} else {
PreferencesManager._setCurrentLanguage(undefined);
}

if (newDoc !== oldDoc) {
// Dispatch deprecated event with doc args (not File args as the new event uses)
exports.trigger("currentDocumentChange", newDoc, oldDoc);
}

if (newDoc) {
newDoc.on("languageChanged.DocumentManager", function (data) {
exports.trigger("currentDocumentLanguageChanged", data);
});
}

});

// Deprecated APIs
Expand Down
34 changes: 24 additions & 10 deletions src/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ define(function (require, exports, module) {
var AnimationUtils = require("utils/AnimationUtils"),
Async = require("utils/Async"),
CodeMirror = require("thirdparty/CodeMirror2/lib/codemirror"),
LanguageManager = require("language/LanguageManager"),
EventDispatcher = require("utils/EventDispatcher"),
Menus = require("command/Menus"),
PerfUtils = require("utils/PerfUtils"),
Expand Down Expand Up @@ -178,6 +179,19 @@ define(function (require, exports, module) {
return true;
}

/**
* Helper function to build preferences context based on the full path of
* the file.
*
* @param {string} fullPath Full path of the file
*
* @return {*} A context for the specified file name
*/
function _buildPreferencesContext(fullPath) {
return PreferencesManager._buildContext(fullPath,
fullPath ? LanguageManager.getLanguageForPath(fullPath).getId() : undefined);
}

/**
* List of all current (non-destroy()ed) Editor instances. Needed when changing global preferences
* that affect all editors, e.g. tabbing or color scheme settings.
Expand Down Expand Up @@ -656,7 +670,7 @@ define(function (require, exports, module) {
/**
* Determine the mode to use from the document's language
* Uses "text/plain" if the language does not define a mode
* @return string The mode to use
* @return {string} The mode to use
*/
Editor.prototype._getModeFromDocument = function () {
// We'd like undefined/null/"" to mean plain text mode. CodeMirror defaults to plaintext for any
Expand Down Expand Up @@ -2159,7 +2173,7 @@ define(function (require, exports, module) {
* @return {*} current value of that pref
*/
Editor.prototype._getOption = function (prefName) {
return PreferencesManager.get(prefName, this.document.file.fullPath);
return PreferencesManager.get(prefName, PreferencesManager._buildContext(this.document.file.fullPath, this.document.getLanguage().getId()));
};

/**
Expand Down Expand Up @@ -2247,7 +2261,7 @@ define(function (require, exports, module) {


// Global settings that affect Editor instances that share the same preference locations

/**
* Sets whether to use tab characters (vs. spaces) when inserting new text.
* Affects any editors that share the same preference location.
Expand All @@ -2266,7 +2280,7 @@ define(function (require, exports, module) {
* @return {boolean}
*/
Editor.getUseTabChar = function (fullPath) {
return PreferencesManager.get(USE_TAB_CHAR, fullPath);
return PreferencesManager.get(USE_TAB_CHAR, _buildPreferencesContext(fullPath));
};

/**
Expand All @@ -2287,7 +2301,7 @@ define(function (require, exports, module) {
* @return {number}
*/
Editor.getTabSize = function (fullPath) {
return PreferencesManager.get(TAB_SIZE, fullPath);
return PreferencesManager.get(TAB_SIZE, _buildPreferencesContext(fullPath));
};

/**
Expand All @@ -2308,7 +2322,7 @@ define(function (require, exports, module) {
* @return {number}
*/
Editor.getSpaceUnits = function (fullPath) {
return PreferencesManager.get(SPACE_UNITS, fullPath);
return PreferencesManager.get(SPACE_UNITS, _buildPreferencesContext(fullPath));
};

/**
Expand All @@ -2329,7 +2343,7 @@ define(function (require, exports, module) {
* @return {boolean}
*/
Editor.getCloseBrackets = function (fullPath) {
return PreferencesManager.get(CLOSE_BRACKETS, fullPath);
return PreferencesManager.get(CLOSE_BRACKETS, _buildPreferencesContext(fullPath));
};

/**
Expand All @@ -2350,7 +2364,7 @@ define(function (require, exports, module) {
* @return {boolean}
*/
Editor.getShowLineNumbers = function (fullPath) {
return PreferencesManager.get(SHOW_LINE_NUMBERS, fullPath);
return PreferencesManager.get(SHOW_LINE_NUMBERS, _buildPreferencesContext(fullPath));
};

/**
Expand All @@ -2370,7 +2384,7 @@ define(function (require, exports, module) {
* @return {boolean}
*/
Editor.getShowActiveLine = function (fullPath) {
return PreferencesManager.get(STYLE_ACTIVE_LINE, fullPath);
return PreferencesManager.get(STYLE_ACTIVE_LINE, _buildPreferencesContext(fullPath));
};

/**
Expand All @@ -2391,7 +2405,7 @@ define(function (require, exports, module) {
* @return {boolean}
*/
Editor.getWordWrap = function (fullPath) {
return PreferencesManager.get(WORD_WRAP, fullPath);
return PreferencesManager.get(WORD_WRAP, _buildPreferencesContext(fullPath));
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/editor/EditorManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ define(function (require, exports, module) {
// File-based preferences handling
exports.on("activeEditorChange", function (e, current) {
if (current && current.document && current.document.file) {
PreferencesManager._setCurrentEditingFile(current.document.file.fullPath);
PreferencesManager._setCurrentFile(current.document.file.fullPath);
}
});

Expand Down
Loading