deploy_feedback_button.rs

 1use gpui::{AnyElement, Render, ViewContext, WeakView};
 2use ui::{prelude::*, ButtonCommon, Icon, IconButton, Tooltip};
 3use workspace::{item::ItemHandle, StatusItemView, Workspace};
 4
 5use crate::feedback_editor::FeedbackEditor;
 6
 7pub struct DeployFeedbackButton {
 8    active: bool,
 9    workspace: WeakView<Workspace>,
10}
11
12impl DeployFeedbackButton {
13    pub fn new(workspace: &Workspace) -> Self {
14        DeployFeedbackButton {
15            active: false,
16            workspace: workspace.weak_handle(),
17        }
18    }
19}
20
21impl Render for DeployFeedbackButton {
22    type Element = AnyElement;
23
24    fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
25        let active = self.active;
26
27        IconButton::new("give-feedback", Icon::Envelope)
28            .style(ui::ButtonStyle::Subtle)
29            .tooltip(|cx| Tooltip::text("Give Feedback", cx))
30            .on_click(cx.listener(move |this, _, cx| {
31                let Some(workspace) = this.workspace.upgrade() else {
32                    return;
33                };
34
35                if !active {
36                    workspace.update(cx, |workspace, cx| FeedbackEditor::deploy(workspace, cx))
37                }
38            }))
39            .into_any_element()
40    }
41}
42
43impl StatusItemView for DeployFeedbackButton {
44    fn set_active_pane_item(&mut self, item: Option<&dyn ItemHandle>, cx: &mut ViewContext<Self>) {
45        if let Some(item) = item {
46            if let Some(_) = item.downcast::<FeedbackEditor>() {
47                self.active = true;
48                cx.notify();
49                return;
50            }
51        }
52        self.active = false;
53        cx.notify();
54    }
55}