zed/crates/feedback/src/deploy_feedback_button.rs

91 lines
2.8 KiB
Rust
Raw Normal View History

use gpui::{
elements::*,
platform::{CursorStyle, MouseButton},
2023-05-01 13:48:41 +00:00
Entity, View, ViewContext, WeakViewHandle,
};
2023-05-01 13:48:41 +00:00
use workspace::{item::ItemHandle, StatusItemView, Workspace};
use crate::feedback_editor::{FeedbackEditor, GiveFeedback};
pub struct DeployFeedbackButton {
active: bool,
2023-05-01 13:48:41 +00:00
workspace: WeakViewHandle<Workspace>,
}
impl Entity for DeployFeedbackButton {
type Event = ();
}
impl DeployFeedbackButton {
2023-05-01 13:48:41 +00:00
pub fn new(workspace: &Workspace) -> Self {
DeployFeedbackButton {
active: false,
workspace: workspace.weak_handle(),
}
}
}
impl View for DeployFeedbackButton {
fn ui_name() -> &'static str {
"DeployFeedbackButton"
}
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
let active = self.active;
let theme = theme::current(cx).clone();
Stack::new()
.with_child(
2023-04-12 16:07:17 +00:00
MouseEventHandler::<Self, Self>::new(0, cx, |state, _| {
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
.style_for(state, active);
Svg::new("icons/feedback_16.svg")
.with_color(style.icon_color)
.constrained()
.with_width(style.icon_size)
.aligned()
.constrained()
.with_width(style.icon_size)
.with_height(style.icon_size)
.contained()
.with_style(style.container)
})
.with_cursor_style(CursorStyle::PointingHand)
2023-05-01 13:48:41 +00:00
.on_click(MouseButton::Left, move |_, this, cx| {
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-04-12 16:07:17 +00:00
.with_tooltip::<Self>(
2023-03-11 15:40:47 +00:00
0,
"Send Feedback".into(),
2023-03-11 15:40:47 +00:00
Some(Box::new(GiveFeedback)),
theme.tooltip.clone(),
cx,
),
)
.into_any()
}
}
impl StatusItemView for DeployFeedbackButton {
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();
}
}