Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Hook up buttons in NotificationToast
Nate Butler7ba305e033c3
diff --git a/crates/ui2/src/components/notification.rs b/crates/ui2/src/components/notification.rsindex 31e7af410f5..424358efb21 100644--- a/crates/ui2/src/components/notification.rs+++ b/crates/ui2/src/components/notification.rs@@ -3,12 +3,14 @@ use std::marker::PhantomData;use gpui3::{Element, ParentElement, StyleHelpers, ViewContext};use crate::{- h_stack, v_stack, Icon, IconButton, IconElement, Label, ThemeColor, Toast, ToastOrigin,+ h_stack, v_stack, Button, Icon, IconButton, IconElement, Label, ThemeColor, Toast, ToastOrigin,};/// Notification toasts are used to display a message/// that requires them to take action.///+/// You must provide a primary action for the user to take.+////// To simply convey information, use a Status.#[derive(Element)]pub struct NotificationToast<S: 'static + Send + Sync + Clone> {@@ -16,47 +18,39 @@ pub struct NotificationToast<S: 'static + Send + Sync + Clone> {left_icon: Option<Icon>,title: String,message: String,- // primary_action: Button<S>,- // secondary_action: Option<Button<S>>,+ primary_action: Option<Button<S>>,+ secondary_action: Option<Button<S>>,}impl<S: 'static + Send + Sync + Clone> NotificationToast<S> {pub fn new(title: impl Into<String>,message: impl Into<String>,- // primary_action: Button<S>,+ primary_action: Button<S>,) -> Self {Self {state_type: PhantomData,left_icon: None,title: title.into(),message: message.into(),- // primary_action,- // secondary_action: None,+ primary_action: Some(primary_action),+ secondary_action: None,}}- pub fn set_left_icon(mut self, icon: Icon) -> Self {+ pub fn left_icon(mut self, icon: Icon) -> Self {self.left_icon = Some(icon);self}- // pub fn set_secondary_action(mut self, action: Button<S>) -> Self {- // self.secondary_action = Some(action);- // self- // }+ pub fn secondary_action(mut self, action: Button<S>) -> Self {+ self.secondary_action = Some(action);+ self+ }fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {let color = ThemeColor::new(cx);- // TODO: Fix me-- // let secondary_action = if self.secondary_action.is_some() {- // div().child(Some(self.secondary_action))- // } else {- // div()- // };-let notification = h_stack().gap_1().items_start()@@ -78,8 +72,8 @@ impl<S: 'static + Send + Sync + Clone> NotificationToast<S> {h_stack().gap_1().justify_end()- .child(Label::new("Secondary").color(crate::LabelColor::Muted))- .child(Label::new("Primary")),+ .children(self.secondary_action.take())+ .children(self.primary_action.take()),),),);diff --git a/crates/ui2/src/components/toast.rs b/crates/ui2/src/components/toast.rsindex 81651ddf168..3290f458a52 100644--- a/crates/ui2/src/components/toast.rs+++ b/crates/ui2/src/components/toast.rs@@ -48,10 +48,10 @@ impl<S: 'static + Send + Sync> Toast<S> {.flex().py_2().px_1p5()- .min_w_40()+ .min_w_64().rounded_md().fill(color.elevated_surface)- .max_w_64()+ .max_w_96().children(self.children.drain(..))}}diff --git a/crates/ui2/src/components/workspace.rs b/crates/ui2/src/components/workspace.rsindex 9cdbb4683f8..bcd7d406732 100644--- a/crates/ui2/src/components/workspace.rs+++ b/crates/ui2/src/components/workspace.rs@@ -3,9 +3,9 @@ use gpui3::{px, relative, rems, view, Context, Size, View};use crate::{hello_world_rust_editor_with_status_example, random_players_with_call_status, theme, v_stack,- AssistantPanel, ChatMessage, ChatPanel, CollabPanel, EditorPane, Label, LanguageSelector,- Livestream, Pane, PaneGroup, Panel, PanelAllowedSides, PanelSide, ProjectPanel, SplitDirection,- StatusBar, Terminal, TitleBar, Toast, ToastOrigin,+ AssistantPanel, Button, ChatMessage, ChatPanel, CollabPanel, EditorPane, Label,+ LanguageSelector, Livestream, Pane, PaneGroup, Panel, PanelAllowedSides, PanelSide,+ ProjectPanel, SplitDirection, StatusBar, Terminal, TitleBar, Toast, ToastOrigin,};use crate::{prelude::*, NotificationToast};@@ -270,6 +270,7 @@ impl Workspace {.child(NotificationToast::new("A notification","This is a notification",+ Button::new("Primary"),))}}