1use gpui::{AnyElement, Render, ViewContext, WeakView};
2use ui::{prelude::*, ButtonCommon, Icon, IconButton, Tooltip};
3use workspace::{StatusItemView, Workspace};
4
5use crate::feedback_modal::FeedbackModal;
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 is_open = self
26 .workspace
27 .upgrade()
28 .and_then(|workspace| {
29 workspace.update(cx, |workspace, cx| {
30 workspace.active_modal::<FeedbackModal>(cx)
31 })
32 })
33 .is_some();
34
35 IconButton::new("give-feedback", Icon::Envelope)
36 .style(ui::ButtonStyle::Subtle)
37 .selected(is_open)
38 .tooltip(|cx| Tooltip::text("Give Feedback", cx))
39 .on_click(cx.listener(|this, _, cx| {
40 let Some(workspace) = this.workspace.upgrade() else {
41 return;
42 };
43 workspace.update(cx, |workspace, cx| {
44 workspace.toggle_modal(cx, |cx| FeedbackModal::new(cx))
45 })
46 }))
47 .into_any_element()
48 }
49}
50impl StatusItemView for DeployFeedbackButton {
51 fn set_active_pane_item(
52 &mut self,
53 _active_pane_item: Option<&dyn workspace::item::ItemHandle>,
54 _cx: &mut ViewContext<Self>,
55 ) {
56 // no-op
57 }
58}