| 1 | use gpui_kit::assets::IconName; |
| 2 | use gpui_kit::base::GlobalState; |
| 3 | use gpui_kit::component::h_flex; |
| 4 | use gpui_kit::*; |
| 5 | |
| 6 | use super::message_actions::{Action, HoverChange, bar_button}; |
| 7 | use super::widgets::icon; |
| 8 | use crate::theme; |
| 9 | |
| 10 | pub struct ScheduledMenu { |
| 11 | pub key: String, |
| 12 | pub edit: Action, |
| 13 | pub send_now: Action, |
| 14 | pub delete: Action, |
| 15 | pub hover: HoverChange, |
| 16 | } |
| 17 | |
| 18 | fn element_id(prefix: &str, key: &str) -> ElementId { |
| 19 | ElementId::Name(format!("{prefix}-{key}").into()) |
| 20 | } |
| 21 | |
| 22 | fn text_button(id: ElementId, label: &'static str) -> Stateful<Div> { |
| 23 | bar_button(id) |
| 24 | .w_auto() |
| 25 | .px(px(8.)) |
| 26 | .text_size(px(12.5)) |
| 27 | .text_color(theme::text_soft()) |
| 28 | .child(label) |
| 29 | } |
| 30 | |
| 31 | pub fn scheduled_toolbar(menu: ScheduledMenu) -> AnyElement { |
| 32 | let ScheduledMenu { |
| 33 | key, |
| 34 | edit, |
| 35 | send_now, |
| 36 | delete, |
| 37 | hover, |
| 38 | } = menu; |
| 39 | h_flex() |
| 40 | .id(element_id("scheduled-toolbar", &key)) |
| 41 | .p(px(2.)) |
| 42 | .gap(px(2.)) |
| 43 | .items_center() |
| 44 | .rounded(px(8.)) |
| 45 | .bg(theme::surface()) |
| 46 | .border_1() |
| 47 | .border_color(theme::border_strong()) |
| 48 | .occlude() |
| 49 | .on_hover(move |hovered, _, cx| hover(*hovered, cx)) |
| 50 | .on_mouse_down(MouseButton::Left, |_, _, cx| { |
| 51 | GlobalState::suppress_text_selection(cx) |
| 52 | }) |
| 53 | .child( |
| 54 | text_button(element_id("scheduled-edit", &key), "Edit").on_click( |
| 55 | move |_, window, cx| { |
| 56 | cx.stop_propagation(); |
| 57 | edit(window, cx); |
| 58 | }, |
| 59 | ), |
| 60 | ) |
| 61 | .child( |
| 62 | text_button(element_id("scheduled-send-now", &key), "Send now").on_click( |
| 63 | move |_, window, cx| { |
| 64 | cx.stop_propagation(); |
| 65 | send_now(window, cx); |
| 66 | }, |
| 67 | ), |
| 68 | ) |
| 69 | .child( |
| 70 | bar_button(element_id("scheduled-delete", &key)) |
| 71 | .child(icon(IconName::Trash, 16., theme::red_soft())) |
| 72 | .on_click(move |_, window, cx| { |
| 73 | cx.stop_propagation(); |
| 74 | delete(window, cx); |
| 75 | }), |
| 76 | ) |
| 77 | .into_any_element() |
| 78 | } |