Combine panel icon button info

Eric Holk created

Change summary

crates/agent_ui/src/sidebar.rs             | 18 +++----
crates/collab_ui/src/collab_panel.rs       | 18 +++----
crates/collab_ui/src/notification_panel.rs | 24 ++++------
crates/debugger_ui/src/debugger_panel.rs   | 18 +++----
crates/git_ui/src/git_panel.rs             | 18 +++----
crates/outline_panel/src/outline_panel.rs  | 18 +++----
crates/project_panel/src/project_panel.rs  | 18 +++----
crates/terminal_view/src/terminal_panel.rs | 18 +++----
crates/workspace/src/dock.rs               | 53 +++++++++--------------
9 files changed, 81 insertions(+), 122 deletions(-)

Detailed changes

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<dyn Action> {
-        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 {

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<dyn gpui::Action> {
-        Box::new(ToggleFocus)
-    }
-
     fn persistent_name() -> &'static str {
         "CollabPanel"
     }

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<dyn gpui::Action> {
-        Box::new(ToggleFocus)
-    }
-
     fn activation_priority(&self) -> u32 {
         8
     }

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<dyn Action> {
-        Box::new(ToggleFocus)
-    }
-
     fn pane(&self) -> Option<Entity<Pane>> {
         None
     }

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<dyn Action> {
-        Box::new(ToggleFocus)
-    }
-
     fn activation_priority(&self) -> u32 {
         2
     }

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<dyn Action> {
-        Box::new(ToggleFocus)
-    }
-
     fn starts_open(&self, _window: &Window, _: &App) -> bool {
         self.active
     }

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<dyn Action> {
-        Box::new(ToggleFocus)
-    }
-
     fn persistent_name() -> &'static str {
         "Project Panel"
     }

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<dyn gpui::Action> {
-        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<Entity<Pane>> {

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<dyn Action>,
+}
+
 pub trait Panel: Focusable + EventEmitter<PanelEvent> + Render + Sized {
     fn persistent_name() -> &'static str;
     fn panel_key() -> &'static str;
@@ -34,9 +40,7 @@ pub trait Panel: Focusable + EventEmitter<PanelEvent> + Render + Sized {
     fn set_position(&mut self, position: DockPosition, window: &mut Window, cx: &mut Context<Self>);
     fn size(&self, window: &Window, cx: &App) -> Pixels;
     fn set_size(&mut self, size: Option<Pixels>, window: &mut Window, cx: &mut Context<Self>);
-    fn icon(&self, window: &Window, cx: &App) -> ui::IconName;
-    fn icon_tooltip(&self, window: &Window, cx: &App) -> &'static str;
-    fn toggle_action(&self) -> Box<dyn Action>;
+    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<Entity<Pane>>;
     fn size(&self, window: &Window, cx: &App) -> Pixels;
     fn set_size(&self, size: Option<Pixels>, 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<dyn Action>;
+    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<dyn Action> {
-        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<dyn Action> {
-            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 {