feedback_info_text.rs

 1use gpui::{
 2    elements::{Flex, Label, MouseEventHandler, ParentElement, Text},
 3    platform::{CursorStyle, MouseButton},
 4    AnyElement, Element, Entity, View, ViewContext, ViewHandle,
 5};
 6use workspace::{item::ItemHandle, ToolbarItemLocation, ToolbarItemView};
 7
 8use crate::{feedback_editor::FeedbackEditor, open_zed_community_repo, OpenZedCommunityRepo};
 9
10pub struct FeedbackInfoText {
11    active_item: Option<ViewHandle<FeedbackEditor>>,
12}
13
14impl FeedbackInfoText {
15    pub fn new() -> Self {
16        Self {
17            active_item: Default::default(),
18        }
19    }
20}
21
22impl Entity for FeedbackInfoText {
23    type Event = ();
24}
25
26impl View for FeedbackInfoText {
27    fn ui_name() -> &'static str {
28        "FeedbackInfoText"
29    }
30
31    fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
32        let theme = theme::current(cx).clone();
33
34        Flex::row()
35            .with_child(
36                Text::new(
37                    "Share your feedback. Include your email for replies. For issues and discussions, visit the ",
38                    theme.feedback.info_text_default.text.clone(),
39                )
40                .with_soft_wrap(false)
41                .aligned(),
42            )
43            .with_child(
44                MouseEventHandler::new::<OpenZedCommunityRepo, _>(0, cx, |state, _| {
45                    let contained_text = if state.hovered() {
46                        &theme.feedback.link_text_hover
47                    } else {
48                        &theme.feedback.link_text_default
49                    };
50
51                    Label::new("community repo", contained_text.text.clone())
52                        .contained()
53                        .aligned()
54                        .left()
55                        .clipped()
56                })
57                .with_cursor_style(CursorStyle::PointingHand)
58                .on_click(MouseButton::Left, |_, _, cx| {
59                    open_zed_community_repo(&Default::default(), cx)
60                }),
61            )
62            .with_child(
63                Text::new(".", theme.feedback.info_text_default.text.clone())
64                    .with_soft_wrap(false)
65                    .aligned(),
66            )
67            .aligned()
68            .left()
69            .clipped()
70            .into_any()
71    }
72}
73
74impl ToolbarItemView for FeedbackInfoText {
75    fn set_active_pane_item(
76        &mut self,
77        active_pane_item: Option<&dyn ItemHandle>,
78        cx: &mut ViewContext<Self>,
79    ) -> workspace::ToolbarItemLocation {
80        cx.notify();
81        if let Some(feedback_editor) = active_pane_item.and_then(|i| i.downcast::<FeedbackEditor>())
82        {
83            self.active_item = Some(feedback_editor);
84            ToolbarItemLocation::PrimaryLeft {
85                flex: Some((1., false)),
86            }
87        } else {
88            self.active_item = None;
89            ToolbarItemLocation::Hidden
90        }
91    }
92}