1use gpui::{AnyElement, Render, ViewContext, WeakView};
2use ui::{prelude::*, ButtonCommon, Icon, IconButton, Tooltip};
3use workspace::{item::ItemHandle, StatusItemView, Workspace};
4
5use crate::{feedback_editor::GiveFeedback, 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 IconButton::new("give-feedback", Icon::Envelope)
35 .style(ui::ButtonStyle::Subtle)
36 .selected(is_open)
37 .tooltip(|cx| Tooltip::text("Give Feedback", cx))
38 .on_click(|_, cx| {
39 cx.dispatch_action(Box::new(GiveFeedback));
40 })
41 .into_any_element()
42 }
43}
44
45impl StatusItemView for DeployFeedbackButton {
46 fn set_active_pane_item(
47 &mut self,
48 _item: Option<&dyn ItemHandle>,
49 _cx: &mut ViewContext<Self>,
50 ) {
51 // no-op
52 }
53}