From 14066c4f0ed0abf209c08d737c5fa7b00d555b3a Mon Sep 17 00:00:00 2001 From: Julia Date: Tue, 2 Jan 2024 17:56:19 -0500 Subject: [PATCH] Add `icon_tooltip` for panel buttons rather than using persistent name --- crates/assistant2/src/assistant_panel.rs | 4 ++++ crates/collab_ui2/src/chat_panel.rs | 4 ++++ crates/collab_ui2/src/collab_panel.rs | 4 ++++ crates/collab_ui2/src/notification_panel.rs | 4 ++++ crates/project_panel2/src/project_panel.rs | 4 ++++ crates/terminal_view2/src/terminal_panel.rs | 4 ++++ crates/workspace2/src/dock.rs | 14 ++++++++++++-- 7 files changed, 36 insertions(+), 2 deletions(-) diff --git a/crates/assistant2/src/assistant_panel.rs b/crates/assistant2/src/assistant_panel.rs index b158facbd93dfc034a2b8f1cdb937fc988645f97..f93f33d539bdb20484d1d6c8942a69bad2832033 100644 --- a/crates/assistant2/src/assistant_panel.rs +++ b/crates/assistant2/src/assistant_panel.rs @@ -1281,6 +1281,10 @@ impl Panel for AssistantPanel { Some(Icon::Ai) } + fn icon_tooltip(&self, _cx: &WindowContext) -> Option<&'static str> { + Some("Assistant Panel") + } + fn toggle_action(&self) -> Box { Box::new(ToggleFocus) } diff --git a/crates/collab_ui2/src/chat_panel.rs b/crates/collab_ui2/src/chat_panel.rs index 84bd855754d47feebef62d1e99730a109c5097f8..2e161df9f41d418cb35b04c9e3f68684e2cde844 100644 --- a/crates/collab_ui2/src/chat_panel.rs +++ b/crates/collab_ui2/src/chat_panel.rs @@ -611,6 +611,10 @@ impl Panel for ChatPanel { Some(ui::Icon::MessageBubbles) } + fn icon_tooltip(&self, _cx: &WindowContext) -> Option<&'static str> { + Some("Chat Panel") + } + fn toggle_action(&self) -> Box { Box::new(ToggleFocus) } diff --git a/crates/collab_ui2/src/collab_panel.rs b/crates/collab_ui2/src/collab_panel.rs index 6b9f8a841b61becc9eef68a2cc0cac3bc72332bd..d5642241428e723b6a1622826f367b09ec58f6c5 100644 --- a/crates/collab_ui2/src/collab_panel.rs +++ b/crates/collab_ui2/src/collab_panel.rs @@ -2347,6 +2347,10 @@ impl Panel for CollabPanel { .then(|| ui::Icon::Collab) } + fn icon_tooltip(&self, _cx: &WindowContext) -> Option<&'static str> { + Some("Collab Panel") + } + fn toggle_action(&self) -> Box { Box::new(ToggleFocus) } diff --git a/crates/collab_ui2/src/notification_panel.rs b/crates/collab_ui2/src/notification_panel.rs index 68df41697fdf27c88cbf175b599d638b0283ddbb..e000921cdafc56908fb6f47ece85b419dff24a76 100644 --- a/crates/collab_ui2/src/notification_panel.rs +++ b/crates/collab_ui2/src/notification_panel.rs @@ -661,6 +661,10 @@ impl Panel for NotificationPanel { .then(|| Icon::Bell) } + fn icon_tooltip(&self, _cx: &WindowContext) -> Option<&'static str> { + Some("Notification Panel") + } + fn icon_label(&self, cx: &WindowContext) -> Option { let count = self.notification_store.read(cx).unread_notification_count(); if count == 0 { diff --git a/crates/project_panel2/src/project_panel.rs b/crates/project_panel2/src/project_panel.rs index 7f743015f1a79cd48c344c71af0c9ba50a966e6d..c125f76cd1aef9d95fd2c3b3e49c2bde3a65854e 100644 --- a/crates/project_panel2/src/project_panel.rs +++ b/crates/project_panel2/src/project_panel.rs @@ -1612,6 +1612,10 @@ impl Panel for ProjectPanel { Some(ui::Icon::FileTree) } + fn icon_tooltip(&self, _cx: &WindowContext) -> Option<&'static str> { + Some("Project Panel") + } + fn toggle_action(&self) -> Box { Box::new(ToggleFocus) } diff --git a/crates/terminal_view2/src/terminal_panel.rs b/crates/terminal_view2/src/terminal_panel.rs index d228e9e48d492721c0857f1cdb23538aefd789c8..05e4198f21b9504510a640909885a847db557167 100644 --- a/crates/terminal_view2/src/terminal_panel.rs +++ b/crates/terminal_view2/src/terminal_panel.rs @@ -419,6 +419,10 @@ impl Panel for TerminalPanel { Some(Icon::Terminal) } + fn icon_tooltip(&self, _cx: &WindowContext) -> Option<&'static str> { + Some("Terminal Panel") + } + fn toggle_action(&self) -> Box { Box::new(ToggleFocus) } diff --git a/crates/workspace2/src/dock.rs b/crates/workspace2/src/dock.rs index 3d853cdee1828b1990277521a934b97cf210c2c9..08949dfd21216b25d40c1039fd516dc964a89311 100644 --- a/crates/workspace2/src/dock.rs +++ b/crates/workspace2/src/dock.rs @@ -29,8 +29,8 @@ pub trait Panel: FocusableView + EventEmitter { fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext); fn size(&self, cx: &WindowContext) -> Pixels; fn set_size(&mut self, size: Option, cx: &mut ViewContext); - // todo!("We should have a icon tooltip method, rather than using persistant_name") fn icon(&self, cx: &WindowContext) -> Option; + fn icon_tooltip(&self, cx: &WindowContext) -> Option<&'static str>; fn toggle_action(&self) -> Box; fn icon_label(&self, _: &WindowContext) -> Option { None @@ -54,6 +54,7 @@ pub trait PanelHandle: Send + Sync { fn size(&self, cx: &WindowContext) -> Pixels; fn set_size(&self, size: Option, cx: &mut WindowContext); fn icon(&self, cx: &WindowContext) -> Option; + fn icon_tooltip(&self, cx: &WindowContext) -> Option<&'static str>; fn toggle_action(&self, cx: &WindowContext) -> Box; fn icon_label(&self, cx: &WindowContext) -> Option; fn focus_handle(&self, cx: &AppContext) -> FocusHandle; @@ -108,6 +109,10 @@ where self.read(cx).icon(cx) } + fn icon_tooltip(&self, cx: &WindowContext) -> Option<&'static str> { + self.read(cx).icon_tooltip(cx) + } + fn toggle_action(&self, cx: &WindowContext) -> Box { self.read(cx).toggle_action() } @@ -612,6 +617,7 @@ impl Render for PanelButtons { .enumerate() .filter_map(|(i, entry)| { let icon = entry.panel.icon(cx)?; + let icon_tooltip = entry.panel.icon_tooltip(cx)?; let name = entry.panel.persistent_name(); let panel = entry.panel.clone(); @@ -627,7 +633,7 @@ impl Render for PanelButtons { } else { let action = entry.panel.toggle_action(cx); - (action, name.into()) + (action, icon_tooltip.into()) }; Some( @@ -748,6 +754,10 @@ pub mod test { None } + fn icon_tooltip(&self, _cx: &WindowContext) -> Option<&'static str> { + None + } + fn toggle_action(&self) -> Box { ToggleTestPanel.boxed_clone() }