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