tab_switcher: Add support for tab switcher in assistant panel (#15475)

Additionally, I've generalized the implementation of tab switcher so
that - instead of explicitly listing panels it supports (at the time of
writing it was just the terminal panel and nothing else), it now relies
on Panel::pane trait method. As long as that's implemented, you get a
tab switcher support for free.

Release Notes:

- Added support for tab switcher in Assistant panel.
This commit is contained in:
Piotr Osiewicz 2024-07-30 13:32:13 +02:00 committed by GitHub
parent 0540291204
commit 530feecdaa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 35 additions and 32 deletions

View file

@ -18,7 +18,6 @@ gpui.workspace = true
menu.workspace = true
picker.workspace = true
serde.workspace = true
terminal_view.workspace = true
ui.workspace = true
util.workspace = true
workspace.workspace = true

View file

@ -57,16 +57,25 @@ impl TabSwitcher {
}
fn open(action: &Toggle, workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
let terminal = workspace.panel::<terminal_view::terminal_panel::TerminalPanel>(cx);
let terminal_pane = terminal.and_then(|terminal| {
terminal
.focus_handle(cx)
.contains_focused(cx)
.then(|| terminal.read(cx).pane())
});
let weak_pane = terminal_pane
.unwrap_or_else(|| workspace.active_pane())
.downgrade();
let mut weak_pane = workspace.active_pane().downgrade();
for dock in [
workspace.left_dock(),
workspace.bottom_dock(),
workspace.right_dock(),
] {
dock.update(cx, |this, cx| {
let Some(panel) = this
.active_panel()
.filter(|panel| panel.focus_handle(cx).contains_focused(cx))
else {
return;
};
if let Some(pane) = panel.pane(cx) {
weak_pane = pane.downgrade();
}
})
}
workspace.toggle_modal(cx, |cx| {
let delegate = TabSwitcherDelegate::new(action, cx.view().downgrade(), weak_pane, cx);
TabSwitcher::new(delegate, cx)