2023-03-10 16:02:52 +00:00
|
|
|
use gpui::{elements::*, CursorStyle, Entity, MouseButton, RenderContext, View, ViewContext};
|
2023-02-11 06:50:05 +00:00
|
|
|
use settings::Settings;
|
|
|
|
use workspace::{item::ItemHandle, StatusItemView};
|
|
|
|
|
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-02-11 06:50:05 +00:00
|
|
|
|
|
|
|
impl Entity for DeployFeedbackButton {
|
|
|
|
type Event = ();
|
|
|
|
}
|
|
|
|
|
2023-03-11 00:19:33 +00:00
|
|
|
impl DeployFeedbackButton {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
DeployFeedbackButton { active: false }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-11 06:50:05 +00:00
|
|
|
impl View for DeployFeedbackButton {
|
|
|
|
fn ui_name() -> &'static str {
|
|
|
|
"DeployFeedbackButton"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn render(&mut self, cx: &mut RenderContext<'_, Self>) -> ElementBox {
|
2023-03-11 00:19:33 +00:00
|
|
|
let active = self.active;
|
2023-03-11 15:40:47 +00:00
|
|
|
let theme = cx.global::<Settings>().theme.clone();
|
2023-02-11 06:50:05 +00:00
|
|
|
Stack::new()
|
|
|
|
.with_child(
|
2023-03-11 15:40:47 +00:00
|
|
|
MouseEventHandler::<Self>::new(0, cx, |state, _| {
|
2023-03-11 00:19:33 +00:00
|
|
|
let style = &theme
|
|
|
|
.workspace
|
|
|
|
.status_bar
|
|
|
|
.sidebar_buttons
|
|
|
|
.item
|
|
|
|
.style_for(state, active);
|
|
|
|
|
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)
|
|
|
|
.boxed()
|
2023-02-11 06:50:05 +00:00
|
|
|
})
|
|
|
|
.with_cursor_style(CursorStyle::PointingHand)
|
2023-03-11 00:19:33 +00:00
|
|
|
.on_click(MouseButton::Left, move |_, cx| {
|
|
|
|
if !active {
|
|
|
|
cx.dispatch_action(GiveFeedback)
|
|
|
|
}
|
|
|
|
})
|
2023-03-11 15:40:47 +00:00
|
|
|
.with_tooltip::<Self, _>(
|
|
|
|
0,
|
2023-03-20 15:04:30 +00:00
|
|
|
"Send Feedback".into(),
|
2023-03-11 15:40:47 +00:00
|
|
|
Some(Box::new(GiveFeedback)),
|
|
|
|
theme.tooltip.clone(),
|
|
|
|
cx,
|
|
|
|
)
|
2023-02-11 06:50:05 +00:00
|
|
|
.boxed(),
|
|
|
|
)
|
|
|
|
.boxed()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|