Cleanups to status bar language-switcher:

* Make LanguageManager the official public API that is used to set per-file
overrides, rather than proxying through Document objects - remove Document.setLanguageOverride()
* Clear path overrides when switching projects, so it's more obvious that
it's not something that gets persisted across sessions
* Simplify how JS Code Hints listen for language updates: remove dependency
on "currentDocumentLanguageChanged" event; remove unneeded extra 'if' tests
This commit is contained in:
Peter Flynn committed 2014-07-17 14:12:46 -07:00
1 parent ce7e691f73
commit cc4704350a
7 files changed
+63 -70

No files matched your search

@@ -1037,8 +1037,8 @@ define(function (require, exports, module) {
* Do the work to initialize a code hinting session.
*
* @param {Session} session - the active hinting session
* @param {Document} document - the document the editor has changed to
* @param {Document} previousDocument - the document the editor has changed from
* @param {!Document} document - the document the editor has changed to
* @param {?Document} previousDocument - the document the editor has changed from
*/
function doEditorChange(session, document, previousDocument) {
var file = document.file,
@@ -1138,7 +1138,7 @@ define(function (require, exports, module) {
*
* @param {Session} session - the active hinting session
* @param {Document} document - the document of the editor that has changed
* @param {Document} previousDocument - the document of the editor is changing from
* @param {?Document} previousDocument - the document of the editor is changing from
*/
function handleEditorChange(session, document, previousDocument) {
if (addFilesPromise === null) {
@@ -1376,7 +1376,7 @@ define(function (require, exports, module) {
*
* @param {Session} session - the active hinting session
* @param {Document} document - the document of the editor that has changed
* @param {Document} previousDocument - the document of the editor is changing from
* @param {?Document} previousDocument - the document of the editor is changing from
*/
function handleEditorChange(session, document, previousDocument) {
@@ -564,7 +564,7 @@ define(function (require, exports, module) {
* information, and reject any pending deferred requests.
*
* @param {Editor} editor - editor context to be initialized.
* @param {Editor} previousEditor - the previous editor.
* @param {?Editor} previousEditor - the previous editor.
*/
function initializeSession(editor, previousEditor) {
session = new Session(editor);
@@ -579,7 +579,7 @@ define(function (require, exports, module) {
*
* @param {Editor} editor - editor context on which to listen for
* changes
* @param {Editor} previousEditor - the previous editor
* @param {?Editor} previousEditor - the previous editor
*/
function installEditorListeners(editor, previousEditor) {
// always clean up cached scope and hint info
@@ -624,18 +624,21 @@ define(function (require, exports, module) {
* @param {Editor} previous - the previous editor context
*/
function handleActiveEditorChange(event, current, previous) {
// Uninstall "languageChanged" event listeners on the previous editor's document
if (previous && previous !== current) {
// Uninstall "languageChanged" event listeners on previous editor's document & put them on current editor's doc
if (previous) {
$(previous.document)
.off(HintUtils.eventName("languageChanged"));
}
if (current && current.document !== DocumentManager.getCurrentDocument()) {
if (current) {
$(current.document)
.on(HintUtils.eventName("languageChanged"), function () {
// If current doc's language changed, reset our state by treating it as if the user switched to a
// different document altogether
uninstallEditorListeners(current);
installEditorListeners(current);
});
}
uninstallEditorListeners(previous);
installEditorListeners(current, previous);
}
@@ -803,13 +806,6 @@ define(function (require, exports, module) {
.on(HintUtils.eventName("activeEditorChange"),
handleActiveEditorChange);
$(DocumentManager)
.on("currentDocumentLanguageChanged", function (e) {
var activeEditor = EditorManager.getActiveEditor();
uninstallEditorListeners(activeEditor);
installEditorListeners(activeEditor);
});
$(ProjectManager).on("beforeProjectClose", function () {
ScopeManager.handleProjectClose();
});