pane: Hide "Copy Relative Path" and "Reveal In Project Panel" actions for files outside of the projects (#25386)

"Copy Relative Path" action had a check for existence of relative path
but it always passed because
[`WorktreeStore::find_worktree()`](1d5499bee7/crates/project/src/worktree_store.rs (L148))
function returned empty path for these kinds of files. It feels correct
to make changes there, but I don't know what else could be impacted.

"Reveal In Project Panel" had no check whatsoever and so I made one.

Release Notes:

- N/A
This commit is contained in:
Egor Krugletsov 2025-03-02 00:31:18 +03:00 committed by GitHub
parent e65471c7a1
commit b0dee94126
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2566,15 +2566,34 @@ impl Pane {
}) })
}; };
if let Some(entry) = single_entry_to_resolve { 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 entry_abs_path = pane.read(cx).entry_abs_path(entry, cx);
let parent_abs_path = entry_abs_path let parent_abs_path = entry_abs_path
.as_deref() .as_deref()
.and_then(|abs_path| Some(abs_path.parent()?.to_path_buf())); .and_then(|abs_path| Some(abs_path.parent()?.to_path_buf()));
let relative_path = pane let relative_path = project_path
.read(cx) .map(|project_path| project_path.path)
.item_for_entry(entry, cx) .filter(|_| has_relative_path);
.and_then(|item| item.project_path(cx))
.map(|project_path| project_path.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(); let entry_id = entry.to_proto();
menu = menu menu = menu
@ -2603,21 +2622,23 @@ impl Pane {
}) })
.map(pin_tab_entries) .map(pin_tab_entries)
.separator() .separator()
.entry( .when(visible_in_project_panel, |menu| {
"Reveal In Project Panel", menu.entry(
Some(Box::new(RevealInProjectPanel { "Reveal In Project Panel",
entry_id: Some(entry_id), Some(Box::new(RevealInProjectPanel {
})), entry_id: Some(entry_id),
window.handler_for(&pane, move |pane, _, cx| { })),
pane.project window.handler_for(&pane, move |pane, _, cx| {
.update(cx, |_, cx| { pane.project
cx.emit(project::Event::RevealInProjectPanel( .update(cx, |_, cx| {
ProjectEntryId::from_proto(entry_id), cx.emit(project::Event::RevealInProjectPanel(
)) ProjectEntryId::from_proto(entry_id),
}) ))
.ok(); })
}), .ok();
) }),
)
})
.when_some(parent_abs_path, |menu, parent_abs_path| { .when_some(parent_abs_path, |menu, parent_abs_path| {
menu.entry( menu.entry(
"Open in Terminal", "Open in Terminal",