From 2dc16c7b8271a195b68708d8273d8f9454de16c6 Mon Sep 17 00:00:00 2001 From: Jeff Booher Date: Tue, 10 Jun 2014 21:48:08 -0700 Subject: [PATCH 001/244] splitview refactoring --- src/LiveDevelopment/LiveDevelopment.js | 5 +- src/brackets.js | 18 +- src/command/Commands.js | 187 ++--- src/command/DefaultMenus.js | 36 +- src/command/Menus.js | 33 +- src/document/DocumentCommandHandlers.js | 125 ++-- src/document/DocumentManager.js | 685 ++++++------------ src/editor/Editor.js | 7 + src/editor/EditorManager.js | 88 ++- src/editor/ImageViewer.js | 6 +- src/extensions/default/CloseOthers/main.js | 11 +- .../default/CloseOthers/unittests.js | 11 +- src/htmlContent/main-view.html | 4 +- src/language/CodeInspection.js | 4 +- src/nls/root/strings.js | 12 +- src/project/FileSyncManager.js | 3 +- src/project/FileViewController.js | 41 +- ...{WorkingSetSort.js => PaneViewListSort.js} | 120 +-- ...{WorkingSetView.js => PaneViewListView.js} | 53 +- src/project/ProjectManager.js | 9 +- src/project/SidebarView.js | 6 +- src/search/FindInFiles.js | 7 +- src/search/FindReplace.js | 4 +- src/search/QuickOpen.js | 2 +- src/search/ScrollTrackMarkers.js | 6 +- src/styles/brackets.less | 4 +- src/utils/AppInit.js | 12 +- src/utils/DeprecationWarning.js | 33 +- src/utils/DragAndDrop.js | 6 +- src/utils/ExtensionLoader.js | 2 +- src/utils/Resizer.js | 12 +- src/view/MainViewManager.js | 559 ++++++++++++++ src/view/PanelManager.js | 230 +----- src/view/WorkspaceManager.js | 275 +++++++ src/widgets/DropdownButton.js | 10 +- test/UnitTestSuite.js | 4 +- test/spec/Document-test.js | 7 +- test/spec/DocumentCommandHandlers-test.js | 99 +-- test/spec/DocumentManager-test.js | 8 +- test/spec/EditorCommandHandlers-test.js | 2 +- test/spec/EditorManager-test.js | 34 +- test/spec/EditorOptionHandlers-test.js | 2 +- test/spec/FindReplace-test.js | 12 +- test/spec/InlineEditorProviders-test.js | 17 +- test/spec/MainViewManager-test.js | 41 ++ test/spec/PaneViewListSort-test.js | 201 +++++ .../directory/directory/file_one.js | 0 .../directory/file_one.js | 0 .../file_four.html} | 0 .../file_one.js} | 0 .../file_three.js} | 0 .../PaneViewListView-test-files/file_two.js | 0 .../PaneViewListView-test-files/file_zero.css | 0 ...tView-test.js => PaneViewListView-test.js} | 33 +- test/spec/PreferencesManager-test.js | 4 +- test/spec/SpecRunnerUtils.js | 8 +- test/spec/ViewCommandHandlers-test.js | 2 +- 57 files changed, 1948 insertions(+), 1152 deletions(-) rename src/project/{WorkingSetSort.js => PaneViewListSort.js} (70%) rename src/project/{WorkingSetView.js => PaneViewListView.js} (92%) create mode 100644 src/view/MainViewManager.js create mode 100644 src/view/WorkspaceManager.js create mode 100644 test/spec/MainViewManager-test.js create mode 100644 test/spec/PaneViewListSort-test.js rename test/spec/{WorkingSetView-test-files => PaneViewListView-test-files}/directory/directory/file_one.js (100%) rename test/spec/{WorkingSetView-test-files => PaneViewListView-test-files}/directory/file_one.js (100%) rename test/spec/{WorkingSetView-test-files/file_one.js => PaneViewListView-test-files/file_four.html} (100%) rename test/spec/{WorkingSetView-test-files/file_three.js => PaneViewListView-test-files/file_one.js} (100%) rename test/spec/{WorkingSetView-test-files/file_two.js => PaneViewListView-test-files/file_three.js} (100%) create mode 100644 test/spec/PaneViewListView-test-files/file_two.js create mode 100644 test/spec/PaneViewListView-test-files/file_zero.css rename test/spec/{WorkingSetView-test.js => PaneViewListView-test.js} (90%) diff --git a/src/LiveDevelopment/LiveDevelopment.js b/src/LiveDevelopment/LiveDevelopment.js index bfc0d09e6e6..3e3444127ce 100644 --- a/src/LiveDevelopment/LiveDevelopment.js +++ b/src/LiveDevelopment/LiveDevelopment.js @@ -85,6 +85,7 @@ define(function LiveDevelopment(require, exports, module) { FileSystemError = require("filesystem/FileSystemError"), FileUtils = require("file/FileUtils"), LiveDevServerManager = require("LiveDevelopment/LiveDevServerManager"), + MainViewManager = require("view/MainViewManager"), NativeApp = require("utils/NativeApp"), PreferencesDialogs = require("preferences/PreferencesDialogs"), ProjectManager = require("project/ProjectManager"), @@ -1266,8 +1267,8 @@ define(function LiveDevelopment(require, exports, module) { otherDocumentsInWorkingFiles; if (doc && !doc._masterEditor) { - otherDocumentsInWorkingFiles = DocumentManager.getWorkingSet().length; - DocumentManager.addToWorkingSet(doc.file); + otherDocumentsInWorkingFiles = MainViewManager.getPaneViewList(MainViewManager.FOCUSED_PANE).length; + MainViewManager.addToPaneViewList(MainViewManager.FOCUSED_PANE, doc.file); if (!otherDocumentsInWorkingFiles) { DocumentManager.setCurrentDocument(doc); diff --git a/src/brackets.js b/src/brackets.js index 8d5cfd8bd43..f2d6a6b59f7 100644 --- a/src/brackets.js +++ b/src/brackets.js @@ -68,8 +68,8 @@ define(function (require, exports, module) { EditorManager = require("editor/EditorManager"), CSSInlineEditor = require("editor/CSSInlineEditor"), JSUtils = require("language/JSUtils"), - WorkingSetView = require("project/WorkingSetView"), - WorkingSetSort = require("project/WorkingSetSort"), + PaneViewListView = require("project/PaneViewListView"), + PaneViewListSort = require("project/PaneViewListSort"), DocumentCommandHandlers = require("document/DocumentCommandHandlers"), FileViewController = require("project/FileViewController"), FileSyncManager = require("project/FileSyncManager"), @@ -103,6 +103,7 @@ define(function (require, exports, module) { NativeApp = require("utils/NativeApp"), DeprecationWarning = require("utils/DeprecationWarning"), ViewCommandHandlers = require("view/ViewCommandHandlers"), + MainViewManager = require("view/MainViewManager"), _ = require("thirdparty/lodash"); // DEPRECATED: In future we want to remove the global CodeMirror, but for now we @@ -116,7 +117,7 @@ define(function (require, exports, module) { return CodeMirror; } }); - + // Load modules that self-register and just need to get included in the main project require("command/DefaultMenus"); require("document/ChangedDocumentTracker"); @@ -137,6 +138,9 @@ define(function (require, exports, module) { require("file/NativeFileSystem"); require("file/NativeFileError"); + // Compatibility shim for PanelManager to WorkspaceManager migration + require("view/PanelManager"); + PerfUtils.addMeasurement("brackets module dependencies resolved"); // Local variables @@ -182,6 +186,7 @@ define(function (require, exports, module) { LanguageManager : LanguageManager, LiveDevelopment : require("LiveDevelopment/LiveDevelopment"), LiveDevServerManager : require("LiveDevelopment/LiveDevServerManager"), + MainViewManager : MainViewManager, Menus : Menus, MultiRangeInlineEditor : require("editor/MultiRangeInlineEditor").MultiRangeInlineEditor, NativeApp : NativeApp, @@ -191,7 +196,7 @@ define(function (require, exports, module) { RemoteAgent : require("LiveDevelopment/Agents/RemoteAgent"), ScrollTrackMarkers : require("search/ScrollTrackMarkers"), UpdateNotification : require("utils/UpdateNotification"), - WorkingSetView : WorkingSetView, + PaneViewListView : PaneViewListView, doneLoading : false }; @@ -242,6 +247,9 @@ define(function (require, exports, module) { // Load the initial project after extensions have loaded extensionLoaderPromise.always(function () { + // Signal that extensions are loaded + AppInit._dispatchReady(AppInit.EXTENSIONS_READY); + // Finish UI initialization ViewCommandHandlers.restoreFontSize(); var initialProjectPath = ProjectManager.getInitialProjectPath(); @@ -259,7 +267,7 @@ define(function (require, exports, module) { if (ProjectManager.isWelcomeProjectPath(initialProjectPath)) { FileSystem.resolve(initialProjectPath + "index.html", function (err, file) { if (!err) { - var promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, { fullPath: file.fullPath }); + var promise = CommandManager.execute(Commands.CMD_ADD_TO_PANE_VIEW_LIST, { fullPath: file.fullPath }); promise.then(deferred.resolve, deferred.reject); } else { deferred.reject(); diff --git a/src/command/Commands.js b/src/command/Commands.js index b079affb861..55a1eeae3d6 100644 --- a/src/command/Commands.js +++ b/src/command/Commands.js @@ -53,101 +53,103 @@ define(function (require, exports, module) { */ // FILE - exports.FILE_NEW_UNTITLED = "file.newDoc"; // DocumentCommandHandlers.js handleFileNew() - exports.FILE_NEW = "file.newFile"; // DocumentCommandHandlers.js handleFileNewInProject() - exports.FILE_NEW_FOLDER = "file.newFolder"; // DocumentCommandHandlers.js handleNewFolderInProject() - exports.FILE_OPEN = "file.open"; // DocumentCommandHandlers.js handleFileOpen() - exports.FILE_OPEN_FOLDER = "file.openFolder"; // ProjectManager.js openProject() - exports.FILE_SAVE = "file.save"; // DocumentCommandHandlers.js handleFileSave() - exports.FILE_SAVE_ALL = "file.saveAll"; // DocumentCommandHandlers.js handleFileSaveAll() - exports.FILE_SAVE_AS = "file.saveAs"; // DocumentCommandHandlers.js handleFileSaveAs() - exports.FILE_CLOSE = "file.close"; // DocumentCommandHandlers.js handleFileClose() - exports.FILE_CLOSE_ALL = "file.close_all"; // DocumentCommandHandlers.js handleFileCloseAll() - exports.FILE_CLOSE_LIST = "file.close_list"; // DocumentCommandHandlers.js handleFileCloseList() - exports.FILE_ADD_TO_WORKING_SET = "file.addToWorkingSet"; // DocumentCommandHandlers.js handleFileAddToWorkingSet() - exports.FILE_OPEN_DROPPED_FILES = "file.openDroppedFiles"; // DragAndDrop.js openDroppedFiles() - exports.FILE_LIVE_FILE_PREVIEW = "file.liveFilePreview"; // LiveDevelopment/main.js _handleGoLiveCommand() - exports.FILE_LIVE_HIGHLIGHT = "file.previewHighlight"; // LiveDevelopment/main.js _handlePreviewHighlightCommand() - exports.FILE_PROJECT_SETTINGS = "file.projectSettings"; // ProjectManager.js _projectSettings() - exports.FILE_RENAME = "file.rename"; // DocumentCommandHandlers.js handleFileRename() - exports.FILE_DELETE = "file.delete"; // DocumentCommandHandlers.js handleFileDelete() - exports.FILE_EXTENSION_MANAGER = "file.extensionManager"; // ExtensionManagerDialog.js _showDialog() - exports.FILE_REFRESH = "file.refresh"; // ProjectManager.js refreshFileTree() - exports.FILE_OPEN_PREFERENCES = "file.openPreferences"; // PreferencesManager.js _handleOpenPreferences() + exports.FILE_NEW_UNTITLED = "file.newDoc"; // DocumentCommandHandlers.js handleFileNew() + exports.FILE_NEW = "file.newFile"; // DocumentCommandHandlers.js handleFileNewInProject() + exports.FILE_NEW_FOLDER = "file.newFolder"; // DocumentCommandHandlers.js handleNewFolderInProject() + exports.FILE_OPEN = "file.open"; // DocumentCommandHandlers.js handleFileOpen() + exports.FILE_OPEN_FOLDER = "file.openFolder"; // ProjectManager.js openProject() + exports.FILE_SAVE = "file.save"; // DocumentCommandHandlers.js handleFileSave() + exports.FILE_SAVE_ALL = "file.saveAll"; // DocumentCommandHandlers.js handleFileSaveAll() + exports.FILE_SAVE_AS = "file.saveAs"; // DocumentCommandHandlers.js handleFileSaveAs() + exports.FILE_CLOSE = "file.close"; // DocumentCommandHandlers.js handleFileClose() + exports.FILE_CLOSE_ALL = "file.close_all"; // DocumentCommandHandlers.js handleFileCloseAll() + exports.FILE_CLOSE_LIST = "file.close_list"; // DocumentCommandHandlers.js handleFileCloseList() + exports.FILE_OPEN_DROPPED_FILES = "file.openDroppedFiles"; // DragAndDrop.js openDroppedFiles() + exports.FILE_LIVE_FILE_PREVIEW = "file.liveFilePreview"; // LiveDevelopment/main.js _handleGoLiveCommand() + exports.FILE_LIVE_HIGHLIGHT = "file.previewHighlight"; // LiveDevelopment/main.js _handlePreviewHighlightCommand() + exports.FILE_PROJECT_SETTINGS = "file.projectSettings"; // ProjectManager.js _projectSettings() + exports.FILE_RENAME = "file.rename"; // DocumentCommandHandlers.js handleFileRename() + exports.FILE_DELETE = "file.delete"; // DocumentCommandHandlers.js handleFileDelete() + exports.FILE_EXTENSION_MANAGER = "file.extensionManager"; // ExtensionManagerDialog.js _showDialog() + exports.FILE_REFRESH = "file.refresh"; // ProjectManager.js refreshFileTree() + exports.FILE_OPEN_PREFERENCES = "file.openPreferences"; // PreferencesManager.js _handleOpenPreferences() // File shell callbacks - string must MATCH string in native code (appshell/command_callbacks.h) - exports.FILE_CLOSE_WINDOW = "file.close_window"; // DocumentCommandHandlers.js handleFileCloseWindow() - exports.FILE_QUIT = "file.quit"; // DocumentCommandHandlers.js handleFileQuit() + exports.FILE_CLOSE_WINDOW = "file.close_window"; // DocumentCommandHandlers.js handleFileCloseWindow() + exports.FILE_QUIT = "file.quit"; // DocumentCommandHandlers.js handleFileQuit() // EDIT // File shell callbacks - string must MATCH string in native code (appshell/command_callbacks.h) - exports.EDIT_UNDO = "edit.undo"; // EditorCommandHandlers.js handleUndo() - exports.EDIT_REDO = "edit.redo"; // EditorCommandHandlers.js handleRedo() - exports.EDIT_CUT = "edit.cut"; // EditorCommandHandlers.js ignoreCommand() - exports.EDIT_COPY = "edit.copy"; // EditorCommandHandlers.js ignoreCommand() - exports.EDIT_PASTE = "edit.paste"; // EditorCommandHandlers.js ignoreCommand() - exports.EDIT_SELECT_ALL = "edit.selectAll"; // EditorCommandHandlers.js _handleSelectAll() - - exports.EDIT_SELECT_LINE = "edit.selectLine"; // EditorCommandHandlers.js selectLine() - exports.EDIT_SPLIT_SEL_INTO_LINES = "edit.splitSelIntoLines"; // EditorCommandHandlers.js splitSelIntoLines() - exports.EDIT_ADD_CUR_TO_NEXT_LINE = "edit.addCursorToNextLine"; // EditorCommandHandlers.js addCursorToNextLine() - exports.EDIT_ADD_CUR_TO_PREV_LINE = "edit.addCursorToPrevLine"; // EditorCommandHandlers.js addCursorToPrevLine() - exports.EDIT_INDENT = "edit.indent"; // EditorCommandHandlers.js indentText() - exports.EDIT_UNINDENT = "edit.unindent"; // EditorCommandHandlers.js unindentText() - exports.EDIT_DUPLICATE = "edit.duplicate"; // EditorCommandHandlers.js duplicateText() - exports.EDIT_DELETE_LINES = "edit.deletelines"; // EditorCommandHandlers.js deleteCurrentLines() - exports.EDIT_LINE_COMMENT = "edit.lineComment"; // EditorCommandHandlers.js lineComment() - exports.EDIT_BLOCK_COMMENT = "edit.blockComment"; // EditorCommandHandlers.js blockComment() - exports.EDIT_LINE_UP = "edit.lineUp"; // EditorCommandHandlers.js moveLineUp() - exports.EDIT_LINE_DOWN = "edit.lineDown"; // EditorCommandHandlers.js moveLineDown() - exports.EDIT_OPEN_LINE_ABOVE = "edit.openLineAbove"; // EditorCommandHandlers.js openLineAbove() - exports.EDIT_OPEN_LINE_BELOW = "edit.openLineBelow"; // EditorCommandHandlers.js openLineBelow() - exports.TOGGLE_CLOSE_BRACKETS = "edit.autoCloseBrackets"; // EditorOptionHandlers.js _getToggler() - exports.SHOW_CODE_HINTS = "edit.showCodeHints"; // CodeHintManager.js _startNewSession() + exports.EDIT_UNDO = "edit.undo"; // EditorCommandHandlers.js handleUndo() + exports.EDIT_REDO = "edit.redo"; // EditorCommandHandlers.js handleRedo() + exports.EDIT_CUT = "edit.cut"; // EditorCommandHandlers.js ignoreCommand() + exports.EDIT_COPY = "edit.copy"; // EditorCommandHandlers.js ignoreCommand() + exports.EDIT_PASTE = "edit.paste"; // EditorCommandHandlers.js ignoreCommand() + exports.EDIT_SELECT_ALL = "edit.selectAll"; // EditorCommandHandlers.js _handleSelectAll() + + exports.EDIT_SELECT_LINE = "edit.selectLine"; // EditorCommandHandlers.js selectLine() + exports.EDIT_SPLIT_SEL_INTO_LINES = "edit.splitSelIntoLines"; // EditorCommandHandlers.js splitSelIntoLines() + exports.EDIT_ADD_CUR_TO_NEXT_LINE = "edit.addCursorToNextLine"; // EditorCommandHandlers.js addCursorToNextLine() + exports.EDIT_ADD_CUR_TO_PREV_LINE = "edit.addCursorToPrevLine"; // EditorCommandHandlers.js addCursorToPrevLine() + exports.EDIT_INDENT = "edit.indent"; // EditorCommandHandlers.js indentText() + exports.EDIT_UNINDENT = "edit.unindent"; // EditorCommandHandlers.js unindentText() + exports.EDIT_DUPLICATE = "edit.duplicate"; // EditorCommandHandlers.js duplicateText() + exports.EDIT_DELETE_LINES = "edit.deletelines"; // EditorCommandHandlers.js deleteCurrentLines() + exports.EDIT_LINE_COMMENT = "edit.lineComment"; // EditorCommandHandlers.js lineComment() + exports.EDIT_BLOCK_COMMENT = "edit.blockComment"; // EditorCommandHandlers.js blockComment() + exports.EDIT_LINE_UP = "edit.lineUp"; // EditorCommandHandlers.js moveLineUp() + exports.EDIT_LINE_DOWN = "edit.lineDown"; // EditorCommandHandlers.js moveLineDown() + exports.EDIT_OPEN_LINE_ABOVE = "edit.openLineAbove"; // EditorCommandHandlers.js openLineAbove() + exports.EDIT_OPEN_LINE_BELOW = "edit.openLineBelow"; // EditorCommandHandlers.js openLineBelow() + exports.TOGGLE_CLOSE_BRACKETS = "edit.autoCloseBrackets"; // EditorOptionHandlers.js _getToggler() + exports.SHOW_CODE_HINTS = "edit.showCodeHints"; // CodeHintManager.js _startNewSession() // FIND - exports.CMD_FIND = "cmd.find"; // FindReplace.js _launchFind() - exports.CMD_FIND_IN_FILES = "cmd.findInFiles"; // FindInFiles.js _doFindInFiles() - exports.CMD_FIND_IN_SELECTED = "cmd.findInSelected"; // FindInFiles.js _doFindInSubtree() - exports.CMD_FIND_IN_SUBTREE = "cmd.findInSubtree"; // FindInFiles.js _doFindInSubtree() - exports.CMD_FIND_NEXT = "cmd.findNext"; // FindReplace.js _findNext() - exports.CMD_FIND_PREVIOUS = "cmd.findPrevious"; // FindReplace.js _findPrevious() - exports.CMD_FIND_ALL_AND_SELECT = "cmd.findAllAndSelect"; // FindReplace.js _findAllAndSelect() - exports.CMD_ADD_NEXT_MATCH = "cmd.addNextMatch"; // FindReplace.js _expandAndAddNextToSelection() - exports.CMD_SKIP_CURRENT_MATCH = "cmd.skipCurrentMatch"; // FindReplace.js _skipCurrentMatch() - exports.CMD_REPLACE = "cmd.replace"; // FindReplace.js _replace() + exports.CMD_FIND = "cmd.find"; // FindReplace.js _launchFind() + exports.CMD_FIND_IN_FILES = "cmd.findInFiles"; // FindInFiles.js _doFindInFiles() + exports.CMD_FIND_IN_SELECTED = "cmd.findInSelected"; // FindInFiles.js _doFindInSubtree() + exports.CMD_FIND_IN_SUBTREE = "cmd.findInSubtree"; // FindInFiles.js _doFindInSubtree() + exports.CMD_FIND_NEXT = "cmd.findNext"; // FindReplace.js _findNext() + exports.CMD_FIND_PREVIOUS = "cmd.findPrevious"; // FindReplace.js _findPrevious() + exports.CMD_FIND_ALL_AND_SELECT = "cmd.findAllAndSelect"; // FindReplace.js _findAllAndSelect() + exports.CMD_ADD_NEXT_MATCH = "cmd.addNextMatch"; // FindReplace.js _expandAndAddNextToSelection() + exports.CMD_SKIP_CURRENT_MATCH = "cmd.skipCurrentMatch"; // FindReplace.js _skipCurrentMatch() + exports.CMD_REPLACE = "cmd.replace"; // FindReplace.js _replace() // VIEW - exports.VIEW_HIDE_SIDEBAR = "view.hideSidebar"; // SidebarView.js toggle() - exports.VIEW_INCREASE_FONT_SIZE = "view.increaseFontSize"; // ViewCommandHandlers.js _handleIncreaseFontSize() - exports.VIEW_DECREASE_FONT_SIZE = "view.decreaseFontSize"; // ViewCommandHandlers.js _handleDecreaseFontSize() - exports.VIEW_RESTORE_FONT_SIZE = "view.restoreFontSize"; // ViewCommandHandlers.js _handleRestoreFontSize() - exports.VIEW_SCROLL_LINE_UP = "view.scrollLineUp"; // ViewCommandHandlers.js _handleScrollLineUp() - exports.VIEW_SCROLL_LINE_DOWN = "view.scrollLineDown"; // ViewCommandHandlers.js _handleScrollLineDown() - exports.VIEW_TOGGLE_INSPECTION = "view.toggleCodeInspection"; // CodeInspection.js toggleEnabled() - exports.TOGGLE_LINE_NUMBERS = "view.toggleLineNumbers"; // EditorOptionHandlers.js _getToggler() - exports.TOGGLE_ACTIVE_LINE = "view.toggleActiveLine"; // EditorOptionHandlers.js _getToggler() - exports.TOGGLE_WORD_WRAP = "view.toggleWordWrap"; // EditorOptionHandlers.js _getToggler() - exports.SORT_WORKINGSET_BY_ADDED = "view.sortWorkingSetByAdded"; // WorkingSetSort.js _handleSortWorkingSetByAdded() - exports.SORT_WORKINGSET_BY_NAME = "view.sortWorkingSetByName"; // WorkingSetSort.js _handleSortWorkingSetByName() - exports.SORT_WORKINGSET_BY_TYPE = "view.sortWorkingSetByType"; // WorkingSetSort.js _handleSortWorkingSetByType() - exports.SORT_WORKINGSET_AUTO = "view.sortWorkingSetAuto"; // WorkingSetSort.js _handleAutomaticSort() + exports.VIEW_HIDE_SIDEBAR = "view.hideSidebar"; // SidebarView.js toggle() + exports.VIEW_INCREASE_FONT_SIZE = "view.increaseFontSize"; // ViewCommandHandlers.js _handleIncreaseFontSize() + exports.VIEW_DECREASE_FONT_SIZE = "view.decreaseFontSize"; // ViewCommandHandlers.js _handleDecreaseFontSize() + exports.VIEW_RESTORE_FONT_SIZE = "view.restoreFontSize"; // ViewCommandHandlers.js _handleRestoreFontSize() + exports.VIEW_SCROLL_LINE_UP = "view.scrollLineUp"; // ViewCommandHandlers.js _handleScrollLineUp() + exports.VIEW_SCROLL_LINE_DOWN = "view.scrollLineDown"; // ViewCommandHandlers.js _handleScrollLineDown() + exports.VIEW_TOGGLE_INSPECTION = "view.toggleCodeInspection"; // CodeInspection.js toggleEnabled() + exports.TOGGLE_LINE_NUMBERS = "view.toggleLineNumbers"; // EditorOptionHandlers.js _getToggler() + exports.TOGGLE_ACTIVE_LINE = "view.toggleActiveLine"; // EditorOptionHandlers.js _getToggler() + exports.TOGGLE_WORD_WRAP = "view.toggleWordWrap"; // EditorOptionHandlers.js _getToggler() + + exports.CMD_ADD_TO_PANE_VIEW_LIST = "cmd.addToPaneViewList"; // DocumentCommandHandlers.js handleOpenDocumentInNewPane() + + exports.CMD_SORT_PANE_VIEW_LIST_BY_ADDED = "cmd.sortPaneViewListByAdded"; // PaneViewListSort.js _handleSort() + exports.CMD_SORT_PANE_VIEW_LIST_BY_NAME = "cmd.sortPaneViewListByName"; // PaneViewListSort.js _handleSort() + exports.CMD_SORT_PANE_VIEW_LIST_BY_TYPE = "cmd.sortPaneViewListByType"; // PaneViewListSort.js _handleSort() + exports.CMD_TOGGLE_AUTO_SORT = "cmd.toggleAutoSort"; // PaneViewListSort.js _handleToggleAutoSort() // NAVIGATE - exports.NAVIGATE_NEXT_DOC = "navigate.nextDoc"; // DocumentCommandHandlers.js handleGoNextDoc() - exports.NAVIGATE_PREV_DOC = "navigate.prevDoc"; // DocumentCommandHandlers.js handleGoPrevDoc() - exports.NAVIGATE_SHOW_IN_FILE_TREE = "navigate.showInFileTree"; // DocumentCommandHandlers.js handleShowInTree() - exports.NAVIGATE_SHOW_IN_OS = "navigate.showInOS"; // DocumentCommandHandlers.js handleShowInOS() - exports.NAVIGATE_QUICK_OPEN = "navigate.quickOpen"; // QuickOpen.js doFileSearch() - exports.NAVIGATE_JUMPTO_DEFINITION = "navigate.jumptoDefinition"; // EditorManager.js _doJumpToDef() - exports.NAVIGATE_GOTO_DEFINITION = "navigate.gotoDefinition"; // QuickOpen.js doDefinitionSearch() - exports.NAVIGATE_GOTO_LINE = "navigate.gotoLine"; // QuickOpen.js doGotoLine() - exports.NAVIGATE_GOTO_FIRST_PROBLEM = "navigate.gotoFirstProblem"; // CodeInspection.js handleGotoFirstProblem() - exports.TOGGLE_QUICK_EDIT = "navigate.toggleQuickEdit"; // EditorManager.js _toggleInlineWidget() - exports.TOGGLE_QUICK_DOCS = "navigate.toggleQuickDocs"; // EditorManager.js _toggleInlineWidget() - exports.QUICK_EDIT_NEXT_MATCH = "navigate.nextMatch"; // MultiRangeInlineEditor.js _nextRange() - exports.QUICK_EDIT_PREV_MATCH = "navigate.previousMatch"; // MultiRangeInlineEditor.js _previousRange() - exports.CSS_QUICK_EDIT_NEW_RULE = "navigate.newRule"; // CSSInlineEditor.js _handleNewRule() + exports.NAVIGATE_NEXT_DOC = "navigate.nextDoc"; // DocumentCommandHandlers.js handleGoNextDoc() + exports.NAVIGATE_PREV_DOC = "navigate.prevDoc"; // DocumentCommandHandlers.js handleGoPrevDoc() + exports.NAVIGATE_SHOW_IN_FILE_TREE = "navigate.showInFileTree"; // DocumentCommandHandlers.js handleShowInTree() + exports.NAVIGATE_SHOW_IN_OS = "navigate.showInOS"; // DocumentCommandHandlers.js handleShowInOS() + exports.NAVIGATE_QUICK_OPEN = "navigate.quickOpen"; // QuickOpen.js doFileSearch() + exports.NAVIGATE_JUMPTO_DEFINITION = "navigate.jumptoDefinition"; // EditorManager.js _doJumpToDef() + exports.NAVIGATE_GOTO_DEFINITION = "navigate.gotoDefinition"; // QuickOpen.js doDefinitionSearch() + exports.NAVIGATE_GOTO_LINE = "navigate.gotoLine"; // QuickOpen.js doGotoLine() + exports.NAVIGATE_GOTO_FIRST_PROBLEM = "navigate.gotoFirstProblem"; // CodeInspection.js handleGotoFirstProblem() + exports.TOGGLE_QUICK_EDIT = "navigate.toggleQuickEdit"; // EditorManager.js _toggleInlineWidget() + exports.TOGGLE_QUICK_DOCS = "navigate.toggleQuickDocs"; // EditorManager.js _toggleInlineWidget() + exports.QUICK_EDIT_NEXT_MATCH = "navigate.nextMatch"; // MultiRangeInlineEditor.js _nextRange() + exports.QUICK_EDIT_PREV_MATCH = "navigate.previousMatch"; // MultiRangeInlineEditor.js _previousRange() + exports.CSS_QUICK_EDIT_NEW_RULE = "navigate.newRule"; // CSSInlineEditor.js _handleNewRule() // HELP exports.HELP_CHECK_FOR_UPDATE = "help.checkForUpdate"; // HelpCommandHandlers.js _handleCheckForUpdates() @@ -161,16 +163,23 @@ define(function (require, exports, module) { exports.HELP_TWITTER = "help.twitter"; // HelpCommandHandlers.js _handleLinkMenuItem() // File shell callbacks - string must MATCH string in native code (appshell/command_callbacks.h) - exports.HELP_ABOUT = "help.about"; // HelpCommandHandlers.js _handleAboutDialog() + exports.HELP_ABOUT = "help.about"; // HelpCommandHandlers.js _handleAboutDialog() // APP - exports.APP_RELOAD = "app.reload"; // DocumentCommandHandlers.js handleReload() - exports.APP_RELOAD_WITHOUT_EXTS = "app.reload_without_exts"; // DocumentCommandHandlers.js handleReloadWithoutExts() + exports.APP_RELOAD = "app.reload"; // DocumentCommandHandlers.js handleReload() + exports.APP_RELOAD_WITHOUT_EXTS = "app.reload_without_exts"; // DocumentCommandHandlers.js handleReloadWithoutExts() // File shell callbacks - string must MATCH string in native code (appshell/command_callbacks.h) - exports.APP_ABORT_QUIT = "app.abort_quit"; // DocumentCommandHandlers.js handleAbortQuit() - exports.APP_BEFORE_MENUPOPUP = "app.before_menupopup"; // DocumentCommandHandlers.js handleBeforeMenuPopup() + exports.APP_ABORT_QUIT = "app.abort_quit"; // DocumentCommandHandlers.js handleAbortQuit() + exports.APP_BEFORE_MENUPOPUP = "app.before_menupopup"; // DocumentCommandHandlers.js handleBeforeMenuPopup() + // DEPRECATED: Working Set Commands + _deprecateCommand("FILE_ADD_TO_WORKING_SET", "CMD_ADD_TO_PANE_VIEW_LIST"); + _deprecateCommand("SORT_WORKINGSET_BY_ADDED", "CMD_SORT_PANE_VIEW_LIST_BY_ADDED"); + _deprecateCommand("SORT_WORKINGSET_BY_NAME", "CMD_SORT_PANE_VIEW_LIST_BY_NAME"); + _deprecateCommand("SORT_WORKINGSET_BY_TYPE", "CMD_SORT_PANE_VIEW_LIST_BY_TYPE"); + _deprecateCommand("SORT_WORKINGSET_AUTO", "CMD_TOGGLE_AUTO_SORT"); + // DEPRECATED: Edit commands that were moved from the Edit Menu to the Find Menu _deprecateCommand("EDIT_FIND", "CMD_FIND"); _deprecateCommand("EDIT_FIND_IN_SELECTED", "CMD_FIND_IN_SELECTED"); diff --git a/src/command/DefaultMenus.js b/src/command/DefaultMenus.js index 04e8c8f3a4d..c2f9a60e661 100644 --- a/src/command/DefaultMenus.js +++ b/src/command/DefaultMenus.js @@ -212,24 +212,24 @@ define(function (require, exports, module) { project_cmenu.addMenuDivider(); project_cmenu.addMenuItem(Commands.FILE_REFRESH); - var working_set_cmenu = Menus.registerContextMenu(Menus.ContextMenuIds.WORKING_SET_MENU); - working_set_cmenu.addMenuItem(Commands.FILE_SAVE); - working_set_cmenu.addMenuItem(Commands.FILE_SAVE_AS); - working_set_cmenu.addMenuItem(Commands.FILE_RENAME); - working_set_cmenu.addMenuItem(Commands.NAVIGATE_SHOW_IN_FILE_TREE); - working_set_cmenu.addMenuItem(Commands.NAVIGATE_SHOW_IN_OS); - working_set_cmenu.addMenuDivider(); - working_set_cmenu.addMenuItem(Commands.CMD_FIND_IN_SUBTREE); - working_set_cmenu.addMenuDivider(); - working_set_cmenu.addMenuItem(Commands.FILE_CLOSE); + var pane_view_list_cmenu = Menus.registerContextMenu(Menus.ContextMenuIds.PANE_VIEW_LIST_CONTEXT_MENU); + pane_view_list_cmenu.addMenuItem(Commands.FILE_SAVE); + pane_view_list_cmenu.addMenuItem(Commands.FILE_SAVE_AS); + pane_view_list_cmenu.addMenuItem(Commands.FILE_RENAME); + pane_view_list_cmenu.addMenuItem(Commands.NAVIGATE_SHOW_IN_FILE_TREE); + pane_view_list_cmenu.addMenuItem(Commands.NAVIGATE_SHOW_IN_OS); + pane_view_list_cmenu.addMenuDivider(); + pane_view_list_cmenu.addMenuItem(Commands.CMD_FIND_IN_SUBTREE); + pane_view_list_cmenu.addMenuDivider(); + pane_view_list_cmenu.addMenuItem(Commands.FILE_CLOSE); - var working_set_settings_cmenu = Menus.registerContextMenu(Menus.ContextMenuIds.WORKING_SET_SETTINGS_MENU); - working_set_settings_cmenu.addMenuItem(Commands.SORT_WORKINGSET_BY_ADDED); - working_set_settings_cmenu.addMenuItem(Commands.SORT_WORKINGSET_BY_NAME); - working_set_settings_cmenu.addMenuItem(Commands.SORT_WORKINGSET_BY_TYPE); - working_set_settings_cmenu.addMenuDivider(); - working_set_settings_cmenu.addMenuItem(Commands.SORT_WORKINGSET_AUTO); + var pane_view_list_configuration_menu = Menus.registerContextMenu(Menus.ContextMenuIds.PANE_VIEW_LIST_CONFIG_MENU); + pane_view_list_configuration_menu.addMenuItem(Commands.CMD_SORT_PANE_VIEW_LIST_BY_ADDED); + pane_view_list_configuration_menu.addMenuItem(Commands.CMD_SORT_PANE_VIEW_LIST_BY_NAME); + pane_view_list_configuration_menu.addMenuItem(Commands.CMD_SORT_PANE_VIEW_LIST_BY_TYPE); + pane_view_list_configuration_menu.addMenuDivider(); + pane_view_list_configuration_menu.addMenuItem(Commands.CMD_TOGGLE_AUTO_SORT); var editor_cmenu = Menus.registerContextMenu(Menus.ContextMenuIds.EDITOR_MENU); // editor_cmenu.addMenuItem(Commands.NAVIGATE_JUMPTO_DEFINITION); @@ -292,13 +292,13 @@ define(function (require, exports, module) { }); $("#open-files-container").on("contextmenu", function (e) { - working_set_cmenu.open(e); + pane_view_list_cmenu.open(e); }); /** * Dropdown menu for workspace sorting */ - Menus.ContextMenu.assignContextMenuToSelector("#working-set-option-btn", working_set_settings_cmenu); + Menus.ContextMenu.assignContextMenuToSelector("#working-set-option-btn", pane_view_list_configuration_menu); // Prevent the browser context menu since Brackets creates a custom context menu $(window).contextmenu(function (e) { diff --git a/src/command/Menus.js b/src/command/Menus.js index ed9a3a02fd5..7eb731f5691 100644 --- a/src/command/Menus.js +++ b/src/command/Menus.js @@ -40,6 +40,24 @@ define(function (require, exports, module) { ViewUtils = require("utils/ViewUtils"), DeprecationWarning = require("utils/DeprecationWarning"); + /** + * @private + * Create a deprecation warning and action for updated menu constants + * @param {!string} old Menu Id + * @param {!string} new Menu Id + */ + function _deprecateMenuId(obj, oldId, newId) { + var warning = "Use Menus." + newId + " instead of Menus." + oldId, + newValue = obj[newId]; + + Object.defineProperty(obj, oldId, { + get: function () { + DeprecationWarning.deprecationWarning(warning, true); + return newValue; + } + }); + } + /** * Brackets Application Menu Constants * @enum {string} @@ -58,14 +76,13 @@ define(function (require, exports, module) { * @enum {string} */ var ContextMenuIds = { - EDITOR_MENU: "editor-context-menu", - INLINE_EDITOR_MENU: "inline-editor-context-menu", - PROJECT_MENU: "project-context-menu", - WORKING_SET_MENU: "working-set-context-menu", - WORKING_SET_SETTINGS_MENU: "working-set-settings-context-menu" + EDITOR_MENU: "editor-context-menu", + INLINE_EDITOR_MENU: "inline-editor-context-menu", + PROJECT_MENU: "project-context-menu", + PANE_VIEW_LIST_CONTEXT_MENU: "pane-view-list-context-menu", + PANE_VIEW_LIST_CONFIG_MENU: "pane-view-list-configuration-menu" }; - /** * Brackets Application Menu Section Constants * It is preferred that plug-ins specify the location of new MenuItems @@ -1176,6 +1193,10 @@ define(function (require, exports, module) { return cmenu; } + // Deprecated menu ids + _deprecateMenuId(ContextMenuIds, "WORKING_SET_MENU", "PANE_VIEW_LIST_CONTEXT_MENU"); + _deprecateMenuId(ContextMenuIds, "WORKING_SET_SETTINGS_MENU", "PANE_VIEW_LIST_CONFIG_MENU"); + // Define public API exports.AppMenuBar = AppMenuBar; exports.ContextMenuIds = ContextMenuIds; diff --git a/src/document/DocumentCommandHandlers.js b/src/document/DocumentCommandHandlers.js index da55db368f8..0a958d27beb 100644 --- a/src/document/DocumentCommandHandlers.js +++ b/src/document/DocumentCommandHandlers.js @@ -36,6 +36,7 @@ define(function (require, exports, module) { Commands = require("command/Commands"), ProjectManager = require("project/ProjectManager"), DocumentManager = require("document/DocumentManager"), + MainViewManager = require("view/MainViewManager"), EditorManager = require("editor/EditorManager"), FileSystem = require("filesystem/FileSystem"), FileSystemError = require("filesystem/FileSystemError"), @@ -264,10 +265,10 @@ define(function (require, exports, module) { // So we need to explicitly close the currently viewing image file whose filename is // no longer valid. Calling notifyPathDeleted will close the image vieer and then select // the previously opened text file or show no-editor if none exists. - EditorManager.notifyPathDeleted(fullFilePath); + MainViewManager.notifyPathDeleted(fullFilePath); } else { - // For performance, we do lazy checking of file existence, so it may be in working set - DocumentManager.removeFromWorkingSet(FileSystem.getFileForPath(fullFilePath)); + // For performance, we do lazy checking of file existence, so it may be in pane view list + MainViewManager.removeFromPaneViewList(MainViewManager.FOCUSED_PANE, FileSystem.getFileForPath(fullFilePath)); EditorManager.focusEditor(); } result.reject(); @@ -350,7 +351,7 @@ define(function (require, exports, module) { FileSystem.showOpenDialog(true, false, Strings.OPEN_FILE, _defaultOpenDialogFullPath, null, function (err, paths) { if (!err) { if (paths.length > 0) { - // Add all files to the working set without verifying that + // Add all files to the pane view list without verifying that // they still exist on disk (for faster opening) var filesToOpen = [], filteredPaths = DragAndDrop.filterFilesToOpen(paths); @@ -358,14 +359,14 @@ define(function (require, exports, module) { filteredPaths.forEach(function (file) { filesToOpen.push(FileSystem.getFileForPath(file)); }); - DocumentManager.addListToWorkingSet(filesToOpen); + MainViewManager.addListToPaneViewList(MainViewManager.FOCUSED_PANE, filesToOpen); doOpen(filteredPaths[filteredPaths.length - 1], silent) .done(function (doc) { // doc may be null, i.e. if an image has been opened. - // Then we do not add the opened file to the working set. + // Then we do not add the opened file to the pane view list. if (doc) { - DocumentManager.addToWorkingSet(doc.file); + MainViewManager.addToPaneViewList(MainViewManager.FOCUSED_PANE, doc.file); } _defaultOpenDialogFullPath = FileUtils.getDirectoryPath(EditorManager.getCurrentlyViewedPath()); }) @@ -410,7 +411,7 @@ define(function (require, exports, module) { } /** - * Opens the given file and makes it the current document. Does NOT add it to the working set. + * Opens the given file and makes it the current document. Does NOT add it to the pane view list. * @param {!{fullPath:string}} Params for FILE_OPEN command; * the fullPath string is of the form "path[:lineNumber[:columnNumber]]" * lineNumber and columnNumber are 1-origin: the very first line is line 1, and the very first column is column 1. @@ -446,18 +447,18 @@ define(function (require, exports, module) { } /** - * Opens the given file, makes it the current document, AND adds it to the working set + * Opens the given file, makes it the current document, AND adds it to the pane view list * only if the file does not have a custom viewer. * @param {!{fullPath:string, index:number=, forceRedraw:boolean}} commandData File to open; optional position in - * working set list (defaults to last); optional flag to force working set redraw + * pane view list list (defaults to last); optional flag to force pane view list redraw */ - function handleFileAddToWorkingSet(commandData) { + function handleOpenDocumentInNewPane(commandData) { return handleFileOpen(commandData).done(function (doc) { - // addToWorkingSet is synchronous + // addToPaneViewList is synchronous // When opening a file with a custom viewer, we get a null doc. - // So check it before we add it to the working set. + // So check it before we add it to the pane view list. if (doc) { - DocumentManager.addToWorkingSet(doc.file, commandData.index, commandData.forceRedraw); + MainViewManager.addToPaneViewList(MainViewManager.FOCUSED_PANE, doc.file, commandData.index, commandData.forceRedraw); } }); } @@ -519,7 +520,7 @@ define(function (require, exports, module) { // If a file is currently selected in the tree, put it next to it. // If a directory is currently selected in the tree, put it in it. // If an Untitled document is selected or nothing is selected in the tree, put it at the root of the project. - // (Note: 'selected' may be an item that's selected in the working set and not the tree; but in that case + // (Note: 'selected' may be an item that's selected in the pane view list and not the tree; but in that case // ProjectManager.createNewItem() ignores the baseDir we give it and falls back to the project root on its own) var baseDirEntry, selected = ProjectManager.getSelectedItem(); @@ -545,7 +546,7 @@ define(function (require, exports, module) { } /** - * Create a new untitled document in the working set, and make it the current document. + * Create a new untitled document in the pane view list, and make it the current document. * Promise is resolved (synchronously) with the newly-created Document. */ function handleFileNew() { @@ -756,21 +757,23 @@ define(function (require, exports, module) { result.resolve(newFile); } - // Replace old document with new one in open editor & working set + // Replace old document with new one in open editor & pane view list function openNewFile() { var fileOpenPromise; if (FileViewController.getFileSelectionFocus() === FileViewController.PROJECT_MANAGER) { - // If selection is in the tree, leave working set unchanged - even if orig file is in the list + // If selection is in the tree, leave pane view list unchanged - even if orig file is in the list fileOpenPromise = FileViewController .openAndSelectDocument(path, FileViewController.PROJECT_MANAGER); } else { - // If selection is in working set, replace orig item in place with the new file - var index = DocumentManager.findInWorkingSet(doc.file.fullPath); - // Remove old file from working set; no redraw yet since there's a pause before the new file is opened - DocumentManager.removeFromWorkingSet(doc.file, true); - // Add new file to working set, and ensure we now redraw (even if index hasn't changed) - fileOpenPromise = handleFileAddToWorkingSet({fullPath: path, index: index, forceRedraw: true}); + // If selection is in pane view list, replace orig item in place with the new file + var index = MainViewManager.findInPaneViewList(MainViewManager.ALL_PANES, doc.file.fullPath); + + // Remove old file from pane view list; no redraw yet since there's a pause before the new file is opened + MainViewManager.removeFromPaneViewList(MainViewManager.ALL_PANES, doc.file, true); + + // Add new file to pane view list, and ensure we now redraw (even if index hasn't changed) + fileOpenPromise = handleOpenDocumentInNewPane({fullPath: path, index: index, forceRedraw: true}); } // always configure editor after file is opened @@ -799,9 +802,9 @@ define(function (require, exports, module) { // If there were unsaved changes before Save As, they don't stay with the old // file anymore - so must revert the old doc to match disk content. // Only do this if the doc was dirty: doRevert on a file that is not dirty and - // not in the working set has the side effect of adding it to the working set. + // not in the pane view list has the side effect of adding it to the pane view list. if (doc.isDirty && !(doc.isUntitled())) { - // if the file is dirty it must be in the working set + // if the file is dirty it must be in the pane view list // doRevert is side effect free in this case doRevert(doc).always(openNewFile); } else { @@ -924,7 +927,7 @@ define(function (require, exports, module) { }); return savePromise; } else { - // working set entry that was never actually opened - ignore + // pane view list entry that was never actually opened - ignore filesAfterSave.push(file); return (new $.Deferred()).resolve().promise(); } @@ -940,7 +943,7 @@ define(function (require, exports, module) { * @return {$.Promise} */ function saveAll() { - return _saveFileList(DocumentManager.getWorkingSet()); + return _saveFileList(MainViewManager.getPaneViewList(MainViewManager.FOCUSED_PANE)); } /** @@ -979,7 +982,7 @@ define(function (require, exports, module) { } /** - * Closes the specified file: removes it from the working set, and closes the main editor if one + * Closes the specified file: removes it from the pane view list, and closes the main editor if one * is open. Prompts user about saving changes first, if document is dirty. * * @param {?{file: File, promptOnly:boolean}} commandData Optional bag of arguments: @@ -1003,10 +1006,10 @@ define(function (require, exports, module) { _forceClose = commandData._forceClose; } - // utility function for handleFileClose: closes document & removes from working set + // utility function for handleFileClose: closes document & removes from pane view list function doClose(file) { if (!promptOnly) { - // This selects a different document if the working set has any other options + // This selects a different document if the pane view list has any other options DocumentManager.closeFullEditor(file); EditorManager.focusEditor(); @@ -1017,7 +1020,7 @@ define(function (require, exports, module) { function doCloseCustomViewer() { if (!promptOnly) { - var nextFile = DocumentManager.getNextPrevFile(1); + var nextFile = MainViewManager.traversePaneViewListByMRU(MainViewManager.FOCUSED_PANE, 1); if (nextFile) { // opening a text file will automatically close the custom viewer. // This is done in the currentDocumentChange handler in EditorManager @@ -1218,7 +1221,13 @@ define(function (require, exports, module) { result.done(function (listAfterSave) { listAfterSave = listAfterSave || list; if (!promptOnly) { - DocumentManager.removeListFromWorkingSet(listAfterSave, clearCurrentDoc); + // Call clear current document here because we need the editor + // to close the current document and this is the only way to + // do that at the moment. + if (clearCurrentDoc) { + DocumentManager.clearCurrentDocument(); + } + MainViewManager.removeListFromPaneViewList(MainViewManager.FOCUSED_PANE, listAfterSave); } }); @@ -1234,7 +1243,7 @@ define(function (require, exports, module) { * @return {$.Promise} a promise that is resolved when all files are closed */ function handleFileCloseAll(commandData) { - return _closeList(DocumentManager.getWorkingSet(), + return _closeList(MainViewManager.getPaneViewList(MainViewManager.FOCUSED_PANE), (commandData && commandData.promptOnly), true).done(function () { if (!DocumentManager.getCurrentDocument()) { EditorManager._closeCustomViewer(); @@ -1325,7 +1334,7 @@ define(function (require, exports, module) { // Prefer selected sidebar item (which could be a folder) var entry = ProjectManager.getSelectedItem(); if (!entry) { - // Else use current file (not selected in ProjectManager if not visible in tree or working set) + // Else use current file (not selected in ProjectManager if not visible in tree or pane view list) var doc = DocumentManager.getCurrentDocument(); entry = doc && doc.file; } @@ -1370,7 +1379,7 @@ define(function (require, exports, module) { /** Navigate to the next/previous (MRU) document. Don't update MRU order yet */ function goNextPrevDoc(inc) { - var file = DocumentManager.getNextPrevFile(inc); + var file = MainViewManager.traversePaneViewListByMRU(MainViewManager.FOCUSED_PANE, inc); if (file) { DocumentManager.beginDocumentNavigation(); CommandManager.execute(Commands.FILE_OPEN, { fullPath: file.fullPath }); @@ -1427,7 +1436,7 @@ define(function (require, exports, module) { } } - /** Show the selected sidebar (tree or working set) item in Finder/Explorer */ + /** Show the selected sidebar (tree or pane view list) item in Finder/Explorer */ function handleShowInOS() { var entry = ProjectManager.getSelectedItem(); if (entry) { @@ -1589,7 +1598,7 @@ define(function (require, exports, module) { // Exported for unit testing only exports._parseDecoratedPath = _parseDecoratedPath; - + // Set some command strings var quitString = Strings.CMD_QUIT, showInOS = Strings.CMD_SHOW_IN_OS; @@ -1601,26 +1610,26 @@ define(function (require, exports, module) { } // Register global commands - CommandManager.register(Strings.CMD_FILE_OPEN, Commands.FILE_OPEN, handleFileOpen); - CommandManager.register(Strings.CMD_ADD_TO_WORKING_SET, Commands.FILE_ADD_TO_WORKING_SET, handleFileAddToWorkingSet); - CommandManager.register(Strings.CMD_FILE_NEW_UNTITLED, Commands.FILE_NEW_UNTITLED, handleFileNew); - CommandManager.register(Strings.CMD_FILE_NEW, Commands.FILE_NEW, handleFileNewInProject); - CommandManager.register(Strings.CMD_FILE_NEW_FOLDER, Commands.FILE_NEW_FOLDER, handleNewFolderInProject); - CommandManager.register(Strings.CMD_FILE_SAVE, Commands.FILE_SAVE, handleFileSave); - CommandManager.register(Strings.CMD_FILE_SAVE_ALL, Commands.FILE_SAVE_ALL, handleFileSaveAll); - CommandManager.register(Strings.CMD_FILE_SAVE_AS, Commands.FILE_SAVE_AS, handleFileSaveAs); - CommandManager.register(Strings.CMD_FILE_RENAME, Commands.FILE_RENAME, handleFileRename); - CommandManager.register(Strings.CMD_FILE_DELETE, Commands.FILE_DELETE, handleFileDelete); - - CommandManager.register(Strings.CMD_FILE_CLOSE, Commands.FILE_CLOSE, handleFileClose); - CommandManager.register(Strings.CMD_FILE_CLOSE_ALL, Commands.FILE_CLOSE_ALL, handleFileCloseAll); - CommandManager.register(Strings.CMD_FILE_CLOSE_LIST, Commands.FILE_CLOSE_LIST, handleFileCloseList); - CommandManager.register(quitString, Commands.FILE_QUIT, handleFileQuit); - - CommandManager.register(Strings.CMD_NEXT_DOC, Commands.NAVIGATE_NEXT_DOC, handleGoNextDoc); - CommandManager.register(Strings.CMD_PREV_DOC, Commands.NAVIGATE_PREV_DOC, handleGoPrevDoc); - CommandManager.register(Strings.CMD_SHOW_IN_TREE, Commands.NAVIGATE_SHOW_IN_FILE_TREE, handleShowInTree); - CommandManager.register(showInOS, Commands.NAVIGATE_SHOW_IN_OS, handleShowInOS); + CommandManager.register(Strings.CMD_FILE_OPEN, Commands.FILE_OPEN, handleFileOpen); + CommandManager.register(Strings.CMD_ADD_TO_PANE_VIEW_LIST, Commands.CMD_ADD_TO_PANE_VIEW_LIST, handleOpenDocumentInNewPane); + CommandManager.register(Strings.CMD_FILE_NEW_UNTITLED, Commands.FILE_NEW_UNTITLED, handleFileNew); + CommandManager.register(Strings.CMD_FILE_NEW, Commands.FILE_NEW, handleFileNewInProject); + CommandManager.register(Strings.CMD_FILE_NEW_FOLDER, Commands.FILE_NEW_FOLDER, handleNewFolderInProject); + CommandManager.register(Strings.CMD_FILE_SAVE, Commands.FILE_SAVE, handleFileSave); + CommandManager.register(Strings.CMD_FILE_SAVE_ALL, Commands.FILE_SAVE_ALL, handleFileSaveAll); + CommandManager.register(Strings.CMD_FILE_SAVE_AS, Commands.FILE_SAVE_AS, handleFileSaveAs); + CommandManager.register(Strings.CMD_FILE_RENAME, Commands.FILE_RENAME, handleFileRename); + CommandManager.register(Strings.CMD_FILE_DELETE, Commands.FILE_DELETE, handleFileDelete); + + CommandManager.register(Strings.CMD_FILE_CLOSE, Commands.FILE_CLOSE, handleFileClose); + CommandManager.register(Strings.CMD_FILE_CLOSE_ALL, Commands.FILE_CLOSE_ALL, handleFileCloseAll); + CommandManager.register(Strings.CMD_FILE_CLOSE_LIST, Commands.FILE_CLOSE_LIST, handleFileCloseList); + CommandManager.register(quitString, Commands.FILE_QUIT, handleFileQuit); + + CommandManager.register(Strings.CMD_NEXT_DOC, Commands.NAVIGATE_NEXT_DOC, handleGoNextDoc); + CommandManager.register(Strings.CMD_PREV_DOC, Commands.NAVIGATE_PREV_DOC, handleGoPrevDoc); + CommandManager.register(Strings.CMD_SHOW_IN_TREE, Commands.NAVIGATE_SHOW_IN_FILE_TREE, handleShowInTree); + CommandManager.register(showInOS, Commands.NAVIGATE_SHOW_IN_OS, handleShowInOS); // These commands have no UI representation and are only used internally CommandManager.registerInternal(Commands.APP_ABORT_QUIT, handleAbortQuit); diff --git a/src/document/DocumentManager.js b/src/document/DocumentManager.js index 6f972df009f..750a70172a7 100644 --- a/src/document/DocumentManager.js +++ b/src/document/DocumentManager.js @@ -26,8 +26,9 @@ /*global define, $ */ /** - * DocumentManager maintains a list of currently 'open' Documents. It also owns the list of files in - * the working set, and the notion of which Document is currently shown in the main editor UI area. + * DocumentManager maintains a list of currently 'open' Documents. The DocumentManager is responsible + * manifesting documents into the editor, closing documents, coordinating document operations and + * dispatching certain document events. * * Document is the model for a file's contents; it dispatches events whenever those contents change. * To transiently inspect a file's content, simply get a Document and call getText() on it. However, @@ -58,24 +59,15 @@ * Document that has been saved. * - documentRefreshed -- When a Document's contents have been reloaded from disk. The 2nd arg to the * listener is the Document that has been refreshed. + * + * NOTE: WorkingSet APIs have been deprecated and have moved to MainViewManager as PaneViewList APIs + * Some WorkingSet APIs that have been identified as being used by 3rd party extensions will + * emit deprecation warnings and call the PaneViewList APIS to maintain backwards compatibility * - * - currentDocumentChange -- When the value of getCurrentDocument() changes. 2nd argument to the listener - * is the current document and 3rd argument is the previous document. - * - * To listen for working set changes, you must listen to *all* of these events: - * - workingSetAdd -- When a file is added to the working set (see getWorkingSet()). The 2nd arg - * to the listener is the added File, and the 3rd arg is the index it was inserted at. - * - workingSetAddList -- When multiple files are added to the working set (e.g. project open, multiple file open). - * The 2nd arg to the listener is the array of added File objects. - * - workingSetRemove -- When a file is removed from the working set (see getWorkingSet()). The - * 2nd arg to the listener is the removed File. - * - workingSetRemoveList -- When multiple files are removed from the working set (e.g. project close). - * The 2nd arg to the listener is the array of removed File objects. - * - workingSetSort -- When the workingSet array is reordered without additions or removals. - * Listener receives no arguments. - * - * - workingSetDisableAutoSorting -- Dispatched in addition to workingSetSort when the reorder was caused - * by manual dragging and dropping. Listener receives no arguments. + * - currentDocumentChange -- This is being deprecated and is currently ony used as a shim to assist + * the document open process so that the editor will actually open or close the desired document. + * This will change accordingly once work begins to refactor EditorManager to be a view provider + * and open documents directly. * * - fileNameChange -- When the name of a file or folder has changed. The 2nd arg is the old name. * The 3rd arg is the new name. @@ -91,7 +83,10 @@ define(function (require, exports, module) { var _ = require("thirdparty/lodash"); - var DocumentModule = require("document/Document"), + var AppInit = require("utils/AppInit"), + DocumentModule = require("document/Document"), + DeprecationWarning = require("utils/DeprecationWarning"), + MainViewManager = require("view/MainViewManager"), ProjectManager = require("project/ProjectManager"), EditorManager = require("editor/EditorManager"), FileSyncManager = require("project/FileSyncManager"), @@ -106,79 +101,126 @@ define(function (require, exports, module) { LanguageManager = require("language/LanguageManager"), Strings = require("strings"); - /** - * @private - * @see DocumentManager.getCurrentDocument() - */ - var _currentDocument = null; - - /** - * Returns the Document that is currently open in the editor UI. May be null. - * When this changes, DocumentManager dispatches a "currentDocumentChange" event. The current - * document always has a backing Editor (Document._masterEditor != null) and is thus modifiable. - * @return {?Document} - */ - function getCurrentDocument() { - return _currentDocument; - } - + /** * @private * Random path prefix for untitled documents */ var _untitledDocumentPath = "/_brackets_" + _.random(10000000, 99999999); + /** - * @private - * @type {Array.} - * @see DocumentManager.getWorkingSet() + * While true, the MRU order is frozen + * @type {boolean} */ - var _workingSet = []; + var _documentNavPending = false; /** + * All documents with refCount > 0. Maps Document.file.id -> Document. * @private - * Contains the same set of items as _workingSet, but ordered by how recently they were _currentDocument (0 = most recent). - * @type {Array.} + * @type {Object.} */ - var _workingSetMRUOrder = []; + var _openDocuments = {}; /** - * @private - * Contains the same set of items as _workingSet, but ordered in the way they where added to _workingSet (0 = last added). - * @type {Array.} + * Creates a deprecation warning event handler + * @param {!string} the event being deprecated + * @param {!string} the new event to use + */ + function _deprecateEvent(oldEventName, newEventName) { + DeprecationWarning.deprecateEvent(exports, + MainViewManager, + oldEventName, + newEventName, + "DocumentManager." + oldEventName, + "MainViewManager." + newEventName); + } + + /** + * Returns the existing open Document for the given file, or null if the file is not open ('open' + * means referenced by the UI somewhere). If you will hang onto the Document, you must addRef() + * it; see {@link getDocumentForPath()} for details. + * @param {!string} fullPath + * @return {?Document} */ - var _workingSetAddedOrder = []; + function getOpenDocumentForPath(fullPath) { + var id; + + if (!fullPath) { + return null; + } + + // Need to walk all open documents and check for matching path. We can't + // use getFileForPath(fullPath).id since the file it returns won't match + // an Untitled document's InMemoryFile. + for (id in _openDocuments) { + if (_openDocuments.hasOwnProperty(id)) { + if (_openDocuments[id].file.fullPath === fullPath) { + return _openDocuments[id]; + } + } + } + return null; + } + /** - * While true, the MRU order is frozen - * @type {boolean} + * [shim] Returns a document open for the currently focused pane's editor + * @return {?Document} */ - var _documentNavPending = false; + function _getCurrentDocument() { + // using getCurrentFullEditor() will return the editor whether it has focus or not + // this doesn't work in scenarios where you want the active editor's document + // even though it does not have focus (such as when clicking on another element (toolbar, menu, etc...) + // So we'll have to do revise this to call + // MainViewManager.getTargetPane().getCurrentFullEditor().getDocument() + return getOpenDocumentForPath(EditorManager.getCurrentlyViewedPath()); + } + + /** + * Returns the Document that is currently open in the editor UI. May be null. + * @return {?Document} + */ + function getCurrentDocument() { + // NOTE: This will eventually be deprecated and a deprecation warning will be added here + // the shim _getCurrentDocument() is being used because the MainViewManager has + // not been fully fleshed out to support a method for getting the current + // editor. Once that has been done then the instances of getCurrentDocument in + // Brackets will change to use that API and this function will emit a deprecation + // warning for extensions still using DocumentManager.getCurrentDocument(); + return _getCurrentDocument(); + } + + /** - * All documents with refCount > 0. Maps Document.file.id -> Document. - * @private - * @type {Object.} + * [shim] Clears the current document. This is usually in response to a close all command + * or close current document when there are no other documents left to open. This */ - var _openDocuments = {}; + function clearCurrentDocument() { + // Change model & dispatch event + var previousDocument = _getCurrentDocument(); + + if (!previousDocument) { + return; + } + + // (this event triggers EditorManager to actually clear the editor UI) + $(exports).triggerHandler("currentDocumentChange", [null, previousDocument]); + } /** + * @deprecated Use MainViewManager.getPaneViewList() instead * Returns a list of items in the working set in UI list order. May be 0-length, but never null. - * - * When a file is added this list, DocumentManager dispatches a "workingSetAdd" event. - * When a file is removed from list, DocumentManager dispatches a "workingSetRemove" event. - * To listen for ALL changes to this list, you must listen for both events. - * - * Which items belong in the working set is managed entirely by DocumentManager. Callers cannot - * (yet) change this collection on their own. - * * @return {Array.} */ function getWorkingSet() { - return _.clone(_workingSet); + DeprecationWarning.deprecationWarning("Use MainViewManager.getPaneViewList() instead of DocumentManager.getWorkingSet()", true); + return MainViewManager.getPaneViewList(MainViewManager.FOCUSED_PANE); } /** + * @deprecated Use MainViewManager.findInPaneViewList() instead * Returns the index of the file matching fullPath in the working set. * Returns -1 if not found. * @param {!string} fullPath @@ -187,23 +229,36 @@ define(function (require, exports, module) { * @return {number} index */ function findInWorkingSet(fullPath, list) { - list = list || _workingSet; - - return _.findIndex(list, function (file, i) { - return file.fullPath === fullPath; - }); + DeprecationWarning.deprecationWarning("Use MainViewManager.findInPaneViewList() instead of DocumentManager.findInWorkingSet()", true); + if (list) { + DeprecationWarning.deprecationWarning("DocumentManager.findInWorkingSet() no longer supports an arbitrary array", true); + return []; + } + return MainViewManager.findInPaneViewList(MainViewManager.ALL_PANES, fullPath); } /** - * Returns the index of the file matching fullPath in _workingSetAddedOrder. - * Returns -1 if not found. - * @param {!string} fullPath - * @return {number} index + * @deprecated Use MainViewManager.removeListFromPaneViewList() instead + * Removes a list of files from the working set + * @param {Array.=} list Pass this arg to search a different array of files. Internal + * use only. + * @param {boolean=} true to close the current document too [deprecated] */ - function findInWorkingSetAddedOrder(fullPath) { - return findInWorkingSet(fullPath, _workingSetAddedOrder); - } + function removeListFromWorkingSet(list, clearCurrentDocument) { + DeprecationWarning.deprecationWarning("Use MainViewManager.removeListFromPaneViewList() instead of DocumentManager.removeListFromWorkingSet()", true); + if (!list) { + return; + } + + if (clearCurrentDocument) { + DeprecationWarning.deprecationWarning("clearCurrentDocument is not a supported option for MainViewManager.removeListFromPaneViewList() Use DocumentManager.clearCurrentDocument() instead", true); + clearCurrentDocument(); + } + + MainViewManager.removeListFromPaneViewList(MainViewManager.FOCUSED_PANE, list); + } + /** * Returns all Documents that are 'open' in the UI somewhere (for now, this means open in an * inline editor and/or a full-size editor). Only these Documents can be modified, and only @@ -223,8 +278,9 @@ define(function (require, exports, module) { /** - * Adds the given file to the end of the working set list, if it is not already in the list - * and it does not have a custom viewer. + * @deprecated Use MainViewManager.addToPaneViewList() instead + * Adds the given file to the end of the working set list, if it is not + * already in the list and it does not have a custom viewer. * Does not change which document is currently open in the editor. Completes synchronously. * @param {!File} file * @param {number=} index Position to add to list (defaults to last); -1 is ignored @@ -232,51 +288,12 @@ define(function (require, exports, module) { * (useful if suppressRedraw was used with removeFromWorkingSet() earlier) */ function addToWorkingSet(file, index, forceRedraw) { - var indexRequested = (index !== undefined && index !== null && index !== -1); - - // If the file has a custom viewer, then don't add it to the working set. - if (EditorManager.getCustomViewerForPath(file.fullPath)) { - return; - } - - // If doc is already in working set, don't add it again - var curIndex = findInWorkingSet(file.fullPath); - if (curIndex !== -1) { - // File is in working set, but not at the specifically requested index - only need to reorder - if (forceRedraw || (indexRequested && curIndex !== index)) { - var entry = _workingSet.splice(curIndex, 1)[0]; - _workingSet.splice(index, 0, entry); - $(exports).triggerHandler("workingSetSort"); - } - return; - } - - if (!indexRequested) { - // If no index is specified, just add the file to the end of the working set. - _workingSet.push(file); - } else { - // If specified, insert into the working set list at this 0-based index - _workingSet.splice(index, 0, file); - } - - // Add to MRU order: either first or last, depending on whether it's already the current doc or not - if (_currentDocument && _currentDocument.file.fullPath === file.fullPath) { - _workingSetMRUOrder.unshift(file); - } else { - _workingSetMRUOrder.push(file); - } - - // Add first to Added order - _workingSetAddedOrder.unshift(file); - - // Dispatch event - if (!indexRequested) { - index = _workingSet.length - 1; - } - $(exports).triggerHandler("workingSetAdd", [file, index]); + DeprecationWarning.deprecationWarning("Use MainViewManager.addToPaneViewList() instead of DocumentManager.addToWorkingSet()", true); + MainViewManager.addToPaneViewList(MainViewManager.FOCUSED_PANE, file, index, forceRedraw); } /** + * @deprecated Use MainViewManager.addListToPaneViewList() instead * Adds the given file list to the end of the working set list. * If a file in the list has its own custom viewer, then it * is not added into the working set. @@ -286,37 +303,12 @@ define(function (require, exports, module) { * @param {!Array.} fileList */ function addListToWorkingSet(fileList) { - var uniqueFileList = []; - - // Process only files not already in working set - fileList.forEach(function (file, index) { - // If doc has a custom viewer, then don't add it to the working set. - // Or if doc is already in working set, don't add it again. - if (!EditorManager.getCustomViewerForPath(file.fullPath) && - findInWorkingSet(file.fullPath) === -1) { - uniqueFileList.push(file); - - // Add - _workingSet.push(file); - - // Add to MRU order: either first or last, depending on whether it's already the current doc or not - if (_currentDocument && _currentDocument.file.fullPath === file.fullPath) { - _workingSetMRUOrder.unshift(file); - } else { - _workingSetMRUOrder.push(file); - } - - // Add first to Added order - _workingSetAddedOrder.splice(index, 1, file); - } - }); - - - // Dispatch event - $(exports).triggerHandler("workingSetAddList", [uniqueFileList]); + DeprecationWarning.deprecationWarning("Use MainViewManager.addListToPaneViewList() instead of DocumentManager.addListToWorkingSet()", true); + MainViewManager.addListToPaneViewList(MainViewManager.FOCUSED_PANE, fileList); } /** + * @deprecated Use MainViewManager.removeFromPaneViewList() instead * Warning: low level API - use FILE_CLOSE command in most cases. * Removes the given file from the working set list, if it was in the list. Does not change * the current editor even if it's for this file. Does not prompt for unsaved changes. @@ -324,81 +316,19 @@ define(function (require, exports, module) { * @param {boolean=} true to suppress redraw after removal */ function removeFromWorkingSet(file, suppressRedraw) { - // If doc isn't in working set, do nothing - var index = findInWorkingSet(file.fullPath); - if (index === -1) { - return; - } - - // Remove - _workingSet.splice(index, 1); - _workingSetMRUOrder.splice(findInWorkingSet(file.fullPath, _workingSetMRUOrder), 1); - _workingSetAddedOrder.splice(findInWorkingSet(file.fullPath, _workingSetAddedOrder), 1); - - // Dispatch event - $(exports).triggerHandler("workingSetRemove", [file, suppressRedraw]); - } - - /** - * Removes all files from the working set list. - */ - function _removeAllFromWorkingSet() { - var fileList = _workingSet; - - // Remove all - _workingSet = []; - _workingSetMRUOrder = []; - _workingSetAddedOrder = []; - - // Dispatch event - $(exports).triggerHandler("workingSetRemoveList", [fileList]); + DeprecationWarning.deprecationWarning("Use MainViewManager.removeFromPaneViewList() instead of DocumentManager.removeFromWorkingSet()", true); + MainViewManager.removeFromPaneViewList(MainViewManager.FOCUSED_PANE, file, suppressRedraw); } + /** * Moves document to the front of the MRU list, IF it's in the working set; no-op otherwise. * @param {!Document} */ function _markMostRecent(doc) { - var mruI = findInWorkingSet(doc.file.fullPath, _workingSetMRUOrder); - if (mruI !== -1) { - _workingSetMRUOrder.splice(mruI, 1); - _workingSetMRUOrder.unshift(doc.file); - } - } - - - /** - * Mutually exchanges the files at the indexes passed by parameters. - * @param {number} index Old file index - * @param {number} index New file index - */ - function swapWorkingSetIndexes(index1, index2) { - var length = _workingSet.length - 1; - var temp; - - if (index1 >= 0 && index2 <= length && index1 >= 0 && index2 <= length) { - temp = _workingSet[index1]; - _workingSet[index1] = _workingSet[index2]; - _workingSet[index2] = temp; - - $(exports).triggerHandler("workingSetSort"); - $(exports).triggerHandler("workingSetDisableAutoSorting"); - } - } - - /** - * Sorts _workingSet using the compare function - * @param {function(File, File): number} compareFn The function that will be used inside JavaScript's - * sort function. The return a value should be >0 (sort a to a lower index than b), =0 (leaves a and b - * unchanged with respect to each other) or <0 (sort b to a lower index than a) and must always returns - * the same value when given a specific pair of elements a and b as its two arguments. - * Documentation: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/sort - */ - function sortWorkingSet(compareFn) { - _workingSet.sort(compareFn); - $(exports).triggerHandler("workingSetSort"); + MainViewManager.makePaneViewMostRecent(MainViewManager.FOCUSED_PANE, doc.file); } - + /** * Indicate that changes to currentDocument are temporary for now, and should not update the MRU @@ -418,7 +348,7 @@ define(function (require, exports, module) { if (_documentNavPending) { _documentNavPending = false; - _markMostRecent(_currentDocument); + _markMostRecent(_getCurrentDocument()); } } @@ -430,33 +360,8 @@ define(function (require, exports, module) { * @return {?File} null if working set empty */ function getNextPrevFile(inc) { - if (inc !== -1 && inc !== +1) { - console.error("Illegal argument: inc = " + inc); - return null; - } - - if (EditorManager.getCurrentlyViewedPath()) { - var mruI = findInWorkingSet(EditorManager.getCurrentlyViewedPath(), _workingSetMRUOrder); - if (mruI === -1) { - // If doc not in working set, return most recent working set item - if (_workingSetMRUOrder.length > 0) { - return _workingSetMRUOrder[0]; - } - } else { - // If doc is in working set, return next/prev item with wrap-around - var newI = mruI + inc; - if (newI >= _workingSetMRUOrder.length) { - newI = 0; - } else if (newI < 0) { - newI = _workingSetMRUOrder.length - 1; - } - - return _workingSetMRUOrder[newI]; - } - } - - // If no doc open or working set empty, there is no "next" file - return null; + DeprecationWarning.deprecationWarning("Use MainViewManager.traversePaneViewListByMRU() instead of DocumentManager.getNextPrevFile()", true); + return MainViewManager.traversePaneViewListByMRU(MainViewManager.FOCUSED_PANE, inc); } @@ -469,9 +374,10 @@ define(function (require, exports, module) { * working set. */ function setCurrentDocument(doc) { + var currentDocument = _getCurrentDocument(); // If this doc is already current, do nothing - if (_currentDocument === doc) { + if (currentDocument === doc) { return; } @@ -480,40 +386,21 @@ define(function (require, exports, module) { // If file is untitled or otherwise not within project tree, add it to // working set right now (don't wait for it to become dirty) if (doc.isUntitled() || !ProjectManager.isWithinProject(doc.file.fullPath)) { - addToWorkingSet(doc.file); + MainViewManager.addToPaneViewList(MainViewManager.FOCUSED_PANE, doc.file); } + + // (this event triggers EditorManager to actually switch editors in the UI) + $(exports).triggerHandler("currentDocumentChange", [doc, currentDocument]); + // Adjust MRU working set ordering (except while in the middle of a Ctrl+Tab sequence) if (!_documentNavPending) { _markMostRecent(doc); } - - // Make it the current document - var previousDocument = _currentDocument; - _currentDocument = doc; - $(exports).triggerHandler("currentDocumentChange", [_currentDocument, previousDocument]); - // (this event triggers EditorManager to actually switch editors in the UI) - PerfUtils.addMeasurement(perfTimerName); } - /** Changes currentDocument to null, causing no full Editor to be shown in the UI */ - function _clearCurrentDocument() { - // If editor already blank, do nothing - if (!_currentDocument) { - return; - } else { - // Change model & dispatch event - var previousDocument = _currentDocument; - _currentDocument = null; - // (this event triggers EditorManager to actually clear the editor UI) - $(exports).triggerHandler("currentDocumentChange", [_currentDocument, previousDocument]); - } - } - - - /** * Warning: low level API - use FILE_CLOSE command in most cases. * Closes the full editor for the given file (if there is one), and removes it from the working @@ -529,10 +416,11 @@ define(function (require, exports, module) { function closeFullEditor(file, skipAutoSelect) { // If this was the current document shown in the editor UI, we're going to switch to a // different document (or none if working set has no other options) - if (_currentDocument && _currentDocument.file.fullPath === file.fullPath) { + var currentDocument = _getCurrentDocument(); + if (currentDocument && currentDocument.file.fullPath === file.fullPath) { // Get next most recent doc in the MRU order - var nextFile = getNextPrevFile(1); - if (nextFile && nextFile.fullPath === _currentDocument.file.fullPath) { + var nextFile = MainViewManager.traversePaneViewListByMRU(MainViewManager.FOCUSED_PANE, 1); + if (nextFile && nextFile.fullPath === currentDocument.file.fullPath) { // getNextPrevFile() might return the file we're about to close if it's the only one open (due to wraparound) nextFile = null; } @@ -540,10 +428,6 @@ define(function (require, exports, module) { // Switch editor to next document (or blank it out) if (nextFile && !skipAutoSelect) { CommandManager.execute(Commands.FILE_OPEN, { fullPath: nextFile.fullPath }) - .done(function () { - // (Now we're guaranteed that the current document is not the one we're closing) - console.assert(!(_currentDocument && _currentDocument.file.fullPath === file.fullPath)); - }) .fail(function () { // File chosen to be switched to could not be opened, and the original file // is still in editor. Close it again so code will try to open the next file, @@ -551,13 +435,13 @@ define(function (require, exports, module) { closeFullEditor(file); }); } else { - _clearCurrentDocument(); + clearCurrentDocument(); } } // Remove closed doc from working set, if it was in there // This happens regardless of whether the document being closed was the current one or not - removeFromWorkingSet(file); + MainViewManager.removeFromPaneViewList(MainViewManager.FOCUSED_PANE, file); // Note: EditorManager will dispose the closed document's now-unneeded editor either in // response to the editor-swap call above, or the removeFromWorkingSet() call, depending on @@ -569,35 +453,10 @@ define(function (require, exports, module) { * unsaved changes, so the UI should confirm with the user before calling this. */ function closeAll() { - _clearCurrentDocument(); - _removeAllFromWorkingSet(); + clearCurrentDocument(); + MainViewManager.removeAllFromPaneViewList(MainViewManager.ALL_PANES); } - function removeListFromWorkingSet(list, clearCurrentDocument) { - var fileList = [], index; - - if (!list) { - return; - } - - if (clearCurrentDocument) { - _clearCurrentDocument(); - } - - list.forEach(function (file) { - index = findInWorkingSet(file.fullPath); - - if (index !== -1) { - fileList.push(_workingSet[index]); - - _workingSet.splice(index, 1); - _workingSetMRUOrder.splice(findInWorkingSet(file.fullPath, _workingSetMRUOrder), 1); - _workingSetAddedOrder.splice(findInWorkingSet(file.fullPath, _workingSetAddedOrder), 1); - } - }); - - $(exports).triggerHandler("workingSetRemoveList", [fileList]); - } /** @@ -616,28 +475,6 @@ define(function (require, exports, module) { }); } - /** - * Returns the existing open Document for the given file, or null if the file is not open ('open' - * means referenced by the UI somewhere). If you will hang onto the Document, you must addRef() - * it; see {@link getDocumentForPath()} for details. - * @param {!string} fullPath - * @return {?Document} - */ - function getOpenDocumentForPath(fullPath) { - var id; - - // Need to walk all open documents and check for matching path. We can't - // use getFileForPath(fullPath).id since the file it returns won't match - // an Untitled document's InMemoryFile. - for (id in _openDocuments) { - if (_openDocuments.hasOwnProperty(id)) { - if (_openDocuments[id].file.fullPath === fullPath) { - return _openDocuments[id]; - } - } - } - return null; - } /** * Gets an existing open Document for the given file, or creates a new one if the Document is @@ -806,98 +643,6 @@ define(function (require, exports, module) { } } - - /** - * @private - * Preferences callback. Saves the state of the working set. - */ - function _savePreferences() { - // save the working set file paths - var files = [], - isActive = false, - workingSet = getWorkingSet(), - currentDoc = getCurrentDocument(), - projectRoot = ProjectManager.getProjectRoot(), - context = { location : { scope: "user", - layer: "project", - layerID: projectRoot.fullPath } }; - - if (!projectRoot) { - return; - } - - workingSet.forEach(function (file, index) { - // Do not persist untitled document paths - if (!(file instanceof InMemoryFile)) { - // flag the currently active editor - isActive = currentDoc && (file.fullPath === currentDoc.file.fullPath); - - // save editor UI state for just the working set - var viewState = EditorManager._getViewState(file.fullPath); - - files.push({ - file: file.fullPath, - active: isActive, - viewState: viewState - }); - } - }); - - // Writing out working set files using the project layer specified in 'context'. - PreferencesManager.setViewState("project.files", files, context); - } - - /** - * @private - * Initializes the working set. - */ - function _projectOpen(e) { - // file root is appended for each project - var projectRoot = ProjectManager.getProjectRoot(), - files = [], - context = { location : { scope: "user", - layer: "project" } }; - - files = PreferencesManager.getViewState("project.files", context); - - console.assert(Object.keys(_openDocuments).length === 0); // no files leftover from prev proj - - if (!files) { - return; - } - - var filesToOpen = [], - viewStates = {}, - activeFile; - - // Add all files to the working set without verifying that - // they still exist on disk (for faster project switching) - files.forEach(function (value, index) { - filesToOpen.push(FileSystem.getFileForPath(value.file)); - if (value.active) { - activeFile = value.file; - } - if (value.viewState) { - viewStates[value.file] = value.viewState; - } - }); - addListToWorkingSet(filesToOpen); - - // Allow for restoring saved editor UI state - EditorManager._resetViewStates(viewStates); - - // Initialize the active editor - if (!activeFile && _workingSet.length > 0) { - activeFile = _workingSet[0].fullPath; - } - - if (activeFile) { - var promise = CommandManager.execute(Commands.FILE_OPEN, { fullPath: activeFile }); - // Add this promise to the event's promises to signal that this handler isn't done yet - e.promises.push(promise); - } - } - /** * Called after a file or folder name has changed. This function is responsible * for updating underlying model data and notifying all views of the change. @@ -926,12 +671,23 @@ define(function (require, exports, module) { * @param {string} path The path of the file/folder that has been deleted */ function notifyPathDeleted(path) { - /* FileSyncManager.syncOpenDocuments() does all the work of closing files - in the working set and notifying the user of any unsaved changes. */ - FileSyncManager.syncOpenDocuments(Strings.FILE_DELETED_TITLE); - - // Send a "pathDeleted" event. This will trigger the views to update. - $(exports).triggerHandler("pathDeleted", path); + /* + * This code was migrated from Project Manager to start condensing the + * functionality into MainViewManager and reduce dependencies. Unfortunately, + * the case of deleting the current document still needs to go through the + * syncOpenDocuments API and dispatch the pathDeleted event. This will be + * refactored soon. + */ + if (getCurrentDocument()) { + /* FileSyncManager.syncOpenDocuments() does all the work of closing files + in the working set and notifying the user of any unsaved changes. */ + FileSyncManager.syncOpenDocuments(Strings.FILE_DELETED_TITLE); + + // Send a "pathDeleted" event. This will trigger the views to update. + $(exports).triggerHandler("pathDeleted", path); + } else { + MainViewManager.notifyPathDeleted(path); + } } /** @@ -989,7 +745,7 @@ define(function (require, exports, module) { .on("_dirtyFlagChange", function (event, doc) { $(exports).triggerHandler("dirtyFlagChange", doc); if (doc.isDirty) { - addToWorkingSet(doc.file); + MainViewManager.addToPaneViewList(MainViewManager.FOCUSED_PANE, doc.file); } }) .on("_documentSaved", function (event, doc) { @@ -1016,6 +772,26 @@ define(function (require, exports, module) { return null; } + + /* + * Setup an extensionsReady handler to register deprecated events. + * We do this so these events are added to the end of the event + * handler chain which gives the system a chance to process them + * before they are dispatched to extensions. + * + * Extensions that listen to the new event (paneViewXXX events) are + * always added to the end so this effectively puts the legacy events + * at the end of the event list. This prevents extensiosn from + * handling the event too soon. (e.g. paneViewListView needs to + * process these events before the Extension Highlighter extension) + */ + AppInit.extensionsReady(function () { + _deprecateEvent("workingSetAdd", "paneViewListAdd"); + _deprecateEvent("workingSetAddList", "paneViewListAddList"); + _deprecateEvent("workingSetRemove", "paneViewListRemove"); + _deprecateEvent("workingSetRemoveList", "paneViewListRemoveList"); + _deprecateEvent("workingSetSort", "paneViewListSort"); + }); PreferencesManager.convertPreferences(module, {"files_": "user"}, true, _checkPreferencePrefix); @@ -1024,45 +800,36 @@ define(function (require, exports, module) { PreferencesManager.fileChanged(doc.file.fullPath); }); - // For unit tests and internal use only - exports._clearCurrentDocument = _clearCurrentDocument; - - // Define public API - exports.Document = DocumentModule.Document; - exports.getCurrentDocument = getCurrentDocument; - exports._clearCurrentDocument = _clearCurrentDocument; - exports.getDocumentForPath = getDocumentForPath; - exports.getOpenDocumentForPath = getOpenDocumentForPath; - exports.getDocumentText = getDocumentText; - exports.createUntitledDocument = createUntitledDocument; - exports.getWorkingSet = getWorkingSet; - exports.findInWorkingSet = findInWorkingSet; - exports.findInWorkingSetAddedOrder = findInWorkingSetAddedOrder; - exports.getAllOpenDocuments = getAllOpenDocuments; - exports.setCurrentDocument = setCurrentDocument; - exports.addToWorkingSet = addToWorkingSet; - exports.addListToWorkingSet = addListToWorkingSet; - exports.removeFromWorkingSet = removeFromWorkingSet; - exports.removeListFromWorkingSet = removeListFromWorkingSet; - exports.getNextPrevFile = getNextPrevFile; - exports.swapWorkingSetIndexes = swapWorkingSetIndexes; - exports.sortWorkingSet = sortWorkingSet; - exports.beginDocumentNavigation = beginDocumentNavigation; - exports.finalizeDocumentNavigation = finalizeDocumentNavigation; - exports.closeFullEditor = closeFullEditor; - exports.closeAll = closeAll; - exports.notifyFileDeleted = notifyFileDeleted; - exports.notifyPathNameChanged = notifyPathNameChanged; - exports.notifyPathDeleted = notifyPathDeleted; + // Deprecated APIs + exports.getWorkingSet = getWorkingSet; + exports.findInWorkingSet = findInWorkingSet; + exports.addListToWorkingSet = addListToWorkingSet; + exports.removeFromWorkingSet = removeFromWorkingSet; + exports.removeListFromWorkingSet = removeListFromWorkingSet; + exports.getNextPrevFile = getNextPrevFile; + exports.getCurrentDocument = getCurrentDocument; + + + // Define public API + exports.Document = DocumentModule.Document; + exports.getDocumentForPath = getDocumentForPath; + exports.getOpenDocumentForPath = getOpenDocumentForPath; + exports.getDocumentText = getDocumentText; + exports.createUntitledDocument = createUntitledDocument; + exports.getAllOpenDocuments = getAllOpenDocuments; + exports.setCurrentDocument = setCurrentDocument; + exports.clearCurrentDocument = clearCurrentDocument; + exports.beginDocumentNavigation = beginDocumentNavigation; + exports.finalizeDocumentNavigation = finalizeDocumentNavigation; + exports.closeFullEditor = closeFullEditor; + exports.closeAll = closeAll; + exports.notifyFileDeleted = notifyFileDeleted; + exports.notifyPathNameChanged = notifyPathNameChanged; + exports.notifyPathDeleted = notifyPathDeleted; // Performance measurements PerfUtils.createPerfMeasurement("DOCUMENT_MANAGER_GET_DOCUMENT_FOR_PATH", "DocumentManager.getDocumentForPath()"); - // Handle project change events - var $ProjectManager = $(ProjectManager); - $ProjectManager.on("projectOpen", _projectOpen); - $ProjectManager.on("beforeProjectClose beforeAppClose", _savePreferences); - // Handle Language change events $(LanguageManager).on("languageAdded", _handleLanguageAdded); $(LanguageManager).on("languageModified", _handleLanguageModified); diff --git a/src/editor/Editor.js b/src/editor/Editor.js index fdb3ad6b209..c270916bdb4 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -880,6 +880,13 @@ define(function (require, exports, module) { PerfUtils.addMeasurement(perfTimerName); }; + + /** + * Gets the document associated with this editor + */ + Editor.prototype.getDocument = function () { + return this.document; + }; /** * Gets the current cursor position within the editor. diff --git a/src/editor/EditorManager.js b/src/editor/EditorManager.js index 4536e270e9c..949b013e114 100644 --- a/src/editor/EditorManager.js +++ b/src/editor/EditorManager.js @@ -52,10 +52,11 @@ define(function (require, exports, module) { // Load dependent modules var Commands = require("command/Commands"), - PanelManager = require("view/PanelManager"), + WorkspaceManager = require("view/WorkspaceManager"), PreferencesManager = require("preferences/PreferencesManager"), CommandManager = require("command/CommandManager"), DocumentManager = require("document/DocumentManager"), + MainViewManager = require("view/MainViewManager"), PerfUtils = require("utils/PerfUtils"), Editor = require("editor/Editor").Editor, InlineTextEditor = require("editor/InlineTextEditor").InlineTextEditor, @@ -113,7 +114,7 @@ define(function (require, exports, module) { /** * Maps full path to scroll pos & cursor/selection info. Not kept up to date while an editor is current. * Only updated when switching / closing editor, or when requested explicitly via _getViewState(). - * @type {Object} + * @type {Object.} */ var _viewStateCache = {}; @@ -443,7 +444,7 @@ define(function (require, exports, module) { // If outgoing editor is no longer needed, dispose it var isCurrentDocument = (DocumentManager.getCurrentDocument() === document); - var isInWorkingSet = (DocumentManager.findInWorkingSet(document.file.fullPath) !== -1); + var isInWorkingSet = (MainViewManager.findInPaneViewList(MainViewManager.ALL_PANES, document.file.fullPath) !== -1); if (!isCurrentDocument && !isInWorkingSet) { // Destroy the editor widget (which un-refs the Document and reverts it to read-only mode) editor.destroy(); @@ -484,20 +485,20 @@ define(function (require, exports, module) { /** * Must be called whenever the size/visibility of editor area siblings is changed without going through - * PanelManager or Resizer. Resizable panels created via PanelManager do not require this manual call. + * WorkspaceManager or Resizer. Resizable panels created via WorkspaceManager do not require this manual call. */ function resizeEditor() { if (!_editorHolder) { return; // still too early during init } - // PanelManager computes the correct editor-holder size & calls us back with it, via _onEditorAreaResize() - PanelManager._notifyLayoutChange(); + // WorkspaceManager computes the correct editor-holder size & calls us back with it, via _onEditorAreaResize() + WorkspaceManager._notifyLayoutChange(); } /** * Update the current CodeMirror editor's size. Must be called any time the contents of the editor area * are swapped or any time the editor-holder area has changed height. EditorManager calls us in the swap - * case. PanelManager calls us in the most common height-change cases (panel and/or window resize), but + * case. WorkspaceManager calls us in the most common height-change cases (panel and/or window resize), but * some other cases are handled by external code calling `resizeEditor()` (e.g. ModalBar hide/show). * * @param {number} editorAreaHt @@ -583,7 +584,7 @@ define(function (require, exports, module) { // Resize and refresh the editor, since it might have changed size or had other edits applied // since it was last visible. - PanelManager._notifyLayoutChange(REFRESH_FORCE); + WorkspaceManager._notifyLayoutChange(REFRESH_FORCE); } /** @@ -718,7 +719,7 @@ define(function (require, exports, module) { } // Clean up currently viewing document or custom viewer - DocumentManager._clearCurrentDocument(); + DocumentManager.clearCurrentDocument(); _removeCustomViewer(); // Hide the not-editor or reset current editor @@ -743,34 +744,30 @@ define(function (require, exports, module) { function showingCustomViewerForPath(fullPath) { return (_currentViewProvider && _currentlyViewedPath === fullPath); } + + /** * Registers a new custom viewer provider. To create an extension * that enables Brackets to view files that cannot be shown as * text such as binary files, use this method to register a CustomViewer. * - * A CustomViewer, such as ImageViewer in Brackets core needs to - * implement and export two methods: - * - render - * @param {!string} fullPath Path to the image file - * @param {!jQueryObject} $editorHolder The DOM element to append the view to. - * - onRemove - * signs off listeners and performs any required clean up when editor manager closes - * the custom viewer - * * By registering a CustomViewer with EditorManager Brackets is * enabled to view files for one or more given file extensions. * The first argument defines a so called languageId which bundles * file extensions to be handled by the custom viewer, see more * in LanguageManager JSDocs. - * The second argument is an instance of the custom viewer that is ready to display - * files. * * @param {!String} languageId, i.e. string such as image, audio, etc to * identify a language known to LanguageManager - * @param {!Object} provider custom view provider instance + * @param {!Object.} Provider the Custom View Provider */ function registerCustomViewer(langId, provider) { + // + // Custom View Providers must register an object which has the following method signatures: + // render(fullpath, $holder) is called to render the HTML Dom Node for the custom viewer at $holder for fullpath. + // onRemove() is called when it's time to remove the DOM node + // if (!_customViewerRegistry[langId]) { _customViewerRegistry[langId] = provider; } else { @@ -808,12 +805,16 @@ define(function (require, exports, module) { * If param fullpath is provided then only if fullpath matches * the currently viewed file an alternate file will be opened. * @param {?string} fullPath - file path of deleted file. + * @param {?*} alternateFile - file to open in its place */ - function notifyPathDeleted(fullPath) { + function notifyPathDeleted(fullPath, alternateFile) { function openAlternateFile() { - var fileToOpen = DocumentManager.getNextPrevFile(1); - if (fileToOpen) { - CommandManager.execute(Commands.FILE_OPEN, {fullPath: fileToOpen.fullPath}); + if (alternateFile) { + if (typeof alternateFile === "string") { + CommandManager.execute(Commands.FILE_OPEN, {fullPath: alternateFile}); + } else { + CommandManager.execute(Commands.FILE_OPEN, {fullPath: alternateFile.fullPath}); + } } else { _removeCustomViewer(); _showNoEditor(); @@ -826,9 +827,8 @@ define(function (require, exports, module) { } /** Handles changes to DocumentManager.getCurrentDocument() */ - function _onCurrentDocumentChange() { - var doc = DocumentManager.getCurrentDocument(), - container = _editorHolder.get(0); + function _onCurrentDocumentChange(event, doc, prev) { + var container = _editorHolder.get(0); var perfTimerName = PerfUtils.markStart("EditorManager._onCurrentDocumentChange():\t" + (!doc || doc.file.fullPath)); @@ -847,23 +847,36 @@ define(function (require, exports, module) { PerfUtils.addMeasurement(perfTimerName); } - /** Handles removals from DocumentManager's working set list */ - function _onWorkingSetRemove(event, removedFile) { + function _onFileRemoved(file) { // There's one case where an editor should be disposed even though the current document // didn't change: removing a document from the working set (via the "X" button). (This may // also cover the case where the document WAS current, if the editor-swap happens before the // removal from the working set. - var doc = DocumentManager.getOpenDocumentForPath(removedFile.fullPath); + var doc; + if (typeof file === "string") { + doc = DocumentManager.getOpenDocumentForPath(file); + } + + doc = DocumentManager.getOpenDocumentForPath(file.fullPath); if (doc) { _destroyEditorIfUnneeded(doc); } // else, file was listed in working set but never shown in the editor - ignore } - function _onWorkingSetRemoveList(event, removedFiles) { - removedFiles.forEach(function (removedFile) { - _onWorkingSetRemove(event, removedFile); - }); + /** + * notifies the editor that a reference from the pane list view was removed + * @param {!string} paneId of the pane containing the path being removed + * @param {?*} removedFiles. Can be, string, File, Array[string] or Array[File] + */ + function notifyPathRemovedFromPaneList(paneId, removedFiles) { + if ($.isArray(removedFiles)) { + removedFiles.forEach(function (removedFile) { + _onFileRemoved(removedFile); + }); + } else { + _onFileRemoved(removedFiles); + } } @@ -1071,10 +1084,8 @@ define(function (require, exports, module) { // Initialize: register listeners $(DocumentManager).on("currentDocumentChange", _onCurrentDocumentChange); - $(DocumentManager).on("workingSetRemove", _onWorkingSetRemove); - $(DocumentManager).on("workingSetRemoveList", _onWorkingSetRemoveList); $(DocumentManager).on("fileNameChange", _onFileNameChange); - $(PanelManager).on("editorAreaResize", _onEditorAreaResize); + $(WorkspaceManager).on("editorAreaResize", _onEditorAreaResize); // For unit tests and internal use only @@ -1111,5 +1122,6 @@ define(function (require, exports, module) { exports.registerCustomViewer = registerCustomViewer; exports.getCustomViewerForPath = getCustomViewerForPath; exports.notifyPathDeleted = notifyPathDeleted; + exports.notifyPathRemovedFromPaneList = notifyPathRemovedFromPaneList; exports.showingCustomViewerForPath = showingCustomViewerForPath; }); diff --git a/src/editor/ImageViewer.js b/src/editor/ImageViewer.js index 1d914b0d6fd..131b07b450c 100644 --- a/src/editor/ImageViewer.js +++ b/src/editor/ImageViewer.js @@ -30,7 +30,7 @@ define(function (require, exports, module) { var DocumentManager = require("document/DocumentManager"), EditorManager = require("editor/EditorManager"), ImageHolderTemplate = require("text!htmlContent/image-holder.html"), - PanelManager = require("view/PanelManager"), + WorkspaceManager = require("view/WorkspaceManager"), ProjectManager = require("project/ProjectManager"), Strings = require("strings"), StringUtils = require("utils/StringUtils"), @@ -247,7 +247,7 @@ define(function (require, exports, module) { * the image viewer */ function onRemove() { - $(PanelManager).off("editorAreaResize", _onEditorAreaResize); + $(WorkspaceManager).off("editorAreaResize", _onEditorAreaResize); $(DocumentManager).off("fileNameChange", _onFileNameChange); $("#img").off("mousemove", "#img-preview", _showImageTip) .off("mouseleave", "#img-preview", _hideImageTip); @@ -300,7 +300,7 @@ define(function (require, exports, module) { $("#image-holder").show(); // listen to resize to update the scale sticker - $(PanelManager).on("editorAreaResize", _onEditorAreaResize); + $(WorkspaceManager).on("editorAreaResize", _onEditorAreaResize); // make sure we always show the right file name $(DocumentManager).on("fileNameChange", _onFileNameChange); diff --git a/src/extensions/default/CloseOthers/main.js b/src/extensions/default/CloseOthers/main.js index e7e5a0711cd..38840356811 100644 --- a/src/extensions/default/CloseOthers/main.js +++ b/src/extensions/default/CloseOthers/main.js @@ -31,8 +31,9 @@ define(function (require, exports, module) { CommandManager = brackets.getModule("command/CommandManager"), Commands = brackets.getModule("command/Commands"), DocumentManager = brackets.getModule("document/DocumentManager"), + MainViewManager = brackets.getModule("view/MainViewManager"), Strings = brackets.getModule("strings"), - workingSetCmenu = Menus.getContextMenu(Menus.ContextMenuIds.WORKING_SET_MENU), + workingSetCmenu = Menus.getContextMenu(Menus.ContextMenuIds.PANE_VIEW_LIST_CONTEXT_MENU), PreferencesManager = brackets.getModule("preferences/PreferencesManager"); // Constants @@ -54,8 +55,8 @@ define(function (require, exports, module) { * @param {string} mode */ function handleClose(mode) { - var targetIndex = DocumentManager.findInWorkingSet(DocumentManager.getCurrentDocument().file.fullPath), - workingSet = DocumentManager.getWorkingSet().slice(0), + var targetIndex = MainViewManager.findInPaneViewList(MainViewManager.ALL_PANES, DocumentManager.getCurrentDocument().file.fullPath), + workingSet = MainViewManager.getPaneViewList(MainViewManager.FOCUSED_PANE).slice(0), start = (mode === closeBelow) ? (targetIndex + 1) : 0, end = (mode === closeAbove) ? (targetIndex) : (workingSet.length), files = [], @@ -80,8 +81,8 @@ define(function (require, exports, module) { var doc = DocumentManager.getCurrentDocument(); if (doc) { - var docIndex = DocumentManager.findInWorkingSet(doc.file.fullPath), - workingSet = DocumentManager.getWorkingSet().slice(0); + var docIndex = MainViewManager.findInPaneViewList(MainViewManager.ALL_PANES, doc.file.fullPath), + workingSet = MainViewManager.getPaneViewList(MainViewManager.FOCUSED_PANE).slice(0); if (docIndex === workingSet.length - 1) { // hide "Close Others Below" if the last file in Working Files is selected CommandManager.get(closeBelow).setEnabled(false); diff --git a/src/extensions/default/CloseOthers/unittests.js b/src/extensions/default/CloseOthers/unittests.js index 99754ba2c19..6d4202046f0 100644 --- a/src/extensions/default/CloseOthers/unittests.js +++ b/src/extensions/default/CloseOthers/unittests.js @@ -34,6 +34,7 @@ define(function (require, exports, module) { Dialogs, EditorManager, DocumentManager, + MainViewManager, FileSystem; describe("CloseOthers", function () { @@ -86,6 +87,7 @@ define(function (require, exports, module) { $ = testWindow.$; brackets = testWindow.brackets; DocumentManager = testWindow.brackets.test.DocumentManager; + MainViewManager = testWindow.brackets.test.MainViewManager; CommandManager = testWindow.brackets.test.CommandManager; EditorManager = testWindow.brackets.test.EditorManager; Dialogs = testWindow.brackets.test.Dialogs; @@ -127,7 +129,7 @@ define(function (require, exports, module) { function runCloseOthers() { - var ws = DocumentManager.getWorkingSet(), + var ws = MainViewManager.getPaneViewList(MainViewManager.FOCUSED_PANE), promise; if (ws.length > docSelectIndex) { @@ -137,6 +139,7 @@ define(function (require, exports, module) { promise = CommandManager.execute(cmdToRun); waitsForDone(promise, cmdToRun); + expect(EditorManager.getCurrentlyViewedPath()).toEqual(ws[docSelectIndex].fullPath, "Path of document in editor after close others command should be the document that was selected"); } } @@ -147,7 +150,7 @@ define(function (require, exports, module) { runs(runCloseOthers); runs(function () { - expect(DocumentManager.getWorkingSet().length).toEqual(1); + expect(MainViewManager.getPaneViewList(MainViewManager.FOCUSED_PANE).length).toEqual(1); }); }); @@ -158,7 +161,7 @@ define(function (require, exports, module) { runs(runCloseOthers); runs(function () { - expect(DocumentManager.getWorkingSet().length).toEqual(3); + expect(MainViewManager.getPaneViewList(MainViewManager.FOCUSED_PANE).length).toEqual(3); }); }); @@ -169,7 +172,7 @@ define(function (require, exports, module) { runs(runCloseOthers); runs(function () { - expect(DocumentManager.getWorkingSet().length).toEqual(2); + expect(MainViewManager.getPaneViewList(MainViewManager.FOCUSED_PANE).length).toEqual(2); }); }); }); diff --git a/src/htmlContent/main-view.html b/src/htmlContent/main-view.html index 6211d33481c..9096ed920d9 100644 --- a/src/htmlContent/main-view.html +++ b/src/htmlContent/main-view.html @@ -41,7 +41,7 @@