Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
pane: Hide "Copy Relative Path" and "Reveal In Project Panel" actions for files outside of the projects (#25386)
Egor Krugletsovb0dee9412675
diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rsindex 5ee62fdecfa..1c707b748ea 100644--- a/crates/workspace/src/pane.rs+++ b/crates/workspace/src/pane.rs@@ -2566,15 +2566,34 @@ impl Pane {})};if let Some(entry) = single_entry_to_resolve {+ let project_path = pane+ .read(cx)+ .item_for_entry(entry, cx)+ .and_then(|item| item.project_path(cx));+ let worktree = project_path.as_ref().and_then(|project_path| {+ pane.read(cx)+ .project+ .upgrade()?+ .read(cx)+ .worktree_for_id(project_path.worktree_id, cx)+ });+ let has_relative_path = worktree.as_ref().is_some_and(|worktree| {+ worktree+ .read(cx)+ .root_entry()+ .map_or(false, |entry| entry.is_dir())+ });+let entry_abs_path = pane.read(cx).entry_abs_path(entry, cx);let parent_abs_path = entry_abs_path.as_deref().and_then(|abs_path| Some(abs_path.parent()?.to_path_buf()));- let relative_path = pane- .read(cx)- .item_for_entry(entry, cx)- .and_then(|item| item.project_path(cx))- .map(|project_path| project_path.path);+ let relative_path = project_path+ .map(|project_path| project_path.path)+ .filter(|_| has_relative_path);++ let visible_in_project_panel = relative_path.is_some()+ && worktree.is_some_and(|worktree| worktree.read(cx).is_visible());let entry_id = entry.to_proto();menu = menu@@ -2603,21 +2622,23 @@ impl Pane {}).map(pin_tab_entries).separator()- .entry(- "Reveal In Project Panel",- Some(Box::new(RevealInProjectPanel {- entry_id: Some(entry_id),- })),- window.handler_for(&pane, move |pane, _, cx| {- pane.project- .update(cx, |_, cx| {- cx.emit(project::Event::RevealInProjectPanel(- ProjectEntryId::from_proto(entry_id),- ))- })- .ok();- }),- )+ .when(visible_in_project_panel, |menu| {+ menu.entry(+ "Reveal In Project Panel",+ Some(Box::new(RevealInProjectPanel {+ entry_id: Some(entry_id),+ })),+ window.handler_for(&pane, move |pane, _, cx| {+ pane.project+ .update(cx, |_, cx| {+ cx.emit(project::Event::RevealInProjectPanel(+ ProjectEntryId::from_proto(entry_id),+ ))+ })+ .ok();+ }),+ )+ }).when_some(parent_abs_path, |menu, parent_abs_path| {menu.entry("Open in Terminal",