From c2cd07946f92804c2a1161634fbe4c316890952f Mon Sep 17 00:00:00 2001 From: Peter Flynn Date: Thu, 15 Nov 2012 11:23:07 -0800 Subject: [PATCH 1/4] Add "Show in OS" context menu item to open a folder in Finder/Explorer. Create new ProjectManager.getSidebarSelectedItem() API, and rename getSelectedItem() -> getTreeSelectedItem() for clarity. --- src/command/Commands.js | 1 + src/command/Menus.js | 2 ++ src/document/DocumentCommandHandlers.js | 21 +++++++++++++++++--- src/nls/root/strings.js | 1 + src/project/ProjectManager.js | 26 ++++++++++++++++++++----- src/search/FindInFiles.js | 8 +------- 6 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/command/Commands.js b/src/command/Commands.js index e0dc137d55a..74b06301c47 100644 --- a/src/command/Commands.js +++ b/src/command/Commands.js @@ -86,6 +86,7 @@ define(function (require, exports, module) { exports.NAVIGATE_NEXT_DOC = "navigate.nextDoc"; exports.NAVIGATE_PREV_DOC = "navigate.prevDoc"; exports.NAVIGATE_SHOW_IN_FILE_TREE = "navigate.showInFileTree"; + exports.NAVIGATE_SHOW_IN_OS = "navigate.showInOS"; exports.NAVIGATE_QUICK_OPEN = "navigate.quickOpen"; exports.NAVIGATE_GOTO_DEFINITION = "navigate.gotoDefinition"; exports.NAVIGATE_GOTO_LINE = "navigate.gotoLine"; diff --git a/src/command/Menus.js b/src/command/Menus.js index 167bd0d6d50..faf8354e272 100644 --- a/src/command/Menus.js +++ b/src/command/Menus.js @@ -994,6 +994,7 @@ define(function (require, exports, module) { project_cmenu.addMenuItem(Commands.FILE_NEW); project_cmenu.addMenuItem(Commands.FILE_NEW_FOLDER); project_cmenu.addMenuItem(Commands.FILE_RENAME, "F2"); + project_cmenu.addMenuItem(Commands.NAVIGATE_SHOW_IN_OS); project_cmenu.addMenuDivider(); project_cmenu.addMenuItem(Commands.EDIT_FIND_IN_SUBTREE); @@ -1002,6 +1003,7 @@ define(function (require, exports, module) { working_set_cmenu.addMenuItem(Commands.FILE_SAVE); 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.EDIT_FIND_IN_SUBTREE); working_set_cmenu.addMenuDivider(); diff --git a/src/document/DocumentCommandHandlers.js b/src/document/DocumentCommandHandlers.js index 2bc6c283c38..0ff41ff69a8 100644 --- a/src/document/DocumentCommandHandlers.js +++ b/src/document/DocumentCommandHandlers.js @@ -330,7 +330,7 @@ define(function (require, exports, module) { // If a directory is currently selected, put it in it. // If nothing is selected, put it at the root of the project var baseDir, - selected = ProjectManager.getSelectedItem() || ProjectManager.getProjectRoot(); + selected = ProjectManager.getTreeSelectedItem() || ProjectManager.getProjectRoot(); baseDir = selected.fullPath; if (selected.isFile) { @@ -745,7 +745,7 @@ define(function (require, exports, module) { /** Show a textfield to rename whatever is currently selected in the sidebar (working set OR tree) */ function handleFileRename() { // Prefer selected tree item (which could be a folder); else use current file - var entry = ProjectManager.getSelectedItem(); + var entry = ProjectManager.getTreeSelectedItem(); if (!entry) { var doc = DocumentManager.getCurrentDocument(); entry = doc && doc.file; @@ -823,7 +823,21 @@ define(function (require, exports, module) { ProjectManager.showInTree(DocumentManager.getCurrentDocument().file); } - + function handleShowInOS() { + var entry = ProjectManager.getSidebarSelectedItem(); + if (entry) { + var path = entry.fullPath; + if (entry.isFile) { // if file, we want its containing folder + var lastSlash = entry.fullPath.lastIndexOf("/"); + path = path.substring(0, lastSlash + 1); + } + brackets.app.showOSFolder(path, function errback(err) { + console.error(err); + }); + } + } + + function init($titleContainerToolbar) { _$titleContainerToolbar = $titleContainerToolbar; _$titleWrapper = $(".title-wrapper", _$titleContainerToolbar); @@ -852,6 +866,7 @@ define(function (require, exports, module) { 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(Strings.CMD_SHOW_IN_OS, Commands.NAVIGATE_SHOW_IN_OS, handleShowInOS); // Listen for changes that require updating the editor titlebar $(DocumentManager).on("dirtyFlagChange", handleDirtyChange); diff --git a/src/nls/root/strings.js b/src/nls/root/strings.js index a240fed5eed..d331ce9a1ee 100644 --- a/src/nls/root/strings.js +++ b/src/nls/root/strings.js @@ -216,6 +216,7 @@ define({ "CMD_NEXT_DOC" : "Next Document", "CMD_PREV_DOC" : "Previous Document", "CMD_SHOW_IN_TREE" : "Show in File Tree", + "CMD_SHOW_IN_OS" : "Show in OS", // Debug menu commands "DEBUG_MENU" : "Debug", diff --git a/src/project/ProjectManager.js b/src/project/ProjectManager.js index 075b67b338e..d128477f78b 100644 --- a/src/project/ProjectManager.js +++ b/src/project/ProjectManager.js @@ -178,18 +178,33 @@ define(function (require, exports, module) { } /** - * Returns the FileEntry or DirectoryEntry corresponding to the selected item, or null - * if no item is selected. - * + * Returns the FileEntry or DirectoryEntry corresponding to the item selected in the file tree, or null + * if no item is selected in the tree (though the working set may still have a selection; use + * getSidebarSelectedItem() to get the selection regardless of whether it's in the tree or working set). * @return {?Entry} */ - function getSelectedItem() { + function getTreeSelectedItem() { var selected = _projectTree.jstree("get_selected"); if (selected) { return selected.data("entry"); } return null; } + + /** + * Returns the FileEntry or DirectoryEntry corresponding to the item selected in the sidebar panel, whether in + * the file tree OR in the working set; or null if no item is selected anywhere in the sidebar. + * @return {?Entry} + */ + function getSidebarSelectedItem() { + // Prefer file tree selection, else use working set selection + var selectedEntry = getTreeSelectedItem(); + if (!selectedEntry) { + var doc = DocumentManager.getCurrentDocument(); + selectedEntry = (doc && doc.file); + } + return selectedEntry; + } function _fileViewFocusChange() { _redraw(true); @@ -1321,7 +1336,8 @@ define(function (require, exports, module) { exports.makeProjectRelativeIfPossible = makeProjectRelativeIfPossible; exports.shouldShow = shouldShow; exports.openProject = openProject; - exports.getSelectedItem = getSelectedItem; + exports.getTreeSelectedItem = getTreeSelectedItem; + exports.getSidebarSelectedItem = getSidebarSelectedItem; exports.getInitialProjectPath = getInitialProjectPath; exports.isWelcomeProjectPath = isWelcomeProjectPath; exports.updateWelcomeProjectPath = updateWelcomeProjectPath; diff --git a/src/search/FindInFiles.js b/src/search/FindInFiles.js index 64edeff1f86..61ff21aa9f4 100644 --- a/src/search/FindInFiles.js +++ b/src/search/FindInFiles.js @@ -419,13 +419,7 @@ define(function (require, exports, module) { /** Search within the file/subtree defined by the sidebar selection */ function doFindInSubtree() { - // Prefer project tree selection, else use working set selection - var selectedEntry = ProjectManager.getSelectedItem(); - if (!selectedEntry) { - var doc = DocumentManager.getCurrentDocument(); - selectedEntry = (doc && doc.file); - } - + var selectedEntry = ProjectManager.getSidebarSelectedItem(); doFindInFiles(selectedEntry); } From d3dc96a64e84a0c4562b12754101951ab0ef500c Mon Sep 17 00:00:00 2001 From: Peter Flynn Date: Tue, 30 Apr 2013 00:12:15 -0700 Subject: [PATCH 2/4] Pass full path of files to showOSFolder() - not just parent folder's path - so file can be shown selected --- src/document/DocumentCommandHandlers.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/document/DocumentCommandHandlers.js b/src/document/DocumentCommandHandlers.js index 2a17b7e39b0..7a0fa12c07d 100644 --- a/src/document/DocumentCommandHandlers.js +++ b/src/document/DocumentCommandHandlers.js @@ -843,13 +843,8 @@ define(function (require, exports, module) { function handleShowInOS() { var entry = ProjectManager.getSidebarSelectedItem(); if (entry) { - var path = entry.fullPath; - if (entry.isFile) { // if file, we want its containing folder - var lastSlash = entry.fullPath.lastIndexOf("/"); - path = path.substring(0, lastSlash + 1); - } - brackets.app.showOSFolder(path, function errback(err) { - console.error(err); + brackets.app.showOSFolder(entry.fullPath, function (err) { + console.error("Error showing '" + entry.fullPath + "' in OS folder:", err); }); } } From 45e16077f6c8a0c28fe4b44e7284b623212c8a36 Mon Sep 17 00:00:00 2001 From: Peter Flynn Date: Thu, 16 May 2013 11:50:23 -0700 Subject: [PATCH 3/4] Code review comments: fix bad merge, only log warning for actual errors --- src/command/Menus.js | 234 ------------------------ src/document/DocumentCommandHandlers.js | 4 +- 2 files changed, 3 insertions(+), 235 deletions(-) diff --git a/src/command/Menus.js b/src/command/Menus.js index 5dbafc10bc3..0c07c6bbaac 100644 --- a/src/command/Menus.js +++ b/src/command/Menus.js @@ -981,240 +981,6 @@ define(function (require, exports, module) { // } - function init() { - - /* - * File menu - */ - var menu; - menu = addMenu(Strings.FILE_MENU, AppMenuBar.FILE_MENU); - menu.addMenuItem(Commands.FILE_NEW, "Ctrl-N"); - menu.addMenuItem(Commands.FILE_NEW_FOLDER); - menu.addMenuItem(Commands.FILE_OPEN, "Ctrl-O"); - menu.addMenuItem(Commands.FILE_OPEN_FOLDER); - menu.addMenuItem(Commands.FILE_CLOSE, "Ctrl-W"); - menu.addMenuItem(Commands.FILE_CLOSE_ALL, "Ctrl-Shift-W"); - menu.addMenuDivider(); - menu.addMenuItem(Commands.FILE_SAVE, "Ctrl-S"); - menu.addMenuItem(Commands.FILE_SAVE_ALL, "Ctrl-Alt-S"); - menu.addMenuDivider(); - menu.addMenuItem(Commands.FILE_LIVE_FILE_PREVIEW, "Ctrl-Alt-P"); - menu.addMenuItem(Commands.FILE_PROJECT_SETTINGS); - menu.addMenuDivider(); - menu.addMenuItem(Commands.FILE_QUIT, "Ctrl-Q"); - - /* - * Edit menu - */ - menu = addMenu(Strings.EDIT_MENU, AppMenuBar.EDIT_MENU); - menu.addMenuItem(Commands.EDIT_SELECT_ALL, "Ctrl-A"); - menu.addMenuItem(Commands.EDIT_SELECT_LINE, [{key: "Ctrl-L", platform: "win"}, - {key: "Ctrl-L", platform: "mac"}]); - menu.addMenuDivider(); - menu.addMenuItem(Commands.EDIT_FIND, "Ctrl-F"); - menu.addMenuItem(Commands.EDIT_FIND_IN_FILES, "Ctrl-Shift-F"); - menu.addMenuItem(Commands.EDIT_FIND_NEXT, [{key: "F3", platform: "win"}, - {key: "Cmd-G", platform: "mac"}]); - - menu.addMenuItem(Commands.EDIT_FIND_PREVIOUS, [{key: "Shift-F3", platform: "win"}, - {key: "Cmd-Shift-G", platform: "mac"}]); - - menu.addMenuDivider(); - menu.addMenuItem(Commands.EDIT_REPLACE, [{key: "Ctrl-H", platform: "win"}, - {key: "Cmd-Alt-F", platform: "mac"}]); - menu.addMenuDivider(); - menu.addMenuItem(Commands.EDIT_INDENT, [{key: "Indent", displayKey: "Tab"}]); - menu.addMenuItem(Commands.EDIT_UNINDENT, [{key: "Unindent", displayKey: "Shift-Tab"}]); - menu.addMenuItem(Commands.EDIT_DUPLICATE, "Ctrl-D"); - menu.addMenuItem(Commands.EDIT_DELETE_LINES, "Ctrl-Shift-D"); - menu.addMenuItem(Commands.EDIT_LINE_UP, [{key: "Ctrl-Shift-Up", displayKey: "Ctrl-Shift-\u2191", - platform: "win"}, - {key: "Cmd-Ctrl-Up", displayKey: "Cmd-Ctrl-\u2191", - platform: "mac"}]); - menu.addMenuItem(Commands.EDIT_LINE_DOWN, [{key: "Ctrl-Shift-Down", displayKey: "Ctrl-Shift-\u2193", - platform: "win"}, - {key: "Cmd-Ctrl-Down", displayKey: "Cmd-Ctrl-\u2193", - platform: "mac"}]); - menu.addMenuDivider(); - menu.addMenuItem(Commands.EDIT_LINE_COMMENT, "Ctrl-/"); - menu.addMenuItem(Commands.EDIT_BLOCK_COMMENT, "Ctrl-Shift-/"); - - /* - * View menu - */ - menu = addMenu(Strings.VIEW_MENU, AppMenuBar.VIEW_MENU); - menu.addMenuItem(Commands.VIEW_HIDE_SIDEBAR, "Ctrl-Shift-H"); - menu.addMenuDivider(); - menu.addMenuItem(Commands.VIEW_INCREASE_FONT_SIZE, [{key: "Ctrl-=", displayKey: "Ctrl-+"}, - {key: "Ctrl-+", displayKey: "Ctrl-+"}]); - menu.addMenuItem(Commands.VIEW_DECREASE_FONT_SIZE, [{key: "Ctrl--", displayKey: "Ctrl-\u2212"}]); - menu.addMenuItem(Commands.VIEW_RESTORE_FONT_SIZE, "Ctrl-0"); - menu.addMenuDivider(); - menu.addMenuItem(Commands.TOGGLE_JSLINT); - - /* - * Navigate menu - */ - menu = addMenu(Strings.NAVIGATE_MENU, AppMenuBar.NAVIGATE_MENU); - menu.addMenuItem(Commands.NAVIGATE_QUICK_OPEN, "Ctrl-Shift-O"); - menu.addMenuItem(Commands.NAVIGATE_GOTO_LINE, [{key: "Ctrl-G", platform: "win"}, - {key: "Cmd-L", platform: "mac"}]); - - menu.addMenuItem(Commands.NAVIGATE_GOTO_DEFINITION, "Ctrl-T"); - menu.addMenuDivider(); - menu.addMenuItem(Commands.NAVIGATE_NEXT_DOC, [{key: "Ctrl-Tab", platform: "win"}, - {key: "Ctrl-Tab", platform: "mac"}]); - menu.addMenuItem(Commands.NAVIGATE_PREV_DOC, [{key: "Ctrl-Shift-Tab", platform: "win"}, - {key: "Ctrl-Shift-Tab", platform: "mac"}]); - menu.addMenuDivider(); - menu.addMenuItem(Commands.NAVIGATE_SHOW_IN_FILE_TREE); - menu.addMenuDivider(); - menu.addMenuItem(Commands.TOGGLE_QUICK_EDIT, "Ctrl-E"); - menu.addMenuItem(Commands.QUICK_EDIT_PREV_MATCH, {key: "Alt-Up", displayKey: "Alt-\u2191"}); - menu.addMenuItem(Commands.QUICK_EDIT_NEXT_MATCH, {key: "Alt-Down", displayKey: "Alt-\u2193"}); - - /* - * Debug menu - */ - if (brackets.config.show_debug_menu) { - menu = addMenu(Strings.DEBUG_MENU, AppMenuBar.DEBUG_MENU); - menu.addMenuItem(Commands.DEBUG_SHOW_DEVELOPER_TOOLS, [{key: "F12", platform: "win"}, - {key: "Cmd-Opt-I", platform: "mac"}]); - menu.addMenuItem(Commands.DEBUG_REFRESH_WINDOW, [{key: "F5", platform: "win"}, - {key: "Cmd-R", platform: "mac"}]); - menu.addMenuItem(Commands.DEBUG_NEW_BRACKETS_WINDOW); - menu.addMenuDivider(); - menu.addMenuItem(Commands.DEBUG_SWITCH_LANGUAGE); - menu.addMenuDivider(); - menu.addMenuItem(Commands.DEBUG_RUN_UNIT_TESTS); - menu.addMenuItem(Commands.DEBUG_SHOW_PERF_DATA); - } - - /* - * Help menu - */ - menu = addMenu(Strings.HELP_MENU, AppMenuBar.HELP_MENU); - menu.addMenuItem(Commands.HELP_SHOW_EXT_FOLDER); - menu.addMenuItem(Commands.HELP_CHECK_FOR_UPDATE); - - if (brackets.config.forum_url) { - menu.addMenuDivider(); - menu.addMenuItem(Commands.HELP_FORUM); - } - - menu.addMenuDivider(); - menu.addMenuItem(Commands.HELP_ABOUT); - - - /* - * Context Menus - */ - var project_cmenu = registerContextMenu(ContextMenuIds.PROJECT_MENU); - project_cmenu.addMenuItem(Commands.FILE_NEW); - project_cmenu.addMenuItem(Commands.FILE_NEW_FOLDER); - project_cmenu.addMenuItem(Commands.FILE_RENAME, "F2"); - project_cmenu.addMenuDivider(); - project_cmenu.addMenuItem(Commands.EDIT_FIND_IN_SUBTREE); - - var working_set_cmenu = registerContextMenu(ContextMenuIds.WORKING_SET_MENU); - working_set_cmenu.addMenuItem(Commands.FILE_CLOSE); - working_set_cmenu.addMenuItem(Commands.FILE_SAVE); - working_set_cmenu.addMenuItem(Commands.FILE_RENAME); - working_set_cmenu.addMenuItem(Commands.NAVIGATE_SHOW_IN_FILE_TREE); - working_set_cmenu.addMenuDivider(); - working_set_cmenu.addMenuItem(Commands.EDIT_FIND_IN_SUBTREE); - working_set_cmenu.addMenuDivider(); - working_set_cmenu.addMenuItem(Commands.SORT_WORKINGSET_BY_ADDED); - working_set_cmenu.addMenuItem(Commands.SORT_WORKINGSET_BY_NAME); - working_set_cmenu.addMenuItem(Commands.SORT_WORKINGSET_BY_TYPE); - working_set_cmenu.addMenuDivider(); - working_set_cmenu.addMenuItem(Commands.SORT_WORKINGSET_AUTO); - - var editor_cmenu = registerContextMenu(ContextMenuIds.EDITOR_MENU); - editor_cmenu.addMenuItem(Commands.TOGGLE_QUICK_EDIT); - editor_cmenu.addMenuItem(Commands.EDIT_SELECT_ALL); - - var inline_editor_cmenu = registerContextMenu(ContextMenuIds.INLINE_EDITOR_MENU); - inline_editor_cmenu.addMenuItem(Commands.TOGGLE_QUICK_EDIT); - inline_editor_cmenu.addMenuItem(Commands.EDIT_SELECT_ALL); - inline_editor_cmenu.addMenuDivider(); - inline_editor_cmenu.addMenuItem(Commands.QUICK_EDIT_PREV_MATCH); - inline_editor_cmenu.addMenuItem(Commands.QUICK_EDIT_NEXT_MATCH); - - /** - * Context menu for code editors (both full-size and inline) - * Auto selects the word the user clicks if the click does not occur over - * an existing selection - */ - $("#editor-holder").on("contextmenu", function (e) { - if ($(e.target).parents(".CodeMirror-gutter").length !== 0) { - return; - } - - // Note: on mousedown before this event, CodeMirror automatically checks mouse pos, and - // if not clicking on a selection moves the cursor to click location. When triggered - // from keyboard, no pre-processing occurs and the cursor/selection is left as is. - - var editor = EditorManager.getFocusedEditor(), - inlineWidget = EditorManager.getFocusedInlineWidget(); - - if (editor) { - // If there's just an insertion point select the word token at the cursor pos so - // it's more clear what the context menu applies to. - if (!editor.hasSelection()) { - editor.selectWordAt(editor.getCursorPos()); - - // Prevent menu from overlapping text by moving it down a little - // Temporarily backout this change for now to help mitigate issue #1111, - // which only happens if mouse is not over context menu. Better fix - // requires change to bootstrap, which is too risky for now. - //e.pageY += 6; - } - - if (inlineWidget) { - inline_editor_cmenu.open(e); - } else { - editor_cmenu.open(e); - } - } - }); - - /** - * Context menus for folder tree & working set list - */ - $("#project-files-container").on("contextmenu", function (e) { - project_cmenu.open(e); - }); - - $("#open-files-container").on("contextmenu", function (e) { - working_set_cmenu.open(e); - }); - - // Prevent the browser context menu since Brackets creates a custom context menu - $(window).contextmenu(function (e) { - e.preventDefault(); - }); - - /* - * General menu event processing - */ - // Prevent clicks on top level menus and menu items from taking focus - $(window.document).on("mousedown", ".dropdown", function (e) { - e.preventDefault(); - }); - - // Switch menus when the mouse enters an adjacent menu - // Only open the menu if another one has already been opened - // by clicking - $(window.document).on("mouseenter", "#main-toolbar .dropdown", function (e) { - var open = $(this).siblings(".open"); - if (open.length > 0) { - open.removeClass("open"); - $(this).addClass("open"); - } - }); - } - // Define public API exports.AppMenuBar = AppMenuBar; exports.ContextMenuIds = ContextMenuIds; diff --git a/src/document/DocumentCommandHandlers.js b/src/document/DocumentCommandHandlers.js index 7a0fa12c07d..5dfbca649c6 100644 --- a/src/document/DocumentCommandHandlers.js +++ b/src/document/DocumentCommandHandlers.js @@ -844,7 +844,9 @@ define(function (require, exports, module) { var entry = ProjectManager.getSidebarSelectedItem(); if (entry) { brackets.app.showOSFolder(entry.fullPath, function (err) { - console.error("Error showing '" + entry.fullPath + "' in OS folder:", err); + if (err) { + console.error("Error showing '" + entry.fullPath + "' in OS folder:", err); + } }); } } From 7fff5a107a988fd9eda76ecb9f9a95a11bc28f43 Mon Sep 17 00:00:00 2001 From: Peter Flynn Date: Thu, 16 May 2013 14:51:19 -0700 Subject: [PATCH 4/4] Code review: switch back to a single public ProjectManager.getSelectedItem() API, which now covers the working set selection too. Seems like a fairly safe API change - this may even be how people assumed it worked before. Also: add logging for a ProjectManager error case that was silently ignored before. --- src/command/Menus.js | 1 - src/document/DocumentCommandHandlers.js | 24 +++++++++++++++--------- src/project/ProjectManager.js | 14 ++++++++------ src/search/FindInFiles.js | 2 +- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/command/Menus.js b/src/command/Menus.js index 0c07c6bbaac..455aecb6151 100644 --- a/src/command/Menus.js +++ b/src/command/Menus.js @@ -980,7 +980,6 @@ define(function (require, exports, module) { // NOT IMPLEMENTED // } - // Define public API exports.AppMenuBar = AppMenuBar; exports.ContextMenuIds = ContextMenuIds; diff --git a/src/document/DocumentCommandHandlers.js b/src/document/DocumentCommandHandlers.js index 5dfbca649c6..3d490f57f7c 100644 --- a/src/document/DocumentCommandHandlers.js +++ b/src/document/DocumentCommandHandlers.js @@ -342,11 +342,13 @@ define(function (require, exports, module) { fileNewInProgress = true; // Determine the directory to put the new file - // If a file is currently selected, put it next to it. - // If a directory is currently selected, put it in it. - // If nothing is selected, put it at the root of the project + // 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 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 + // ProjectManager.createNewItem() ignores the baseDir we give it and falls back to the project root on its own) var baseDir, - selected = ProjectManager.getTreeSelectedItem() || ProjectManager.getProjectRoot(); + selected = ProjectManager.getSelectedItem() || ProjectManager.getProjectRoot(); baseDir = selected.fullPath; if (selected.isFile) { @@ -766,15 +768,18 @@ define(function (require, exports, module) { ); } - /** Show a textfield to rename whatever is currently selected in the sidebar (working set OR tree) */ + /** Show a textfield to rename whatever is currently selected in the sidebar (or current doc if nothing else selected) */ function handleFileRename() { - // Prefer selected tree item (which could be a folder); else use current file - var entry = ProjectManager.getTreeSelectedItem(); + // 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) var doc = DocumentManager.getCurrentDocument(); entry = doc && doc.file; } - ProjectManager.renameItemInline(entry); + if (entry) { + ProjectManager.renameItemInline(entry); + } } /** Closes the window, then quits the app */ @@ -840,8 +845,9 @@ define(function (require, exports, module) { ProjectManager.showInTree(DocumentManager.getCurrentDocument().file); } + /** Show the selected sidebar (tree or working set) item in Finder/Explorer */ function handleShowInOS() { - var entry = ProjectManager.getSidebarSelectedItem(); + var entry = ProjectManager.getSelectedItem(); if (entry) { brackets.app.showOSFolder(entry.fullPath, function (err) { if (err) { diff --git a/src/project/ProjectManager.js b/src/project/ProjectManager.js index b12d1fef17a..bb268432da4 100644 --- a/src/project/ProjectManager.js +++ b/src/project/ProjectManager.js @@ -177,10 +177,10 @@ define(function (require, exports, module) { /** * Returns the FileEntry or DirectoryEntry corresponding to the item selected in the file tree, or null * if no item is selected in the tree (though the working set may still have a selection; use - * getSidebarSelectedItem() to get the selection regardless of whether it's in the tree or working set). + * getSelectedItem() to get the selection regardless of whether it's in the tree or working set). * @return {?Entry} */ - function getTreeSelectedItem() { + function _getTreeSelectedItem() { var selected = _projectTree.jstree("get_selected"); if (selected) { return selected.data("entry"); @@ -191,11 +191,13 @@ define(function (require, exports, module) { /** * Returns the FileEntry or DirectoryEntry corresponding to the item selected in the sidebar panel, whether in * the file tree OR in the working set; or null if no item is selected anywhere in the sidebar. + * May NOT be identical to the current Document - a folder may be selected in the sidebar, or the sidebar may not + * have the current document visible in the tree & working set. * @return {?Entry} */ - function getSidebarSelectedItem() { + function getSelectedItem() { // Prefer file tree selection, else use working set selection - var selectedEntry = getTreeSelectedItem(); + var selectedEntry = _getTreeSelectedItem(); if (!selectedEntry) { var doc = DocumentManager.getCurrentDocument(); selectedEntry = (doc && doc.file); @@ -706,6 +708,7 @@ define(function (require, exports, module) { function (error, entries) { if (entries) { // some but not all entries failed to load, so render what we can + console.warn("Error reading a subset of folder " + dirEntry); processEntries(entries); } else { Dialogs.showModalDialog( @@ -1434,8 +1437,7 @@ define(function (require, exports, module) { exports.makeProjectRelativeIfPossible = makeProjectRelativeIfPossible; exports.shouldShow = shouldShow; exports.openProject = openProject; - exports.getTreeSelectedItem = getTreeSelectedItem; - exports.getSidebarSelectedItem = getSidebarSelectedItem; + exports.getSelectedItem = getSelectedItem; exports.getInitialProjectPath = getInitialProjectPath; exports.isWelcomeProjectPath = isWelcomeProjectPath; exports.updateWelcomeProjectPath = updateWelcomeProjectPath; diff --git a/src/search/FindInFiles.js b/src/search/FindInFiles.js index b3383f212f3..db101b7e6a7 100644 --- a/src/search/FindInFiles.js +++ b/src/search/FindInFiles.js @@ -431,7 +431,7 @@ define(function (require, exports, module) { /** Search within the file/subtree defined by the sidebar selection */ function doFindInSubtree() { - var selectedEntry = ProjectManager.getSidebarSelectedItem(); + var selectedEntry = ProjectManager.getSelectedItem(); doFindInFiles(selectedEntry); }