1// use crate::{feedback_editor::SubmitFeedback, feedback_modal::FeedbackModal};
2// use anyhow::Result;
3// use gpui::{AppContext, Render, Task, View, ViewContext};
4// use ui::IconButton;
5// use workspace::{item::ItemHandle, ToolbarItemLocation, ToolbarItemView};
6
7// pub fn init(cx: &mut AppContext) {
8// cx.add_async_action(SubmitFeedbackButton::submit);
9// }
10
11// pub struct SubmitFeedbackButton {
12// pub(crate) active_item: Option<View<FeedbackModal>>,
13// }
14
15// impl SubmitFeedbackButton {
16// pub fn new() -> Self {
17// Self {
18// active_item: Default::default(),
19// }
20// }
21
22// pub fn submit(
23// &mut self,
24// _: &SubmitFeedback,
25// cx: &mut ViewContext<Self>,
26// ) -> Option<Task<Result<()>>> {
27// if let Some(active_item) = self.active_item.as_ref() {
28// Some(active_item.update(cx, |feedback_editor, cx| feedback_editor.submit(cx)))
29// } else {
30// None
31// }
32// }
33// }
34
35// impl Render for SubmitFeedbackbutton {
36// type Element;
37
38// fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
39// todo!();
40// // IconButton::new("give-feedback", Icon::Envelope)
41// // .style(ui::ButtonStyle::Subtle)
42// // .on_click(|_, cx| cx.dispatch_action(GiveFeedback))
43// }
44// }
45
46// // impl View for SubmitFeedbackButton {
47// // fn ui_name() -> &'static str {
48// // "SubmitFeedbackButton"
49// // }
50
51// // fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
52// // let theme = theme::current(cx).clone();
53// // let allow_submission = self
54// // .active_item
55// // .as_ref()
56// // .map_or(true, |i| i.read(cx).allow_submission);
57
58// // enum SubmitFeedbackButton {}
59// // MouseEventHandler::new::<SubmitFeedbackButton, _>(0, cx, |state, _| {
60// // let text;
61// // let style = if allow_submission {
62// // text = "Submit as Markdown";
63// // theme.feedback.submit_button.style_for(state)
64// // } else {
65// // text = "Submitting...";
66// // theme
67// // .feedback
68// // .submit_button
69// // .disabled
70// // .as_ref()
71// // .unwrap_or(&theme.feedback.submit_button.default)
72// // };
73
74// // Label::new(text, style.text.clone())
75// // .contained()
76// // .with_style(style.container)
77// // })
78// // .with_cursor_style(CursorStyle::PointingHand)
79// // .on_click(MouseButton::Left, |_, this, cx| {
80// // this.submit(&Default::default(), cx);
81// // })
82// // .aligned()
83// // .contained()
84// // .with_margin_left(theme.feedback.button_margin)
85// // .with_tooltip::<Self>(
86// // 0,
87// // "cmd-s",
88// // Some(Box::new(SubmitFeedback)),
89// // theme.tooltip.clone(),
90// // cx,
91// // )
92// // .into_any()
93// // }
94// // }
95
96// impl ToolbarItemView for SubmitFeedbackButton {
97// fn set_active_pane_item(
98// &mut self,
99// active_pane_item: Option<&dyn ItemHandle>,
100// cx: &mut ViewContext<Self>,
101// ) -> workspace::ToolbarItemLocation {
102// cx.notify();
103// if let Some(feedback_editor) = active_pane_item.and_then(|i| i.downcast::<FeedbackEditor>())
104// {
105// self.active_item = Some(feedback_editor);
106// ToolbarItemLocation::PrimaryRight { flex: None }
107// } else {
108// self.active_item = None;
109// ToolbarItemLocation::Hidden
110// }
111// }
112// }