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