Dismiss popover when contact finder is unfocused

This commit is contained in:
Antonio Scandurra 2022-10-11 11:01:38 +02:00
parent bf488f2027
commit bf0a04ab50

View file

@ -27,7 +27,6 @@ pub struct ContactsPopover {
project: ModelHandle<Project>,
user_store: ModelHandle<UserStore>,
_subscription: Option<gpui::Subscription>,
_window_subscription: gpui::Subscription,
}
impl ContactsPopover {
@ -43,18 +42,11 @@ impl ContactsPopover {
project,
user_store,
_subscription: None,
_window_subscription: cx.observe_window_activation(Self::window_activation_changed),
};
this.show_contact_list(cx);
this
}
fn window_activation_changed(&mut self, active: bool, cx: &mut ViewContext<Self>) {
if !active {
cx.emit(Event::Dismissed);
}
}
fn toggle_contact_finder(&mut self, _: &ToggleContactFinder, cx: &mut ViewContext<Self>) {
match &self.child {
Child::ContactList(_) => self.show_contact_finder(cx),
@ -65,8 +57,8 @@ impl ContactsPopover {
fn show_contact_finder(&mut self, cx: &mut ViewContext<ContactsPopover>) {
let child = cx.add_view(|cx| ContactFinder::new(self.user_store.clone(), cx));
cx.focus(&child);
self._subscription = Some(cx.subscribe(&child, |this, _, event, cx| match event {
crate::contact_finder::Event::Dismissed => this.show_contact_list(cx),
self._subscription = Some(cx.subscribe(&child, |_, _, event, cx| match event {
crate::contact_finder::Event::Dismissed => cx.emit(Event::Dismissed),
}));
self.child = Child::ContactFinder(child);
cx.notify();