deploy_feedback_button.rs

 1use gpui::{
 2    elements::*,
 3    platform::{CursorStyle, MouseButton},
 4    Entity, View, ViewContext,
 5};
 6use settings::Settings;
 7use workspace::{item::ItemHandle, StatusItemView};
 8
 9use crate::feedback_editor::{FeedbackEditor, GiveFeedback};
10
11pub struct DeployFeedbackButton {
12    active: bool,
13}
14
15impl Entity for DeployFeedbackButton {
16    type Event = ();
17}
18
19impl DeployFeedbackButton {
20    pub fn new() -> Self {
21        DeployFeedbackButton { active: false }
22    }
23}
24
25impl View for DeployFeedbackButton {
26    fn ui_name() -> &'static str {
27        "DeployFeedbackButton"
28    }
29
30    fn render(&mut self, cx: &mut ViewContext<Self>) -> ElementBox<Self> {
31        let active = self.active;
32        let theme = cx.global::<Settings>().theme.clone();
33        Stack::new()
34            .with_child(
35                MouseEventHandler::<Self>::new(0, cx, |state, _| {
36                    let style = &theme
37                        .workspace
38                        .status_bar
39                        .sidebar_buttons
40                        .item
41                        .style_for(state, active);
42
43                    Svg::new("icons/feedback_16.svg")
44                        .with_color(style.icon_color)
45                        .constrained()
46                        .with_width(style.icon_size)
47                        .aligned()
48                        .constrained()
49                        .with_width(style.icon_size)
50                        .with_height(style.icon_size)
51                        .contained()
52                        .with_style(style.container)
53                        .boxed()
54                })
55                .with_cursor_style(CursorStyle::PointingHand)
56                .on_click(MouseButton::Left, move |_, cx| {
57                    if !active {
58                        cx.dispatch_action(GiveFeedback)
59                    }
60                })
61                .with_tooltip::<Self, _>(
62                    0,
63                    "Send Feedback".into(),
64                    Some(Box::new(GiveFeedback)),
65                    theme.tooltip.clone(),
66                    cx,
67                )
68                .boxed(),
69            )
70            .boxed()
71    }
72}
73
74impl StatusItemView for DeployFeedbackButton {
75    fn set_active_pane_item(&mut self, item: Option<&dyn ItemHandle>, cx: &mut ViewContext<Self>) {
76        if let Some(item) = item {
77            if let Some(_) = item.downcast::<FeedbackEditor>() {
78                self.active = true;
79                cx.notify();
80                return;
81            }
82        }
83        self.active = false;
84        cx.notify();
85    }
86}