Keyboardable buttons in linux alerts (#13235)

Release Notes:

- N/A
This commit is contained in:
Conrad Irwin 2024-06-18 14:58:10 -06:00 committed by GitHub
parent 5cbb360952
commit ca18549e02
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,7 +3,10 @@ use gpui::{
InteractiveElement, IntoElement, ParentElement, PromptHandle, PromptLevel, PromptResponse, InteractiveElement, IntoElement, ParentElement, PromptHandle, PromptLevel, PromptResponse,
Render, RenderablePromptHandle, Styled, ViewContext, VisualContext, WindowContext, Render, RenderablePromptHandle, Styled, ViewContext, VisualContext, WindowContext,
}; };
use ui::{h_flex, v_flex, ButtonCommon, ButtonStyle, Clickable, ElevationIndex, LabelSize}; use ui::{
h_flex, v_flex, ButtonCommon, ButtonStyle, Clickable, ElevationIndex, FluentBuilder, LabelSize,
TintColor,
};
use workspace::ui::StyledExt; use workspace::ui::StyledExt;
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
@ -40,44 +43,59 @@ pub struct FallbackPromptRenderer {
actions: Vec<String>, actions: Vec<String>,
focus: FocusHandle, focus: FocusHandle,
} }
impl FallbackPromptRenderer {
fn confirm(&mut self, _: &menu::Confirm, cx: &mut ViewContext<Self>) {
cx.emit(PromptResponse(0));
}
fn cancel(&mut self, _: &menu::Cancel, cx: &mut ViewContext<Self>) {
if let Some(ix) = self.actions.iter().position(|a| a == "Cancel") {
cx.emit(PromptResponse(ix));
}
}
}
impl Render for FallbackPromptRenderer { impl Render for FallbackPromptRenderer {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement { fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
let prompt = let prompt = v_flex()
v_flex() .key_context("Prompt")
.cursor_default() .cursor_default()
.track_focus(&self.focus) .track_focus(&self.focus)
.elevation_3(cx) .on_action(cx.listener(Self::confirm))
.w_72() .on_action(cx.listener(Self::cancel))
.overflow_hidden() .elevation_3(cx)
.p_4() .w_72()
.gap_4() .overflow_hidden()
.font_family("Zed Sans") .p_4()
.child( .gap_4()
div() .font_family("Zed Sans")
.w_full() .child(
.font_weight(FontWeight::BOLD) div()
.child(self.message.clone()) .w_full()
.text_color(ui::Color::Default.color(cx)), .font_weight(FontWeight::BOLD)
) .child(self.message.clone())
.children(self.detail.clone().map(|detail| { .text_color(ui::Color::Default.color(cx)),
div() )
.w_full() .children(self.detail.clone().map(|detail| {
.text_xs() div()
.text_color(ui::Color::Muted.color(cx)) .w_full()
.child(detail) .text_xs()
})) .text_color(ui::Color::Muted.color(cx))
.child(h_flex().justify_end().gap_2().children( .child(detail)
self.actions.iter().enumerate().map(|(ix, action)| { }))
ui::Button::new(ix, action.clone()) .child(h_flex().justify_end().gap_2().children(
.label_size(LabelSize::Large) self.actions.iter().enumerate().rev().map(|(ix, action)| {
.style(ButtonStyle::Filled) ui::Button::new(ix, action.clone())
.layer(ElevationIndex::ModalSurface) .label_size(LabelSize::Large)
.on_click(cx.listener(move |_, _, cx| { .style(ButtonStyle::Filled)
cx.emit(PromptResponse(ix)); .when(ix == 0, |el| {
})) el.style(ButtonStyle::Tinted(TintColor::Accent))
}), })
)); .layer(ElevationIndex::ModalSurface)
.on_click(cx.listener(move |_, _, cx| {
cx.emit(PromptResponse(ix));
}))
}),
));
div() div()
.size_full() .size_full()