diff --git a/crates/ui2/src/components/keybinding.rs b/crates/ui2/src/components/keybinding.rs index a3e5a870a6..04e036f365 100644 --- a/crates/ui2/src/components/keybinding.rs +++ b/crates/ui2/src/components/keybinding.rs @@ -3,7 +3,7 @@ use strum::EnumIter; use crate::prelude::*; -#[derive(Component)] +#[derive(Component, Clone)] pub struct KeyBinding { /// A keybinding consists of a key and a set of modifier keys. /// More then one keybinding produces a chord. diff --git a/crates/ui2/src/components/tooltip.rs b/crates/ui2/src/components/tooltip.rs index 0d4f10e35e..8f31d77b67 100644 --- a/crates/ui2/src/components/tooltip.rs +++ b/crates/ui2/src/components/tooltip.rs @@ -1,15 +1,13 @@ -use gpui::{div, Component, Div, ParentElement, Render, SharedString, Styled, ViewContext}; +use gpui::{Div, Render}; use theme2::ActiveTheme; -use crate::{h_stack, v_stack, Label, LabelColor, StyledExt}; +use crate::prelude::*; +use crate::{h_stack, v_stack, KeyBinding, Label, LabelColor, StyledExt}; -use super::keybinding; - -#[derive(Clone, Debug)] pub struct TextTooltip { title: SharedString, meta: Option, - keybinding: Option, + key_binding: Option, } impl TextTooltip { @@ -17,7 +15,7 @@ impl TextTooltip { Self { title: title.into(), meta: None, - keybinding: None, + key_binding: None, } } @@ -26,8 +24,8 @@ impl TextTooltip { self } - pub fn keybinding(mut self, keybinding: impl Into) -> Self { - self.keybinding = Some(keybinding.into()); + pub fn key_binding(mut self, key_binding: impl Into>) -> Self { + self.key_binding = key_binding.into(); self } } @@ -43,13 +41,13 @@ impl Render for TextTooltip { .text_color(cx.theme().colors().text) .py_1() .px_2() - .child(h_stack().child(self.title.clone()).when_some( - self.keybinding.clone(), - |this, keybinding| { - this.justify_between() - .child(Label::new(keybinding).color(LabelColor::Muted)) - }, - )) + .child( + h_stack() + .child(self.title.clone()) + .when_some(self.key_binding.clone(), |this, key_binding| { + this.justify_between().child(key_binding) + }), + ) .when_some(self.meta.clone(), |this, meta| { this.child(Label::new(meta).color(LabelColor::Muted)) }) diff --git a/crates/workspace2/src/workspace2.rs b/crates/workspace2/src/workspace2.rs index a036b030c9..88e8dc7934 100644 --- a/crates/workspace2/src/workspace2.rs +++ b/crates/workspace2/src/workspace2.rs @@ -69,7 +69,7 @@ use std::{ }; use theme2::ActiveTheme; pub use toolbar::{ToolbarItemLocation, ToolbarItemView}; -use ui::{h_stack, Button, ButtonVariant, Label, LabelColor, TextTooltip}; +use ui::{h_stack, Button, ButtonVariant, KeyBinding, Label, LabelColor, TextTooltip}; use util::ResultExt; use uuid::Uuid; use workspace_settings::{AutosaveSetting, WorkspaceSettings}; @@ -2502,9 +2502,17 @@ impl Workspace { .color(Some(LabelColor::Muted)), ) .tooltip(move |_, cx| { + // todo!() Replace with real action. + #[gpui::action] + struct NoAction {} + cx.build_view(|cx| { TextTooltip::new("Recent Branches") - .keybinding("⌘B") + .key_binding(KeyBinding::new(gpui::KeyBinding::new( + "cmd-b", + NoAction {}, + None, + ))) .meta("Only local branches shown") }) }),