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,
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;
pub fn init(cx: &mut AppContext) {
@ -40,13 +43,25 @@ pub struct FallbackPromptRenderer {
actions: Vec<String>,
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 {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
let prompt =
v_flex()
let prompt = v_flex()
.key_context("Prompt")
.cursor_default()
.track_focus(&self.focus)
.on_action(cx.listener(Self::confirm))
.on_action(cx.listener(Self::cancel))
.elevation_3(cx)
.w_72()
.overflow_hidden()
@ -68,10 +83,13 @@ impl Render for FallbackPromptRenderer {
.child(detail)
}))
.child(h_flex().justify_end().gap_2().children(
self.actions.iter().enumerate().map(|(ix, action)| {
self.actions.iter().enumerate().rev().map(|(ix, action)| {
ui::Button::new(ix, action.clone())
.label_size(LabelSize::Large)
.style(ButtonStyle::Filled)
.when(ix == 0, |el| {
el.style(ButtonStyle::Tinted(TintColor::Accent))
})
.layer(ElevationIndex::ModalSurface)
.on_click(cx.listener(move |_, _, cx| {
cx.emit(PromptResponse(ix));