mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-06 10:42:08 +00:00
Pass KeyBinding
s to TextTooltip
s
This commit is contained in:
parent
aa1471948f
commit
90d7033fd0
3 changed files with 25 additions and 19 deletions
|
@ -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.
|
||||
|
|
|
@ -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<SharedString>,
|
||||
keybinding: Option<SharedString>,
|
||||
key_binding: Option<KeyBinding>,
|
||||
}
|
||||
|
||||
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<SharedString>) -> Self {
|
||||
self.keybinding = Some(keybinding.into());
|
||||
pub fn key_binding(mut self, key_binding: impl Into<Option<KeyBinding>>) -> 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))
|
||||
})
|
||||
|
|
|
@ -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")
|
||||
})
|
||||
}),
|
||||
|
|
Loading…
Reference in a new issue