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>) -> AnyElement<Self> {
31 let active = self.active;
32 let theme = cx.global::<Settings>().theme.clone();
33 Stack::new()
34 .with_child(
35 MouseEventHandler::<Self, 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 })
54 .with_cursor_style(CursorStyle::PointingHand)
55 .on_click(MouseButton::Left, move |_, _, cx| {
56 if !active {
57 cx.dispatch_action(GiveFeedback)
58 }
59 })
60 .with_tooltip::<Self>(
61 0,
62 "Send Feedback".into(),
63 Some(Box::new(GiveFeedback)),
64 theme.tooltip.clone(),
65 cx,
66 ),
67 )
68 .into_any()
69 }
70}
71
72impl StatusItemView for DeployFeedbackButton {
73 fn set_active_pane_item(&mut self, item: Option<&dyn ItemHandle>, cx: &mut ViewContext<Self>) {
74 if let Some(item) = item {
75 if let Some(_) = item.downcast::<FeedbackEditor>() {
76 self.active = true;
77 cx.notify();
78 return;
79 }
80 }
81 self.active = false;
82 cx.notify();
83 }
84}