1use gpui::{
2 elements::{Flex, Label, MouseEventHandler, ParentElement, Text},
3 CursorStyle, Element, ElementBox, Entity, MouseButton, RenderContext, View, ViewContext,
4 ViewHandle,
5};
6use settings::Settings;
7use workspace::{item::ItemHandle, ToolbarItemLocation, ToolbarItemView};
8
9use crate::{feedback_editor::FeedbackEditor, 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 RenderContext<Self>) -> ElementBox {
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 .boxed(),
44 )
45 .with_child(
46 MouseEventHandler::<OpenZedCommunityRepo>::new(0, cx, |state, _| {
47 let contained_text = if state.hovered() {
48 &theme.feedback.link_text_hover
49 } else {
50 &theme.feedback.link_text_default
51 };
52
53 Label::new("community repo", contained_text.text.clone())
54 .contained()
55 .aligned()
56 .left()
57 .clipped()
58 .boxed()
59 })
60 .with_cursor_style(CursorStyle::PointingHand)
61 .on_click(MouseButton::Left, |_, cx| {
62 cx.dispatch_action(OpenZedCommunityRepo)
63 })
64 .boxed(),
65 )
66 .with_child(
67 Text::new(" on GitHub.", theme.feedback.info_text_default.text.clone())
68 .with_soft_wrap(false)
69 .aligned()
70 .boxed(),
71 )
72 .aligned()
73 .left()
74 .clipped()
75 .boxed()
76 }
77}
78
79impl ToolbarItemView for FeedbackInfoText {
80 fn set_active_pane_item(
81 &mut self,
82 active_pane_item: Option<&dyn ItemHandle>,
83 cx: &mut ViewContext<Self>,
84 ) -> workspace::ToolbarItemLocation {
85 cx.notify();
86 if let Some(feedback_editor) = active_pane_item.and_then(|i| i.downcast::<FeedbackEditor>())
87 {
88 self.active_item = Some(feedback_editor);
89 ToolbarItemLocation::PrimaryLeft {
90 flex: Some((1., false)),
91 }
92 } else {
93 self.active_item = None;
94 ToolbarItemLocation::Hidden
95 }
96 }
97}