Add "Open in Terminal" context menu entries for project panel, editor and tab context menus (#10741)

Closes https://github.com/zed-industries/zed/issues/4566

Pane tabs (does not exist for multibuffer tabs):
<img width="439" alt="Screenshot 2024-04-18 at 23 01 08"
src="https://github.com/zed-industries/zed/assets/2690773/3af79ed8-07ea-4cf2-bcf9-735b1b3be8c4">

Editor context menu:
<img width="404" alt="Screenshot 2024-04-18 at 23 01 14"
src="https://github.com/zed-industries/zed/assets/2690773/38ea7afc-df2b-45ef-8331-eb6a4588af9f">

Project panel context menu (was not shown for file entries before this):
<img width="408" alt="Screenshot 2024-04-18 at 23 01 18"
src="https://github.com/zed-industries/zed/assets/2690773/e336fce1-7da0-4671-b8d2-8d3409c23eb6">

Release Notes:

- (breaking change) Moved `project_panel::OpenInTerminal` into
`workspace::OpenInTerminal` action and add it in editors, tab context
menus and proper panel file entries
([4566](https://github.com/zed-industries/zed/issues/4566))
This commit is contained in:
Kirill Bulatov 2024-04-19 01:43:46 +03:00 committed by GitHub
parent 250b71fb44
commit 870a61dd4d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 101 additions and 45 deletions

View file

@ -5,7 +5,8 @@ use crate::{
},
toolbar::Toolbar,
workspace_settings::{AutosaveSetting, TabBarSettings, WorkspaceSettings},
NewCenterTerminal, NewFile, NewSearch, OpenVisible, SplitDirection, ToggleZoom, Workspace,
NewCenterTerminal, NewFile, NewSearch, OpenInTerminal, OpenTerminal, OpenVisible,
SplitDirection, ToggleZoom, Workspace,
};
use anyhow::Result;
use collections::{HashMap, HashSet, VecDeque};
@ -1597,20 +1598,58 @@ impl Pane {
);
if let Some(entry) = single_entry_to_resolve {
let parent_abs_path = pane
.update(cx, |pane, cx| {
pane.workspace.update(cx, |workspace, cx| {
let project = workspace.project().read(cx);
project.worktree_for_entry(entry, cx).and_then(|worktree| {
let worktree = worktree.read(cx);
let entry = worktree.entry_for_id(entry)?;
let abs_path = worktree.absolutize(&entry.path).ok()?;
let parent = if entry.is_symlink {
abs_path.canonicalize().ok()?
} else {
abs_path
}
.parent()?
.to_path_buf();
Some(parent)
})
})
})
.ok()
.flatten();
let entry_id = entry.to_proto();
menu = menu.separator().entry(
"Reveal In Project Panel",
Some(Box::new(RevealInProjectPanel {
entry_id: Some(entry_id),
})),
cx.handler_for(&pane, move |pane, cx| {
pane.project.update(cx, |_, cx| {
cx.emit(project::Event::RevealInProjectPanel(
ProjectEntryId::from_proto(entry_id),
))
});
}),
);
menu = menu
.separator()
.entry(
"Reveal In Project Panel",
Some(Box::new(RevealInProjectPanel {
entry_id: Some(entry_id),
})),
cx.handler_for(&pane, move |pane, cx| {
pane.project.update(cx, |_, cx| {
cx.emit(project::Event::RevealInProjectPanel(
ProjectEntryId::from_proto(entry_id),
))
});
}),
)
.when_some(parent_abs_path, |menu, abs_path| {
menu.entry(
"Open in Terminal",
Some(Box::new(OpenInTerminal)),
cx.handler_for(&pane, move |_, cx| {
cx.dispatch_action(
OpenTerminal {
working_directory: abs_path.clone(),
}
.boxed_clone(),
);
}),
)
});
}
}

View file

@ -112,6 +112,7 @@ actions!(
workspace,
[
Open,
OpenInTerminal,
NewFile,
NewWindow,
CloseWindow,