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 3 commits
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 @@ -96,6 +96,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/DefaultMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,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);
project_cmenu.addMenuItem(Commands.NAVIGATE_SHOW_IN_OS);
project_cmenu.addMenuDivider();
project_cmenu.addMenuItem(Commands.EDIT_FIND_IN_SUBTREE);

Expand All @@ -187,6 +188,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
235 changes: 235 additions & 0 deletions src/command/Menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,241 @@ define(function (require, exports, module) {
// NOT IMPLEMENTED
// }


function init() {
Copy link
Member

Choose a reason for hiding this comment

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

This function shouldn't be in here. All of the menu initialization has been moved to DefaultMenus.js.


/*
* 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;
Expand Down
15 changes: 13 additions & 2 deletions src/document/DocumentCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,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 @@ -769,7 +769,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 @@ -840,6 +840,16 @@ define(function (require, exports, module) {
ProjectManager.showInTree(DocumentManager.getCurrentDocument().file);
}

function handleShowInOS() {
var entry = ProjectManager.getSidebarSelectedItem();
if (entry) {
brackets.app.showOSFolder(entry.fullPath, function (err) {
console.error("Error showing '" + entry.fullPath + "' in OS folder:", err);
Copy link
Member

Choose a reason for hiding this comment

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

Should only call console.error() if err is non-zero.

});
}
}


// Init DOM elements
AppInit.htmlReady(function () {
var $titleContainerToolbar = $("#titlebar");
Expand Down Expand Up @@ -876,6 +886,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 @@ -243,6 +243,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 @@ -175,18 +175,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 @@ -1419,7 +1434,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 @@ -431,13 +431,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