feedback_info_text.rs

 1use gpui::{
 2    elements::Label, Element, ElementBox, Entity, RenderContext, View, ViewContext, ViewHandle,
 3};
 4use settings::Settings;
 5use workspace::{item::ItemHandle, ToolbarItemLocation, ToolbarItemView};
 6
 7use crate::feedback_editor::FeedbackEditor;
 8
 9pub struct FeedbackInfoText {
10    active_item: Option<ViewHandle<FeedbackEditor>>,
11}
12
13impl FeedbackInfoText {
14    pub fn new() -> Self {
15        Self {
16            active_item: Default::default(),
17        }
18    }
19}
20
21impl Entity for FeedbackInfoText {
22    type Event = ();
23}
24
25impl View for FeedbackInfoText {
26    fn ui_name() -> &'static str {
27        "FeedbackInfoText"
28    }
29
30    fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
31        let theme = cx.global::<Settings>().theme.clone();
32        let text = "We read whatever you submit here. For issues and discussions, visit the community repo on GitHub.";
33        Label::new(text, theme.feedback.info_text.text.clone())
34            .contained()
35            .aligned()
36            .left()
37            .clipped()
38            .boxed()
39    }
40}
41
42impl ToolbarItemView for FeedbackInfoText {
43    fn set_active_pane_item(
44        &mut self,
45        active_pane_item: Option<&dyn ItemHandle>,
46        cx: &mut ViewContext<Self>,
47    ) -> workspace::ToolbarItemLocation {
48        cx.notify();
49        if let Some(feedback_editor) = active_pane_item.and_then(|i| i.downcast::<FeedbackEditor>())
50        {
51            self.active_item = Some(feedback_editor);
52            ToolbarItemLocation::PrimaryLeft {
53                flex: Some((1., false)),
54            }
55        } else {
56            self.active_item = None;
57            ToolbarItemLocation::Hidden
58        }
59    }
60}