diff --git a/crates/agent_ui/src/sidebar.rs b/crates/agent_ui/src/sidebar.rs index 1e0ad2cd4689ac48c5deb42c5a5d23129238294d..2f1b3fb0719731b6cbdc7e26a2209be6b6c80ee9 100644 --- a/crates/agent_ui/src/sidebar.rs +++ b/crates/agent_ui/src/sidebar.rs @@ -30,7 +30,7 @@ use util::ResultExt as _; use util::path_list::PathList; use workspace::{ MultiWorkspace, MultiWorkspaceEvent, Workspace, - dock::{DockPosition, Panel, PanelEvent}, + dock::{DockPosition, Panel, PanelEvent, PanelIconButton}, multi_workspace_enabled, }; use zed_actions::assistant::ToggleThreadsSidebar; @@ -2026,16 +2026,12 @@ impl Panel for Sidebar { self.set_width(size, cx); } - fn icon(&self, _window: &Window, _cx: &App) -> IconName { - IconName::ThreadsSidebarLeftClosed - } - - fn icon_tooltip(&self, _window: &Window, _cx: &App) -> &'static str { - "Threads Sidebar" - } - - fn toggle_action(&self) -> Box { - Box::new(ToggleThreadsSidebar) + fn icon_button(&self, _window: &Window, _cx: &App) -> PanelIconButton { + PanelIconButton { + icon: IconName::ThreadsSidebarLeftClosed, + tooltip: "Threads Sidebar", + action: Box::new(ToggleThreadsSidebar), + } } fn activation_priority(&self) -> u32 { diff --git a/crates/collab_ui/src/collab_panel.rs b/crates/collab_ui/src/collab_panel.rs index 0b9ca9d921e18ec00184abf63b50cd1b260d6fe6..f88d9d450cc8560fa4fb19a2ab0f8e5c1be6478b 100644 --- a/crates/collab_ui/src/collab_panel.rs +++ b/crates/collab_ui/src/collab_panel.rs @@ -38,7 +38,7 @@ use util::{ResultExt, TryFutureExt, maybe}; use workspace::{ CopyRoomId, Deafen, LeaveCall, MultiWorkspace, Mute, OpenChannelNotes, OpenChannelNotesById, ScreenShare, ShareProject, Workspace, - dock::{DockPosition, Panel, PanelEvent}, + dock::{DockPosition, Panel, PanelEvent, PanelIconButton}, notifications::{DetachAndPromptErr, NotifyResultExt}, }; @@ -3191,22 +3191,18 @@ impl Panel for CollabPanel { }); } - fn icon(&self, _window: &Window, _cx: &App) -> ui::IconName { - ui::IconName::UserGroup - } - - fn icon_tooltip(&self, _window: &Window, _cx: &App) -> &'static str { - "Collab Panel" + fn icon_button(&self, _window: &Window, _cx: &App) -> PanelIconButton { + PanelIconButton { + icon: ui::IconName::UserGroup, + tooltip: "Collab Panel", + action: Box::new(ToggleFocus), + } } fn enabled(&self, cx: &App) -> bool { CollaborationPanelSettings::get_global(cx).button } - fn toggle_action(&self) -> Box { - Box::new(ToggleFocus) - } - fn persistent_name() -> &'static str { "CollabPanel" } diff --git a/crates/collab_ui/src/notification_panel.rs b/crates/collab_ui/src/notification_panel.rs index d417d843feee0216cd3b10fa4bfa0f0ba420428a..36bf5e0c9ff6259dfd1b1489811f76df132e44c9 100644 --- a/crates/collab_ui/src/notification_panel.rs +++ b/crates/collab_ui/src/notification_panel.rs @@ -27,7 +27,7 @@ use workspace::notifications::{ }; use workspace::{ Workspace, - dock::{DockPosition, Panel, PanelEvent}, + dock::{DockPosition, Panel, PanelEvent, PanelIconButton}, }; const LOADING_THRESHOLD: usize = 30; @@ -659,26 +659,22 @@ impl Panel for NotificationPanel { } } - fn icon(&self, _: &Window, _cx: &App) -> IconName { - if self.unseen_notifications.is_empty() { - IconName::Bell - } else { - IconName::BellDot + fn icon_button(&self, _window: &Window, _cx: &App) -> PanelIconButton { + PanelIconButton { + icon: if self.unseen_notifications.is_empty() { + IconName::Bell + } else { + IconName::BellDot + }, + tooltip: "Notification Panel", + action: Box::new(ToggleFocus), } } - fn icon_tooltip(&self, _window: &Window, _cx: &App) -> &'static str { - "Notification Panel" - } - fn enabled(&self, cx: &App) -> bool { NotificationPanelSettings::get_global(cx).button } - fn toggle_action(&self) -> Box { - Box::new(ToggleFocus) - } - fn activation_priority(&self) -> u32 { 8 } diff --git a/crates/debugger_ui/src/debugger_panel.rs b/crates/debugger_ui/src/debugger_panel.rs index 148a6ec63eccb2f8e71982b4dd4137e96f53e85e..febe189b8b582d055617018899ad59fc4562be31 100644 --- a/crates/debugger_ui/src/debugger_panel.rs +++ b/crates/debugger_ui/src/debugger_panel.rs @@ -42,7 +42,7 @@ use workspace::SplitDirection; use workspace::item::SaveOptions; use workspace::{ Item, Pane, Workspace, - dock::{DockPosition, Panel, PanelEvent}, + dock::{DockPosition, Panel, PanelEvent, PanelIconButton}, }; use zed_actions::debug_panel::ToggleFocus; @@ -1579,22 +1579,18 @@ impl Panel for DebugPanel { Some(proto::PanelId::DebugPanel) } - fn icon(&self, _window: &Window, _cx: &App) -> IconName { - IconName::Debug - } - - fn icon_tooltip(&self, _window: &Window, _cx: &App) -> &'static str { - "Debug Panel" + fn icon_button(&self, _window: &Window, _cx: &App) -> PanelIconButton { + PanelIconButton { + icon: IconName::Debug, + tooltip: "Debug Panel", + action: Box::new(ToggleFocus), + } } fn enabled(&self, cx: &App) -> bool { DebuggerSettings::get_global(cx).button } - fn toggle_action(&self) -> Box { - Box::new(ToggleFocus) - } - fn pane(&self) -> Option> { None } diff --git a/crates/git_ui/src/git_panel.rs b/crates/git_ui/src/git_panel.rs index ba6ce7f99df231f32a5c0bc2359928e4248873cd..ca5925b1da8fc955b0644c526915fa47bcb40218 100644 --- a/crates/git_ui/src/git_panel.rs +++ b/crates/git_ui/src/git_panel.rs @@ -76,7 +76,7 @@ use util::{ResultExt, TryFutureExt, maybe, rel_path::RelPath}; use workspace::SERIALIZATION_THROTTLE_TIME; use workspace::{ Workspace, - dock::{DockPosition, Panel, PanelEvent}, + dock::{DockPosition, Panel, PanelEvent, PanelIconButton}, notifications::{DetachAndPromptErr, ErrorMessagePrompt, NotificationId, NotifyResultExt}, }; @@ -5730,22 +5730,18 @@ impl Panel for GitPanel { cx.notify(); } - fn icon(&self, _: &Window, _cx: &App) -> ui::IconName { - ui::IconName::GitBranchAlt - } - - fn icon_tooltip(&self, _window: &Window, _cx: &App) -> &'static str { - "Git Panel" + fn icon_button(&self, _window: &Window, _cx: &App) -> PanelIconButton { + PanelIconButton { + icon: ui::IconName::GitBranchAlt, + tooltip: "Git Panel", + action: Box::new(ToggleFocus), + } } fn enabled(&self, cx: &App) -> bool { GitPanelSettings::get_global(cx).button } - fn toggle_action(&self) -> Box { - Box::new(ToggleFocus) - } - fn activation_priority(&self) -> u32 { 2 } diff --git a/crates/outline_panel/src/outline_panel.rs b/crates/outline_panel/src/outline_panel.rs index 1f2ec6f07a0e84c6130290d3c8767e9aec4e9e03..ede30b6401b9d7c6ee39de8bdfc61b03b8105c67 100644 --- a/crates/outline_panel/src/outline_panel.rs +++ b/crates/outline_panel/src/outline_panel.rs @@ -54,7 +54,7 @@ use ui::{ use util::{RangeExt, ResultExt, TryFutureExt, debug_panic, rel_path::RelPath}; use workspace::{ OpenInTerminal, WeakItemHandle, Workspace, - dock::{DockPosition, Panel, PanelEvent}, + dock::{DockPosition, Panel, PanelEvent, PanelIconButton}, item::ItemHandle, searchable::{SearchEvent, SearchableItem}, }; @@ -5017,22 +5017,18 @@ impl Panel for OutlinePanel { }); } - fn icon(&self, _: &Window, _cx: &App) -> IconName { - IconName::ListTree - } - - fn icon_tooltip(&self, _window: &Window, _: &App) -> &'static str { - "Outline Panel" + fn icon_button(&self, _window: &Window, _cx: &App) -> PanelIconButton { + PanelIconButton { + icon: IconName::ListTree, + tooltip: "Outline Panel", + action: Box::new(ToggleFocus), + } } fn enabled(&self, cx: &App) -> bool { OutlinePanelSettings::get_global(cx).button } - fn toggle_action(&self) -> Box { - Box::new(ToggleFocus) - } - fn starts_open(&self, _window: &Window, _: &App) -> bool { self.active } diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index f9315c3f28cb399c80bd563f79260a7988dff350..1d91c4bf33a2afc368118fe75cd31e7fa987f8e6 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -72,7 +72,7 @@ use util::{ use workspace::{ DraggedSelection, OpenInTerminal, OpenOptions, OpenVisible, PreviewTabsSettings, SelectedEntry, SplitDirection, Workspace, - dock::{DockPosition, Panel, PanelEvent}, + dock::{DockPosition, Panel, PanelEvent, PanelIconButton}, notifications::{DetachAndPromptErr, NotifyResultExt, NotifyTaskExt}, }; use worktree::CreatedEntry; @@ -7057,22 +7057,18 @@ impl Panel for ProjectPanel { }); } - fn icon(&self, _: &Window, _cx: &App) -> IconName { - IconName::FileTree - } - - fn icon_tooltip(&self, _window: &Window, _cx: &App) -> &'static str { - "Project Panel" + fn icon_button(&self, _window: &Window, _cx: &App) -> PanelIconButton { + PanelIconButton { + icon: IconName::FileTree, + tooltip: "Project Panel", + action: Box::new(ToggleFocus), + } } fn enabled(&self, cx: &App) -> bool { ProjectPanelSettings::get_global(cx).button } - fn toggle_action(&self) -> Box { - Box::new(ToggleFocus) - } - fn persistent_name() -> &'static str { "Project Panel" } diff --git a/crates/terminal_view/src/terminal_panel.rs b/crates/terminal_view/src/terminal_panel.rs index bf25e9eeb93d26466ac98067a13800951084709f..cb65dd3b0b74b31cc0ce02de77b0330c6f622941 100644 --- a/crates/terminal_view/src/terminal_panel.rs +++ b/crates/terminal_view/src/terminal_panel.rs @@ -32,7 +32,7 @@ use workspace::{ MoveItemToPaneInDirection, MovePaneDown, MovePaneLeft, MovePaneRight, MovePaneUp, Pane, PaneGroup, SplitDirection, SplitDown, SplitLeft, SplitMode, SplitRight, SplitUp, SwapPaneDown, SwapPaneLeft, SwapPaneRight, SwapPaneUp, ToggleZoom, Workspace, - dock::{DockPosition, Panel, PanelEvent, PanelHandle}, + dock::{DockPosition, Panel, PanelEvent, PanelHandle, PanelIconButton}, item::SerializableItem, move_active_item, pane, }; @@ -1613,16 +1613,12 @@ impl Panel for TerminalPanel { TERMINAL_PANEL_KEY } - fn icon(&self, _window: &Window, _cx: &App) -> IconName { - IconName::TerminalAlt - } - - fn icon_tooltip(&self, _window: &Window, _cx: &App) -> &'static str { - "Terminal Panel" - } - - fn toggle_action(&self) -> Box { - Box::new(ToggleFocus) + fn icon_button(&self, _window: &Window, _cx: &App) -> PanelIconButton { + PanelIconButton { + icon: IconName::TerminalAlt, + tooltip: "Terminal Panel", + action: Box::new(ToggleFocus), + } } fn pane(&self) -> Option> { diff --git a/crates/workspace/src/dock.rs b/crates/workspace/src/dock.rs index 4bfab25f42aeb0210f29ff9e677a36d70d6302e9..9f8960e498362a064d5268c931b563013ba7237d 100644 --- a/crates/workspace/src/dock.rs +++ b/crates/workspace/src/dock.rs @@ -26,6 +26,12 @@ pub enum PanelEvent { pub use proto::PanelId; +pub struct PanelIconButton { + pub icon: ui::IconName, + pub tooltip: &'static str, + pub action: Box, +} + pub trait Panel: Focusable + EventEmitter + Render + Sized { fn persistent_name() -> &'static str; fn panel_key() -> &'static str; @@ -34,9 +40,7 @@ pub trait Panel: Focusable + EventEmitter + Render + Sized { fn set_position(&mut self, position: DockPosition, window: &mut Window, cx: &mut Context); fn size(&self, window: &Window, cx: &App) -> Pixels; fn set_size(&mut self, size: Option, window: &mut Window, cx: &mut Context); - fn icon(&self, window: &Window, cx: &App) -> ui::IconName; - fn icon_tooltip(&self, window: &Window, cx: &App) -> &'static str; - fn toggle_action(&self) -> Box; + fn icon_button(&self, window: &Window, cx: &App) -> PanelIconButton; fn is_zoomed(&self, _window: &Window, _cx: &App) -> bool { false } @@ -71,9 +75,7 @@ pub trait PanelHandle: Send + Sync { fn pane(&self, cx: &App) -> Option>; fn size(&self, window: &Window, cx: &App) -> Pixels; fn set_size(&self, size: Option, window: &mut Window, cx: &mut App); - fn icon(&self, window: &Window, cx: &App) -> ui::IconName; - fn icon_tooltip(&self, window: &Window, cx: &App) -> &'static str; - fn toggle_action(&self, window: &Window, cx: &App) -> Box; + fn icon_button(&self, window: &Window, cx: &App) -> PanelIconButton; fn panel_focus_handle(&self, cx: &App) -> FocusHandle; fn to_any(&self) -> AnyView; fn activation_priority(&self, cx: &App) -> u32; @@ -151,16 +153,8 @@ where self.update(cx, |this, cx| this.set_size(size, window, cx)) } - fn icon(&self, window: &Window, cx: &App) -> ui::IconName { - self.read(cx).icon(window, cx) - } - - fn icon_tooltip(&self, window: &Window, cx: &App) -> &'static str { - self.read(cx).icon_tooltip(window, cx) - } - - fn toggle_action(&self, _: &Window, cx: &App) -> Box { - self.read(cx).toggle_action() + fn icon_button(&self, window: &Window, cx: &App) -> PanelIconButton { + self.read(cx).icon_button(window, cx) } fn to_any(&self) -> AnyView { @@ -908,8 +902,11 @@ impl Render for PanelButtons { if !entry.panel.enabled(cx) { return None; } - let icon = entry.panel.icon(window, cx); - let icon_tooltip = entry.panel.icon_tooltip(window, cx); + let PanelIconButton { + icon, + tooltip: icon_tooltip, + action: toggle_action, + } = entry.panel.icon_button(window, cx); let name = entry.panel.persistent_name(); let panel = entry.panel.clone(); @@ -922,9 +919,7 @@ impl Render for PanelButtons { (action, tooltip) } else { - let action = entry.panel.toggle_action(window, cx); - - (action, icon_tooltip.into()) + (toggle_action, icon_tooltip.into()) }; let focus_handle = dock.focus_handle(cx); @@ -1073,16 +1068,12 @@ pub mod test { self.size = size.unwrap_or(px(300.)); } - fn icon(&self, _window: &Window, _: &App) -> ui::IconName { - ui::IconName::Cog - } - - fn icon_tooltip(&self, _window: &Window, _cx: &App) -> &'static str { - "Test Panel" - } - - fn toggle_action(&self) -> Box { - ToggleTestPanel.boxed_clone() + fn icon_button(&self, _window: &Window, _cx: &App) -> PanelIconButton { + PanelIconButton { + icon: ui::IconName::Cog, + tooltip: "Test Panel", + action: ToggleTestPanel.boxed_clone(), + } } fn is_zoomed(&self, _window: &Window, _: &App) -> bool {