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

Add "Show in OS" context menu item to open a folder in Finder/Explorer. #2128

Merged
merged 5 commits into from
May 17, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/command/Commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 2 additions & 0 deletions src/command/Menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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();
Expand Down
21 changes: 18 additions & 3 deletions src/document/DocumentCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I considered being clever and using different strings per OS ("Show in Finder" / "Show in Explorer") but thought I'd try the simplest thing possible first :-)


// Debug menu commands
"DEBUG_MENU" : "Debug",
Expand Down
26 changes: 21 additions & 5 deletions src/project/ProjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 1 addition & 7 deletions src/search/FindInFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down