diff --git a/crates/ai/src/assistant.rs b/crates/ai/src/assistant.rs index 957c5e1c06..0a18266d2a 100644 --- a/crates/ai/src/assistant.rs +++ b/crates/ai/src/assistant.rs @@ -362,7 +362,7 @@ impl AssistantPanel { this.set_active_editor_index(this.prev_active_editor_index, cx); } }) - .with_tooltip::(1, "History".into(), None, tooltip_style, cx) + .with_tooltip::(1, "History", None, tooltip_style, cx) } fn render_editor_tools(&self, cx: &mut ViewContext) -> Vec> { @@ -394,7 +394,7 @@ impl AssistantPanel { }) .with_tooltip::( 1, - "Split Message".into(), + "Split Message", Some(Box::new(Split)), tooltip_style, cx, @@ -416,13 +416,7 @@ impl AssistantPanel { active_editor.update(cx, |editor, cx| editor.assist(&Default::default(), cx)); } }) - .with_tooltip::( - 1, - "Assist".into(), - Some(Box::new(Assist)), - tooltip_style, - cx, - ) + .with_tooltip::(1, "Assist", Some(Box::new(Assist)), tooltip_style, cx) } fn render_quote_button(cx: &mut ViewContext) -> impl Element { @@ -446,7 +440,7 @@ impl AssistantPanel { }) .with_tooltip::( 1, - "Quote Selection".into(), + "Quote Selection", Some(Box::new(QuoteSelection)), tooltip_style, cx, @@ -468,7 +462,7 @@ impl AssistantPanel { }) .with_tooltip::( 1, - "New Conversation".into(), + "New Conversation", Some(Box::new(NewConversation)), tooltip_style, cx, @@ -498,11 +492,7 @@ impl AssistantPanel { }) .with_tooltip::( 0, - if self.zoomed { - "Zoom Out".into() - } else { - "Zoom In".into() - }, + if self.zoomed { "Zoom Out" } else { "Zoom In" }, Some(Box::new(ToggleZoom)), tooltip_style, cx, diff --git a/crates/collab_ui/src/collab_titlebar_item.rs b/crates/collab_ui/src/collab_titlebar_item.rs index dbcbaf6072..fefb1c608f 100644 --- a/crates/collab_ui/src/collab_titlebar_item.rs +++ b/crates/collab_ui/src/collab_titlebar_item.rs @@ -238,7 +238,7 @@ impl CollabTitlebarItem { .left() .with_tooltip::( 0, - "Recent projects".into(), + "Recent projects", Some(Box::new(recent_projects::OpenRecent)), theme.tooltip.clone(), cx, @@ -282,7 +282,7 @@ impl CollabTitlebarItem { .left() .with_tooltip::( 0, - "Recent branches".into(), + "Recent branches", Some(Box::new(ToggleVcsMenu)), theme.tooltip.clone(), cx, @@ -582,7 +582,7 @@ impl CollabTitlebarItem { }) .with_tooltip::( 0, - "Show contacts menu".into(), + "Show contacts menu", Some(Box::new(ToggleContactsMenu)), theme.tooltip.clone(), cx, @@ -633,7 +633,7 @@ impl CollabTitlebarItem { }) .with_tooltip::( 0, - tooltip.into(), + tooltip, Some(Box::new(ToggleScreenSharing)), theme.tooltip.clone(), cx, @@ -686,7 +686,7 @@ impl CollabTitlebarItem { }) .with_tooltip::( 0, - tooltip.into(), + tooltip, Some(Box::new(ToggleMute)), theme.tooltip.clone(), cx, @@ -734,7 +734,7 @@ impl CollabTitlebarItem { }) .with_tooltip::( 0, - tooltip.into(), + tooltip, Some(Box::new(ToggleDeafen)), theme.tooltip.clone(), cx, @@ -768,7 +768,7 @@ impl CollabTitlebarItem { }) .with_tooltip::( 0, - tooltip.into(), + tooltip, Some(Box::new(LeaveCall)), theme.tooltip.clone(), cx, diff --git a/crates/collab_ui/src/contact_list.rs b/crates/collab_ui/src/contact_list.rs index 4978452384..24ecec08e7 100644 --- a/crates/collab_ui/src/contact_list.rs +++ b/crates/collab_ui/src/contact_list.rs @@ -1345,7 +1345,7 @@ impl View for ContactList { }) .with_tooltip::( 0, - "Search for new contact".into(), + "Search for new contact", None, theme.tooltip.clone(), cx, diff --git a/crates/copilot_button/src/copilot_button.rs b/crates/copilot_button/src/copilot_button.rs index 5576451b1b..eae1746a01 100644 --- a/crates/copilot_button/src/copilot_button.rs +++ b/crates/copilot_button/src/copilot_button.rs @@ -140,7 +140,7 @@ impl View for CopilotButton { }) .with_tooltip::( 0, - "GitHub Copilot".into(), + "GitHub Copilot", None, theme.tooltip.clone(), cx, diff --git a/crates/diagnostics/src/items.rs b/crates/diagnostics/src/items.rs index c106f042b5..0ae55e99d9 100644 --- a/crates/diagnostics/src/items.rs +++ b/crates/diagnostics/src/items.rs @@ -173,7 +173,7 @@ impl View for DiagnosticIndicator { }) .with_tooltip::( 0, - "Project Diagnostics".to_string(), + "Project Diagnostics", Some(Box::new(crate::Deploy)), tooltip_style, cx, diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 02cd58524b..8d8b77ea95 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -8685,7 +8685,7 @@ pub fn diagnostic_block_renderer(diagnostic: Diagnostic, is_valid: bool) -> Rend // We really need to rethink this ID system... .with_tooltip::( cx.block_id, - "Copy diagnostic message".to_string(), + "Copy diagnostic message", None, tooltip_style, cx, diff --git a/crates/feedback/src/deploy_feedback_button.rs b/crates/feedback/src/deploy_feedback_button.rs index beb5284031..d197f57fa5 100644 --- a/crates/feedback/src/deploy_feedback_button.rs +++ b/crates/feedback/src/deploy_feedback_button.rs @@ -66,7 +66,7 @@ impl View for DeployFeedbackButton { }) .with_tooltip::( 0, - "Send Feedback".into(), + "Send Feedback", Some(Box::new(GiveFeedback)), theme.tooltip.clone(), cx, diff --git a/crates/feedback/src/submit_feedback_button.rs b/crates/feedback/src/submit_feedback_button.rs index 03a2cd51ed..2133296e25 100644 --- a/crates/feedback/src/submit_feedback_button.rs +++ b/crates/feedback/src/submit_feedback_button.rs @@ -80,7 +80,7 @@ impl View for SubmitFeedbackButton { .with_margin_left(theme.feedback.button_margin) .with_tooltip::( 0, - "cmd-s".into(), + "cmd-s", Some(Box::new(SubmitFeedback)), theme.tooltip.clone(), cx, diff --git a/crates/gpui/src/elements.rs b/crates/gpui/src/elements.rs index 5bed935319..bc903fe74c 100644 --- a/crates/gpui/src/elements.rs +++ b/crates/gpui/src/elements.rs @@ -170,7 +170,7 @@ pub trait Element: 'static { fn with_tooltip( self, id: usize, - text: String, + text: impl Into>, action: Option>, style: TooltipStyle, cx: &mut ViewContext, @@ -178,7 +178,7 @@ pub trait Element: 'static { where Self: 'static + Sized, { - Tooltip::new::(id, text, action, style, self.into_any(), cx) + Tooltip::new::(id, text, action, style, self.into_any(), cx) } fn resizable( diff --git a/crates/gpui/src/elements/tooltip.rs b/crates/gpui/src/elements/tooltip.rs index 0510baa9e4..14f3809e67 100644 --- a/crates/gpui/src/elements/tooltip.rs +++ b/crates/gpui/src/elements/tooltip.rs @@ -12,6 +12,7 @@ use crate::{ use schemars::JsonSchema; use serde::Deserialize; use std::{ + borrow::Cow, cell::{Cell, RefCell}, ops::Range, rc::Rc, @@ -52,9 +53,9 @@ pub struct KeystrokeStyle { } impl Tooltip { - pub fn new( + pub fn new( id: usize, - text: String, + text: impl Into>, action: Option>, style: TooltipStyle, child: AnyElement, @@ -66,6 +67,8 @@ impl Tooltip { let state_handle = cx.default_element_state::, Rc>(id); let state = state_handle.read(cx).clone(); + let text = text.into(); + let tooltip = if state.visible.get() { let mut collapsed_tooltip = Self::render_tooltip( focused_view_id, @@ -127,7 +130,7 @@ impl Tooltip { pub fn render_tooltip( focused_view_id: Option, - text: String, + text: impl Into>, style: TooltipStyle, action: Option>, measure: bool, diff --git a/crates/terminal_view/src/terminal_panel.rs b/crates/terminal_view/src/terminal_panel.rs index 6be8a547cd..770cae907c 100644 --- a/crates/terminal_view/src/terminal_panel.rs +++ b/crates/terminal_view/src/terminal_panel.rs @@ -72,10 +72,7 @@ impl TerminalPanel { 0, "icons/plus_12.svg", false, - Some(( - "New Terminal".into(), - Some(Box::new(workspace::NewTerminal)), - )), + Some(("New Terminal", Some(Box::new(workspace::NewTerminal)))), cx, move |_, cx| { let this = this.clone(); diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index 8064478964..1463ac2155 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -303,10 +303,10 @@ impl Pane { let tooltip_label; if pane.is_zoomed() { icon_path = "icons/minimize_8.svg"; - tooltip_label = "Zoom In".into(); + tooltip_label = "Zoom In"; } else { icon_path = "icons/maximize_8.svg"; - tooltip_label = "Zoom In".into(); + tooltip_label = "Zoom In"; } Pane::render_tab_bar_button( @@ -1477,7 +1477,7 @@ impl Pane { index: usize, icon: &'static str, is_active: bool, - tooltip: Option<(String, Option>)>, + tooltip: Option<(&'static str, Option>)>, cx: &mut ViewContext, on_click: F1, on_down: F2, diff --git a/crates/workspace/src/toolbar.rs b/crates/workspace/src/toolbar.rs index 69394b8421..945ac7b0f5 100644 --- a/crates/workspace/src/toolbar.rs +++ b/crates/workspace/src/toolbar.rs @@ -220,7 +220,7 @@ fn nav_button spacing: f32, on_click: F, tooltip_action: A, - action_name: &str, + action_name: &'static str, cx: &mut ViewContext, ) -> AnyElement { MouseEventHandler::::new(0, cx, |state, _| { @@ -252,7 +252,7 @@ fn nav_button }) .with_tooltip::( 0, - action_name.to_string(), + action_name, Some(Box::new(tooltip_action)), tooltip_style, cx,