Files
oak-gpui/crates/feedback2/src/deploy_feedback_button.rs
T
Joseph T. Lyons 78e1c0f9c3 Implement feedback actions
CopySystemSpecsIntoClipboard
RequestFeature
FileBugReport
2023-12-05 15:48:41 -05:00

59 lines
1.7 KiB
Rust

use gpui::{AnyElement, Render, ViewContext, WeakView};
use ui::{prelude::*, ButtonCommon, Icon, IconButton, Tooltip};
use workspace::{StatusItemView, Workspace};
use crate::feedback_modal::FeedbackModal;
pub struct DeployFeedbackButton {
_active: bool,
workspace: WeakView<Workspace>,
}
impl DeployFeedbackButton {
pub fn new(workspace: &Workspace) -> Self {
DeployFeedbackButton {
_active: false,
workspace: workspace.weak_handle(),
}
}
}
impl Render for DeployFeedbackButton {
type Element = AnyElement;
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
let is_open = self
.workspace
.upgrade()
.and_then(|workspace| {
workspace.update(cx, |workspace, cx| {
workspace.active_modal::<FeedbackModal>(cx)
})
})
.is_some();
IconButton::new("give-feedback", Icon::Envelope)
.style(ui::ButtonStyle::Subtle)
.selected(is_open)
.tooltip(|cx| Tooltip::text("Give Feedback", cx))
.on_click(cx.listener(|this, _, cx| {
let Some(workspace) = this.workspace.upgrade() else {
return;
};
workspace.update(cx, |workspace, cx| {
workspace.toggle_modal(cx, |cx| FeedbackModal::new(cx))
})
}))
.into_any_element()
}
}
impl StatusItemView for DeployFeedbackButton {
fn set_active_pane_item(
&mut self,
_active_pane_item: Option<&dyn workspace::item::ItemHandle>,
_cx: &mut ViewContext<Self>,
) {
// no-op
}
}