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