1use editor::Editor;
2use gpui::{elements::*, Entity, RenderContext, View, ViewContext, ViewHandle};
3use settings::Settings;
4
5pub enum Event {
6 Deactivated,
7}
8
9pub struct ContactsPopover {
10 filter_editor: ViewHandle<Editor>,
11}
12
13impl Entity for ContactsPopover {
14 type Event = Event;
15}
16
17impl View for ContactsPopover {
18 fn ui_name() -> &'static str {
19 "ContactsPopover"
20 }
21
22 fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
23 let theme = &cx.global::<Settings>().theme.contacts_popover;
24
25 Flex::row()
26 .with_child(
27 ChildView::new(self.filter_editor.clone())
28 .contained()
29 .with_style(
30 cx.global::<Settings>()
31 .theme
32 .contacts_panel
33 .user_query_editor
34 .container,
35 )
36 .flex(1., true)
37 .boxed(),
38 )
39 // .with_child(
40 // MouseEventHandler::<AddContact>::new(0, cx, |_, _| {
41 // Svg::new("icons/user_plus_16.svg")
42 // .with_color(theme.add_contact_button.color)
43 // .constrained()
44 // .with_height(16.)
45 // .contained()
46 // .with_style(theme.add_contact_button.container)
47 // .aligned()
48 // .boxed()
49 // })
50 // .with_cursor_style(CursorStyle::PointingHand)
51 // .on_click(MouseButton::Left, |_, cx| {
52 // cx.dispatch_action(contact_finder::Toggle)
53 // })
54 // .boxed(),
55 // )
56 .constrained()
57 .with_height(
58 cx.global::<Settings>()
59 .theme
60 .contacts_panel
61 .user_query_editor_height,
62 )
63 .aligned()
64 .top()
65 .contained()
66 .with_background_color(theme.background)
67 .with_uniform_padding(4.)
68 .boxed()
69 }
70}
71
72impl ContactsPopover {
73 pub fn new(cx: &mut ViewContext<Self>) -> Self {
74 cx.observe_window_activation(Self::window_activation_changed)
75 .detach();
76
77 let filter_editor = cx.add_view(|cx| {
78 let mut editor = Editor::single_line(
79 Some(|theme| theme.contacts_panel.user_query_editor.clone()),
80 cx,
81 );
82 editor.set_placeholder_text("Filter contacts", cx);
83 editor
84 });
85
86 Self { filter_editor }
87 }
88
89 fn window_activation_changed(&mut self, is_active: bool, cx: &mut ViewContext<Self>) {
90 if !is_active {
91 cx.emit(Event::Deactivated);
92 }
93 }
94}