From 04fcd18c755c7e6f1ec9339fb1328617ad55c517 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 10 Oct 2022 16:30:02 +0200 Subject: [PATCH] Show contacts popover when clicking on menu bar extra --- crates/collab_ui/src/active_call_popover.rs | 40 -------------------- crates/collab_ui/src/collab_titlebar_item.rs | 3 +- crates/collab_ui/src/collab_ui.rs | 3 +- crates/collab_ui/src/contact_list.rs | 14 +++---- crates/collab_ui/src/contacts_popover.rs | 37 +++++++++++++----- crates/collab_ui/src/menu_bar_extra.rs | 31 ++++++++------- 6 files changed, 56 insertions(+), 72 deletions(-) delete mode 100644 crates/collab_ui/src/active_call_popover.rs diff --git a/crates/collab_ui/src/active_call_popover.rs b/crates/collab_ui/src/active_call_popover.rs deleted file mode 100644 index 01a4e4721d4f490696f0be3a97e7f75c09a67367..0000000000000000000000000000000000000000 --- a/crates/collab_ui/src/active_call_popover.rs +++ /dev/null @@ -1,40 +0,0 @@ -use gpui::{color::Color, elements::*, Entity, RenderContext, View, ViewContext}; - -pub enum Event { - Deactivated, -} - -pub struct ActiveCallPopover { - _subscription: gpui::Subscription, -} - -impl Entity for ActiveCallPopover { - type Event = Event; -} - -impl View for ActiveCallPopover { - fn ui_name() -> &'static str { - "ActiveCallPopover" - } - - fn render(&mut self, _: &mut RenderContext) -> ElementBox { - Empty::new() - .contained() - .with_background_color(Color::red()) - .boxed() - } -} - -impl ActiveCallPopover { - pub fn new(cx: &mut ViewContext) -> Self { - Self { - _subscription: cx.observe_window_activation(Self::window_activation_changed), - } - } - - fn window_activation_changed(&mut self, is_active: bool, cx: &mut ViewContext) { - if !is_active { - cx.emit(Event::Deactivated); - } - } -} diff --git a/crates/collab_ui/src/collab_titlebar_item.rs b/crates/collab_ui/src/collab_titlebar_item.rs index c46861b5ab659224b3462b71c7c6ddaab725719a..bbe27ce3a972976d8ede93fc6931420f6bcca11f 100644 --- a/crates/collab_ui/src/collab_titlebar_item.rs +++ b/crates/collab_ui/src/collab_titlebar_item.rs @@ -163,7 +163,8 @@ impl CollabTitlebarItem { if let Some(workspace) = self.workspace.upgrade(cx) { let project = workspace.read(cx).project().clone(); let user_store = workspace.read(cx).user_store().clone(); - let view = cx.add_view(|cx| ContactsPopover::new(project, user_store, cx)); + let view = cx + .add_view(|cx| ContactsPopover::new(false, Some(project), user_store, cx)); cx.focus(&view); cx.subscribe(&view, |this, _, event, cx| { match event { diff --git a/crates/collab_ui/src/collab_ui.rs b/crates/collab_ui/src/collab_ui.rs index da2cf775340974b062d90242d9a7fa7975f50886..221ee6068fc23e907fed2785303d41e328af0629 100644 --- a/crates/collab_ui/src/collab_ui.rs +++ b/crates/collab_ui/src/collab_ui.rs @@ -1,4 +1,3 @@ -mod active_call_popover; mod collab_titlebar_item; mod contact_finder; mod contact_list; @@ -23,7 +22,7 @@ pub fn init(app_state: Arc, cx: &mut MutableAppContext) { contact_finder::init(cx); contacts_popover::init(cx); incoming_call_notification::init(cx); - menu_bar_extra::init(cx); + menu_bar_extra::init(app_state.user_store.clone(), cx); project_shared_notification::init(cx); cx.add_global_action(move |action: &JoinProject, cx| { diff --git a/crates/collab_ui/src/contact_list.rs b/crates/collab_ui/src/contact_list.rs index a539f8ffac9e0a3e88b30562b46d45ed5b521b87..da48015b4e909cfdd29ce2d37a4776e04b28fe4c 100644 --- a/crates/collab_ui/src/contact_list.rs +++ b/crates/collab_ui/src/contact_list.rs @@ -114,7 +114,7 @@ pub struct ContactList { entries: Vec, match_candidates: Vec, list_state: ListState, - project: ModelHandle, + project: Option>, user_store: ModelHandle, filter_editor: ViewHandle, collapsed_sections: Vec
, @@ -124,7 +124,7 @@ pub struct ContactList { impl ContactList { pub fn new( - project: ModelHandle, + project: Option>, user_store: ModelHandle, cx: &mut ViewContext, ) -> Self { @@ -195,7 +195,7 @@ impl ContactList { ), ContactEntry::Contact(contact) => Self::render_contact( contact, - &this.project, + this.project.as_ref(), &theme.contact_list, is_selected, cx, @@ -292,7 +292,7 @@ impl ContactList { self.call( &Call { recipient_user_id: contact.user.id, - initial_project: Some(self.project.clone()), + initial_project: self.project.clone(), }, cx, ); @@ -664,7 +664,7 @@ impl ContactList { fn render_contact( contact: &Contact, - project: &ModelHandle, + project: Option<&ModelHandle>, theme: &theme::ContactList, is_selected: bool, cx: &mut RenderContext, @@ -672,7 +672,7 @@ impl ContactList { let online = contact.online; let busy = contact.busy; let user_id = contact.user.id; - let initial_project = project.clone(); + let initial_project = project.cloned(); let mut element = MouseEventHandler::::new(contact.user.id as usize, cx, |_, _| { Flex::row() @@ -726,7 +726,7 @@ impl ContactList { if online && !busy { cx.dispatch_action(Call { recipient_user_id: user_id, - initial_project: Some(initial_project.clone()), + initial_project: initial_project.clone(), }); } }); diff --git a/crates/collab_ui/src/contacts_popover.rs b/crates/collab_ui/src/contacts_popover.rs index 07ddc487a405412149c57aa78ad005a2732a7844..dd67cfe72409ca8da3abf79986799048a39dcdb9 100644 --- a/crates/collab_ui/src/contacts_popover.rs +++ b/crates/collab_ui/src/contacts_popover.rs @@ -23,30 +23,41 @@ enum Child { } pub struct ContactsPopover { + is_popup: bool, child: Child, - project: ModelHandle, + project: Option>, user_store: ModelHandle, _subscription: Option, + _window_subscription: gpui::Subscription, } impl ContactsPopover { pub fn new( - project: ModelHandle, + is_popup: bool, + project: Option>, user_store: ModelHandle, cx: &mut ViewContext, ) -> Self { let mut this = Self { + is_popup, child: Child::ContactList( cx.add_view(|cx| ContactList::new(project.clone(), user_store.clone(), cx)), ), 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) { + if !active { + cx.emit(Event::Dismissed); + } + } + fn toggle_contact_finder(&mut self, _: &ToggleContactFinder, cx: &mut ViewContext) { match &self.child { Child::ContactList(_) => self.show_contact_finder(cx), @@ -92,13 +103,21 @@ impl View for ContactsPopover { Child::ContactFinder(child) => ChildView::new(child), }; - child - .contained() - .with_style(theme.contacts_popover.container) - .constrained() - .with_width(theme.contacts_popover.width) - .with_height(theme.contacts_popover.height) - .boxed() + let mut container_style = theme.contacts_popover.container; + if self.is_popup { + container_style.shadow = Default::default(); + container_style.border = Default::default(); + container_style.corner_radius = Default::default(); + child.contained().with_style(container_style).boxed() + } else { + child + .contained() + .with_style(container_style) + .constrained() + .with_width(theme.contacts_popover.width) + .with_height(theme.contacts_popover.height) + .boxed() + } } fn on_focus_in(&mut self, _: gpui::AnyViewHandle, cx: &mut ViewContext) { diff --git a/crates/collab_ui/src/menu_bar_extra.rs b/crates/collab_ui/src/menu_bar_extra.rs index 814d51b1892756b729998b95a08d91e433995f55..1db9ceaabd325a8963c80102f54d48df66e7c29d 100644 --- a/crates/collab_ui/src/menu_bar_extra.rs +++ b/crates/collab_ui/src/menu_bar_extra.rs @@ -1,17 +1,18 @@ -use crate::active_call_popover::{self, ActiveCallPopover}; +use crate::contacts_popover::{self, ContactsPopover}; use call::ActiveCall; +use client::UserStore; use gpui::{ actions, color::Color, elements::*, geometry::{rect::RectF, vector::vec2f}, - Appearance, Entity, MouseButton, MutableAppContext, RenderContext, View, ViewContext, - ViewHandle, WindowKind, + Appearance, Entity, ModelHandle, MouseButton, MutableAppContext, RenderContext, View, + ViewContext, ViewHandle, WindowKind, }; actions!(menu_bar_extra, [ToggleActiveCallPopover]); -pub fn init(cx: &mut MutableAppContext) { +pub fn init(user_store: ModelHandle, cx: &mut MutableAppContext) { cx.add_action(MenuBarExtra::toggle_active_call_popover); let mut status_bar_item_id = None; @@ -24,7 +25,7 @@ pub fn init(cx: &mut MutableAppContext) { } if has_room { - let (id, _) = cx.add_status_bar_item(|_| MenuBarExtra::new()); + let (id, _) = cx.add_status_bar_item(|_| MenuBarExtra::new(user_store.clone())); status_bar_item_id = Some(id); } } @@ -33,7 +34,8 @@ pub fn init(cx: &mut MutableAppContext) { } struct MenuBarExtra { - popover: Option>, + popover: Option>, + user_store: ModelHandle, } impl Entity for MenuBarExtra { @@ -70,8 +72,11 @@ impl View for MenuBarExtra { } impl MenuBarExtra { - fn new() -> Self { - Self { popover: None } + fn new(user_store: ModelHandle) -> Self { + Self { + popover: None, + user_store, + } } fn toggle_active_call_popover( @@ -85,7 +90,7 @@ impl MenuBarExtra { } None => { let window_bounds = cx.window_bounds(); - let size = vec2f(360., 460.); + let size = vec2f(300., 350.); let origin = window_bounds.lower_left() + vec2f(window_bounds.width() / 2. - size.x() / 2., 0.); let (_, popover) = cx.add_window( @@ -96,7 +101,7 @@ impl MenuBarExtra { kind: WindowKind::PopUp, is_movable: false, }, - |cx| ActiveCallPopover::new(cx), + |cx| ContactsPopover::new(true, None, self.user_store.clone(), cx), ); cx.subscribe(&popover, Self::on_popover_event).detach(); self.popover = Some(popover); @@ -106,12 +111,12 @@ impl MenuBarExtra { fn on_popover_event( &mut self, - popover: ViewHandle, - event: &active_call_popover::Event, + popover: ViewHandle, + event: &contacts_popover::Event, cx: &mut ViewContext, ) { match event { - active_call_popover::Event::Deactivated => { + contacts_popover::Event::Dismissed => { self.popover.take(); cx.remove_window(popover.window_id()); }