2023-04-07 17:41:39 +00:00
|
|
|
use gpui::{
|
|
|
|
elements::*,
|
|
|
|
platform::{CursorStyle, MouseButton},
|
2023-05-01 13:48:41 +00:00
|
|
|
Entity, View, ViewContext, WeakViewHandle,
|
2023-04-07 17:41:39 +00:00
|
|
|
};
|
2023-05-01 13:48:41 +00:00
|
|
|
use workspace::{item::ItemHandle, StatusItemView, Workspace};
|
2023-02-11 06:50:05 +00:00
|
|
|
|
2023-03-11 00:19:33 +00:00
|
|
|
use crate::feedback_editor::{FeedbackEditor, GiveFeedback};
|
2023-02-11 06:50:05 +00:00
|
|
|
|
2023-03-11 00:19:33 +00:00
|
|
|
pub struct DeployFeedbackButton {
|
|
|
|
active: bool,
|
2023-05-01 13:48:41 +00:00
|
|
|
workspace: WeakViewHandle<Workspace>,
|
2023-03-11 00:19:33 +00:00
|
|
|
}
|
2023-02-11 06:50:05 +00:00
|
|
|
|
|
|
|
impl Entity for DeployFeedbackButton {
|
|
|
|
type Event = ();
|
|
|
|
}
|
|
|
|
|
2023-03-11 00:19:33 +00:00
|
|
|
impl DeployFeedbackButton {
|
2023-05-01 13:48:41 +00:00
|
|
|
pub fn new(workspace: &Workspace) -> Self {
|
|
|
|
DeployFeedbackButton {
|
|
|
|
active: false,
|
|
|
|
workspace: workspace.weak_handle(),
|
|
|
|
}
|
2023-03-11 00:19:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-11 06:50:05 +00:00
|
|
|
impl View for DeployFeedbackButton {
|
|
|
|
fn ui_name() -> &'static str {
|
|
|
|
"DeployFeedbackButton"
|
|
|
|
}
|
|
|
|
|
2023-04-21 19:04:03 +00:00
|
|
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
|
2023-03-11 00:19:33 +00:00
|
|
|
let active = self.active;
|
2023-05-17 21:44:55 +00:00
|
|
|
let theme = theme::current(cx).clone();
|
2023-02-11 06:50:05 +00:00
|
|
|
Stack::new()
|
|
|
|
.with_child(
|
2023-04-12 16:07:17 +00:00
|
|
|
MouseEventHandler::<Self, Self>::new(0, cx, |state, _| {
|
2023-03-11 00:19:33 +00:00
|
|
|
let style = &theme
|
|
|
|
.workspace
|
|
|
|
.status_bar
|
2023-05-05 22:04:36 +00:00
|
|
|
.panel_buttons
|
2023-05-05 22:13:36 +00:00
|
|
|
.button
|
2023-06-14 12:02:32 +00:00
|
|
|
.in_state(active)
|
|
|
|
.style_for(state);
|
2023-03-11 00:19:33 +00:00
|
|
|
|
2023-03-20 15:04:30 +00:00
|
|
|
Svg::new("icons/feedback_16.svg")
|
2023-03-11 00:19:33 +00:00
|
|
|
.with_color(style.icon_color)
|
2023-03-10 16:02:52 +00:00
|
|
|
.constrained()
|
2023-03-11 00:19:33 +00:00
|
|
|
.with_width(style.icon_size)
|
2023-03-10 16:02:52 +00:00
|
|
|
.aligned()
|
|
|
|
.constrained()
|
2023-03-11 00:19:33 +00:00
|
|
|
.with_width(style.icon_size)
|
|
|
|
.with_height(style.icon_size)
|
2023-03-10 16:02:52 +00:00
|
|
|
.contained()
|
|
|
|
.with_style(style.container)
|
2023-02-11 06:50:05 +00:00
|
|
|
})
|
|
|
|
.with_cursor_style(CursorStyle::PointingHand)
|
2023-05-01 13:48:41 +00:00
|
|
|
.on_click(MouseButton::Left, move |_, this, cx| {
|
2023-03-11 00:19:33 +00:00
|
|
|
if !active {
|
2023-05-01 13:48:41 +00:00
|
|
|
if let Some(workspace) = this.workspace.upgrade(cx) {
|
|
|
|
workspace
|
|
|
|
.update(cx, |workspace, cx| FeedbackEditor::deploy(workspace, cx))
|
|
|
|
}
|
2023-03-11 00:19:33 +00:00
|
|
|
}
|
|
|
|
})
|
2023-04-12 16:07:17 +00:00
|
|
|
.with_tooltip::<Self>(
|
2023-03-11 15:40:47 +00:00
|
|
|
0,
|
2023-08-11 13:29:55 +00:00
|
|
|
"Send Feedback",
|
2023-03-11 15:40:47 +00:00
|
|
|
Some(Box::new(GiveFeedback)),
|
|
|
|
theme.tooltip.clone(),
|
|
|
|
cx,
|
2023-04-21 16:36:21 +00:00
|
|
|
),
|
2023-02-11 06:50:05 +00:00
|
|
|
)
|
2023-04-21 19:04:03 +00:00
|
|
|
.into_any()
|
2023-02-11 06:50:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl StatusItemView for DeployFeedbackButton {
|
2023-03-11 00:19:33 +00:00
|
|
|
fn set_active_pane_item(&mut self, item: Option<&dyn ItemHandle>, cx: &mut ViewContext<Self>) {
|
|
|
|
if let Some(item) = item {
|
|
|
|
if let Some(_) = item.downcast::<FeedbackEditor>() {
|
|
|
|
self.active = true;
|
|
|
|
cx.notify();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.active = false;
|
|
|
|
cx.notify();
|
|
|
|
}
|
2023-02-11 06:50:05 +00:00
|
|
|
}
|