Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
pane: Add "Reveal in Finder" to tab context menu (#51615)
Matt Van Horn7b14c7be5c23
diff --git a/crates/editor/src/actions.rs b/crates/editor/src/actions.rsindex d1d2390fd86..a51ee787f8b 100644--- a/crates/editor/src/actions.rs+++ b/crates/editor/src/actions.rs@@ -699,8 +699,6 @@ actions!(Rename,/// Restarts the language server for the current file.RestartLanguageServer,- /// Reveals the current file in the system file manager.- RevealInFileManager,/// Reverses the order of selected lines.ReverseLines,/// Reloads the file from disk.diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 99814b3cbce..b4f88ea5013 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -221,6 +221,7 @@ use workspace::{notifications::{DetachAndPromptErr, NotificationId, NotifyTaskExt},searchable::SearchEvent,};+pub use zed_actions::editor::RevealInFileManager;use zed_actions::editor::{MoveDown, MoveUp};use crate::{diff --git a/crates/editor/src/mouse_context_menu.rs b/crates/editor/src/mouse_context_menu.rsindex af7b256d78e..2ddbb48b5fc 100644--- a/crates/editor/src/mouse_context_menu.rs+++ b/crates/editor/src/mouse_context_menu.rs@@ -286,13 +286,7 @@ pub fn deploy_context_menu(.separator().action_disabled_when(!has_reveal_target,- if cfg!(target_os = "macos") {- "Reveal in Finder"- } else if cfg!(target_os = "windows") {- "Reveal in File Explorer"- } else {- "Reveal in File Manager"- },+ ui::utils::reveal_in_file_manager_label(false),Box::new(RevealInFileManager),).when(is_markdown, |builder| {diff --git a/crates/outline_panel/src/outline_panel.rs b/crates/outline_panel/src/outline_panel.rsindex e35301ee16b..c4d491db923 100644--- a/crates/outline_panel/src/outline_panel.rs+++ b/crates/outline_panel/src/outline_panel.rs@@ -1490,13 +1490,7 @@ impl OutlinePanel {let context_menu = ContextMenu::build(window, cx, |menu, _, _| {menu.context(self.focus_handle.clone()).action(- if cfg!(target_os = "macos") {- "Reveal in Finder"- } else if cfg!(target_os = "windows") {- "Reveal in File Explorer"- } else {- "Reveal in File Manager"- },+ ui::utils::reveal_in_file_manager_label(false),Box::new(RevealInFileManager),).action("Open in Terminal", Box::new(OpenInTerminal))diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rsindex 652740582da..eafaf208d98 100644--- a/crates/project_panel/src/project_panel.rs+++ b/crates/project_panel/src/project_panel.rs@@ -1201,13 +1201,7 @@ impl ProjectPanel {.separator().when(is_local, |menu| {menu.action(- if cfg!(target_os = "macos") && !is_remote {- "Reveal in Finder"- } else if cfg!(target_os = "windows") && !is_remote {- "Reveal in File Explorer"- } else {- "Reveal in File Manager"- },+ ui::utils::reveal_in_file_manager_label(is_remote),Box::new(RevealInFileManager),)})diff --git a/crates/ui/src/utils.rs b/crates/ui/src/utils.rsindex b73915162f9..2f2a148e198 100644--- a/crates/ui/src/utils.rs+++ b/crates/ui/src/utils.rs@@ -23,3 +23,14 @@ pub use with_rem_size::*;pub fn is_light(cx: &mut App) -> bool {cx.theme().appearance.is_light()}++/// Returns the platform-appropriate label for the "reveal in file manager" action.+pub fn reveal_in_file_manager_label(is_remote: bool) -> &'static str {+ if cfg!(target_os = "macos") && !is_remote {+ "Reveal in Finder"+ } else if cfg!(target_os = "windows") && !is_remote {+ "Reveal in File Explorer"+ } else {+ "Reveal in File Manager"+ }+}diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rsindex 5f1177e58d5..54f83bbbe64 100644--- a/crates/workspace/src/pane.rs+++ b/crates/workspace/src/pane.rs@@ -3192,6 +3192,7 @@ impl Pane {});let entry_abs_path = pane.read(cx).entry_abs_path(entry, cx);+ let reveal_path = entry_abs_path.clone();let parent_abs_path = entry_abs_path.as_deref().and_then(|abs_path| Some(abs_path.parent()?.to_path_buf()));@@ -3201,6 +3202,15 @@ impl Pane {let visible_in_project_panel = relative_path.is_some()&& worktree.is_some_and(|worktree| worktree.read(cx).is_visible());+ let is_local = pane.read(cx).project.upgrade().is_some_and(|project| {+ let project = project.read(cx);+ project.is_local() || project.is_via_wsl_with_host_interop(cx)+ });+ let is_remote = pane+ .read(cx)+ .project+ .upgrade()+ .is_some_and(|project| project.read(cx).is_remote());let entry_id = entry.to_proto();@@ -3233,8 +3243,26 @@ impl Pane {}),)})+ .when(is_local, |menu| {+ menu.when_some(reveal_path, |menu, reveal_path| {+ menu.separator().entry(+ ui::utils::reveal_in_file_manager_label(is_remote),+ Some(Box::new(+ zed_actions::editor::RevealInFileManager,+ )),+ window.handler_for(&pane, move |pane, _, cx| {+ if let Some(project) = pane.project.upgrade() {+ project.update(cx, |project, cx| {+ project.reveal_path(&reveal_path, cx);+ });+ } else {+ cx.reveal_path(&reveal_path);+ }+ }),+ )+ })+ }).map(pin_tab_entries)- .separator().when(visible_in_project_panel, |menu| {menu.entry("Reveal In Project Panel",diff --git a/crates/zed_actions/src/lib.rs b/crates/zed_actions/src/lib.rsindex fe1575bd155..0306854c0ad 100644--- a/crates/zed_actions/src/lib.rs+++ b/crates/zed_actions/src/lib.rs@@ -197,6 +197,8 @@ pub mod editor {MoveUp,/// Moves cursor down.MoveDown,+ /// Reveals the current file in the system file manager.+ RevealInFileManager,]);}