diff --git a/crates/zed/src/zed/linux_prompts.rs b/crates/zed/src/zed/linux_prompts.rs index ee267e775681493ce31d4109bad89363408337bb..3a8065d931cfb262528129a24c108af3cc850aec 100644 --- a/crates/zed/src/zed/linux_prompts.rs +++ b/crates/zed/src/zed/linux_prompts.rs @@ -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,44 +43,59 @@ pub struct FallbackPromptRenderer { actions: Vec, focus: FocusHandle, } +impl FallbackPromptRenderer { + fn confirm(&mut self, _: &menu::Confirm, cx: &mut ViewContext) { + cx.emit(PromptResponse(0)); + } + fn cancel(&mut self, _: &menu::Cancel, cx: &mut ViewContext) { + 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) -> impl IntoElement { - let prompt = - v_flex() - .cursor_default() - .track_focus(&self.focus) - .elevation_3(cx) - .w_72() - .overflow_hidden() - .p_4() - .gap_4() - .font_family("Zed Sans") - .child( - div() - .w_full() - .font_weight(FontWeight::BOLD) - .child(self.message.clone()) - .text_color(ui::Color::Default.color(cx)), - ) - .children(self.detail.clone().map(|detail| { - div() - .w_full() - .text_xs() - .text_color(ui::Color::Muted.color(cx)) - .child(detail) - })) - .child(h_flex().justify_end().gap_2().children( - self.actions.iter().enumerate().map(|(ix, action)| { - ui::Button::new(ix, action.clone()) - .label_size(LabelSize::Large) - .style(ButtonStyle::Filled) - .layer(ElevationIndex::ModalSurface) - .on_click(cx.listener(move |_, _, cx| { - cx.emit(PromptResponse(ix)); - })) - }), - )); + 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() + .p_4() + .gap_4() + .font_family("Zed Sans") + .child( + div() + .w_full() + .font_weight(FontWeight::BOLD) + .child(self.message.clone()) + .text_color(ui::Color::Default.color(cx)), + ) + .children(self.detail.clone().map(|detail| { + div() + .w_full() + .text_xs() + .text_color(ui::Color::Muted.color(cx)) + .child(detail) + })) + .child(h_flex().justify_end().gap_2().children( + 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)); + })) + }), + )); div() .size_full()