Show contacts popover when clicking on menu bar extra
This commit is contained in:
parent
d9d99e5e04
commit
04fcd18c75
6 changed files with 56 additions and 72 deletions
|
@ -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<Self>) -> ElementBox {
|
|
||||||
Empty::new()
|
|
||||||
.contained()
|
|
||||||
.with_background_color(Color::red())
|
|
||||||
.boxed()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveCallPopover {
|
|
||||||
pub fn new(cx: &mut ViewContext<Self>) -> Self {
|
|
||||||
Self {
|
|
||||||
_subscription: cx.observe_window_activation(Self::window_activation_changed),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn window_activation_changed(&mut self, is_active: bool, cx: &mut ViewContext<Self>) {
|
|
||||||
if !is_active {
|
|
||||||
cx.emit(Event::Deactivated);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -163,7 +163,8 @@ impl CollabTitlebarItem {
|
||||||
if let Some(workspace) = self.workspace.upgrade(cx) {
|
if let Some(workspace) = self.workspace.upgrade(cx) {
|
||||||
let project = workspace.read(cx).project().clone();
|
let project = workspace.read(cx).project().clone();
|
||||||
let user_store = workspace.read(cx).user_store().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.focus(&view);
|
||||||
cx.subscribe(&view, |this, _, event, cx| {
|
cx.subscribe(&view, |this, _, event, cx| {
|
||||||
match event {
|
match event {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
mod active_call_popover;
|
|
||||||
mod collab_titlebar_item;
|
mod collab_titlebar_item;
|
||||||
mod contact_finder;
|
mod contact_finder;
|
||||||
mod contact_list;
|
mod contact_list;
|
||||||
|
@ -23,7 +22,7 @@ pub fn init(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
|
||||||
contact_finder::init(cx);
|
contact_finder::init(cx);
|
||||||
contacts_popover::init(cx);
|
contacts_popover::init(cx);
|
||||||
incoming_call_notification::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);
|
project_shared_notification::init(cx);
|
||||||
|
|
||||||
cx.add_global_action(move |action: &JoinProject, cx| {
|
cx.add_global_action(move |action: &JoinProject, cx| {
|
||||||
|
|
|
@ -114,7 +114,7 @@ pub struct ContactList {
|
||||||
entries: Vec<ContactEntry>,
|
entries: Vec<ContactEntry>,
|
||||||
match_candidates: Vec<StringMatchCandidate>,
|
match_candidates: Vec<StringMatchCandidate>,
|
||||||
list_state: ListState,
|
list_state: ListState,
|
||||||
project: ModelHandle<Project>,
|
project: Option<ModelHandle<Project>>,
|
||||||
user_store: ModelHandle<UserStore>,
|
user_store: ModelHandle<UserStore>,
|
||||||
filter_editor: ViewHandle<Editor>,
|
filter_editor: ViewHandle<Editor>,
|
||||||
collapsed_sections: Vec<Section>,
|
collapsed_sections: Vec<Section>,
|
||||||
|
@ -124,7 +124,7 @@ pub struct ContactList {
|
||||||
|
|
||||||
impl ContactList {
|
impl ContactList {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
project: ModelHandle<Project>,
|
project: Option<ModelHandle<Project>>,
|
||||||
user_store: ModelHandle<UserStore>,
|
user_store: ModelHandle<UserStore>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
@ -195,7 +195,7 @@ impl ContactList {
|
||||||
),
|
),
|
||||||
ContactEntry::Contact(contact) => Self::render_contact(
|
ContactEntry::Contact(contact) => Self::render_contact(
|
||||||
contact,
|
contact,
|
||||||
&this.project,
|
this.project.as_ref(),
|
||||||
&theme.contact_list,
|
&theme.contact_list,
|
||||||
is_selected,
|
is_selected,
|
||||||
cx,
|
cx,
|
||||||
|
@ -292,7 +292,7 @@ impl ContactList {
|
||||||
self.call(
|
self.call(
|
||||||
&Call {
|
&Call {
|
||||||
recipient_user_id: contact.user.id,
|
recipient_user_id: contact.user.id,
|
||||||
initial_project: Some(self.project.clone()),
|
initial_project: self.project.clone(),
|
||||||
},
|
},
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
|
@ -664,7 +664,7 @@ impl ContactList {
|
||||||
|
|
||||||
fn render_contact(
|
fn render_contact(
|
||||||
contact: &Contact,
|
contact: &Contact,
|
||||||
project: &ModelHandle<Project>,
|
project: Option<&ModelHandle<Project>>,
|
||||||
theme: &theme::ContactList,
|
theme: &theme::ContactList,
|
||||||
is_selected: bool,
|
is_selected: bool,
|
||||||
cx: &mut RenderContext<Self>,
|
cx: &mut RenderContext<Self>,
|
||||||
|
@ -672,7 +672,7 @@ impl ContactList {
|
||||||
let online = contact.online;
|
let online = contact.online;
|
||||||
let busy = contact.busy;
|
let busy = contact.busy;
|
||||||
let user_id = contact.user.id;
|
let user_id = contact.user.id;
|
||||||
let initial_project = project.clone();
|
let initial_project = project.cloned();
|
||||||
let mut element =
|
let mut element =
|
||||||
MouseEventHandler::<Contact>::new(contact.user.id as usize, cx, |_, _| {
|
MouseEventHandler::<Contact>::new(contact.user.id as usize, cx, |_, _| {
|
||||||
Flex::row()
|
Flex::row()
|
||||||
|
@ -726,7 +726,7 @@ impl ContactList {
|
||||||
if online && !busy {
|
if online && !busy {
|
||||||
cx.dispatch_action(Call {
|
cx.dispatch_action(Call {
|
||||||
recipient_user_id: user_id,
|
recipient_user_id: user_id,
|
||||||
initial_project: Some(initial_project.clone()),
|
initial_project: initial_project.clone(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -23,30 +23,41 @@ enum Child {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ContactsPopover {
|
pub struct ContactsPopover {
|
||||||
|
is_popup: bool,
|
||||||
child: Child,
|
child: Child,
|
||||||
project: ModelHandle<Project>,
|
project: Option<ModelHandle<Project>>,
|
||||||
user_store: ModelHandle<UserStore>,
|
user_store: ModelHandle<UserStore>,
|
||||||
_subscription: Option<gpui::Subscription>,
|
_subscription: Option<gpui::Subscription>,
|
||||||
|
_window_subscription: gpui::Subscription,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ContactsPopover {
|
impl ContactsPopover {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
project: ModelHandle<Project>,
|
is_popup: bool,
|
||||||
|
project: Option<ModelHandle<Project>>,
|
||||||
user_store: ModelHandle<UserStore>,
|
user_store: ModelHandle<UserStore>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let mut this = Self {
|
let mut this = Self {
|
||||||
|
is_popup,
|
||||||
child: Child::ContactList(
|
child: Child::ContactList(
|
||||||
cx.add_view(|cx| ContactList::new(project.clone(), user_store.clone(), cx)),
|
cx.add_view(|cx| ContactList::new(project.clone(), user_store.clone(), cx)),
|
||||||
),
|
),
|
||||||
project,
|
project,
|
||||||
user_store,
|
user_store,
|
||||||
_subscription: None,
|
_subscription: None,
|
||||||
|
_window_subscription: cx.observe_window_activation(Self::window_activation_changed),
|
||||||
};
|
};
|
||||||
this.show_contact_list(cx);
|
this.show_contact_list(cx);
|
||||||
this
|
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>) {
|
fn toggle_contact_finder(&mut self, _: &ToggleContactFinder, cx: &mut ViewContext<Self>) {
|
||||||
match &self.child {
|
match &self.child {
|
||||||
Child::ContactList(_) => self.show_contact_finder(cx),
|
Child::ContactList(_) => self.show_contact_finder(cx),
|
||||||
|
@ -92,13 +103,21 @@ impl View for ContactsPopover {
|
||||||
Child::ContactFinder(child) => ChildView::new(child),
|
Child::ContactFinder(child) => ChildView::new(child),
|
||||||
};
|
};
|
||||||
|
|
||||||
child
|
let mut container_style = theme.contacts_popover.container;
|
||||||
.contained()
|
if self.is_popup {
|
||||||
.with_style(theme.contacts_popover.container)
|
container_style.shadow = Default::default();
|
||||||
.constrained()
|
container_style.border = Default::default();
|
||||||
.with_width(theme.contacts_popover.width)
|
container_style.corner_radius = Default::default();
|
||||||
.with_height(theme.contacts_popover.height)
|
child.contained().with_style(container_style).boxed()
|
||||||
.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<Self>) {
|
fn on_focus_in(&mut self, _: gpui::AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
use crate::active_call_popover::{self, ActiveCallPopover};
|
use crate::contacts_popover::{self, ContactsPopover};
|
||||||
use call::ActiveCall;
|
use call::ActiveCall;
|
||||||
|
use client::UserStore;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions,
|
actions,
|
||||||
color::Color,
|
color::Color,
|
||||||
elements::*,
|
elements::*,
|
||||||
geometry::{rect::RectF, vector::vec2f},
|
geometry::{rect::RectF, vector::vec2f},
|
||||||
Appearance, Entity, MouseButton, MutableAppContext, RenderContext, View, ViewContext,
|
Appearance, Entity, ModelHandle, MouseButton, MutableAppContext, RenderContext, View,
|
||||||
ViewHandle, WindowKind,
|
ViewContext, ViewHandle, WindowKind,
|
||||||
};
|
};
|
||||||
|
|
||||||
actions!(menu_bar_extra, [ToggleActiveCallPopover]);
|
actions!(menu_bar_extra, [ToggleActiveCallPopover]);
|
||||||
|
|
||||||
pub fn init(cx: &mut MutableAppContext) {
|
pub fn init(user_store: ModelHandle<UserStore>, cx: &mut MutableAppContext) {
|
||||||
cx.add_action(MenuBarExtra::toggle_active_call_popover);
|
cx.add_action(MenuBarExtra::toggle_active_call_popover);
|
||||||
|
|
||||||
let mut status_bar_item_id = None;
|
let mut status_bar_item_id = None;
|
||||||
|
@ -24,7 +25,7 @@ pub fn init(cx: &mut MutableAppContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if has_room {
|
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);
|
status_bar_item_id = Some(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +34,8 @@ pub fn init(cx: &mut MutableAppContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MenuBarExtra {
|
struct MenuBarExtra {
|
||||||
popover: Option<ViewHandle<ActiveCallPopover>>,
|
popover: Option<ViewHandle<ContactsPopover>>,
|
||||||
|
user_store: ModelHandle<UserStore>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Entity for MenuBarExtra {
|
impl Entity for MenuBarExtra {
|
||||||
|
@ -70,8 +72,11 @@ impl View for MenuBarExtra {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MenuBarExtra {
|
impl MenuBarExtra {
|
||||||
fn new() -> Self {
|
fn new(user_store: ModelHandle<UserStore>) -> Self {
|
||||||
Self { popover: None }
|
Self {
|
||||||
|
popover: None,
|
||||||
|
user_store,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_active_call_popover(
|
fn toggle_active_call_popover(
|
||||||
|
@ -85,7 +90,7 @@ impl MenuBarExtra {
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let window_bounds = cx.window_bounds();
|
let window_bounds = cx.window_bounds();
|
||||||
let size = vec2f(360., 460.);
|
let size = vec2f(300., 350.);
|
||||||
let origin = window_bounds.lower_left()
|
let origin = window_bounds.lower_left()
|
||||||
+ vec2f(window_bounds.width() / 2. - size.x() / 2., 0.);
|
+ vec2f(window_bounds.width() / 2. - size.x() / 2., 0.);
|
||||||
let (_, popover) = cx.add_window(
|
let (_, popover) = cx.add_window(
|
||||||
|
@ -96,7 +101,7 @@ impl MenuBarExtra {
|
||||||
kind: WindowKind::PopUp,
|
kind: WindowKind::PopUp,
|
||||||
is_movable: false,
|
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();
|
cx.subscribe(&popover, Self::on_popover_event).detach();
|
||||||
self.popover = Some(popover);
|
self.popover = Some(popover);
|
||||||
|
@ -106,12 +111,12 @@ impl MenuBarExtra {
|
||||||
|
|
||||||
fn on_popover_event(
|
fn on_popover_event(
|
||||||
&mut self,
|
&mut self,
|
||||||
popover: ViewHandle<ActiveCallPopover>,
|
popover: ViewHandle<ContactsPopover>,
|
||||||
event: &active_call_popover::Event,
|
event: &contacts_popover::Event,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) {
|
) {
|
||||||
match event {
|
match event {
|
||||||
active_call_popover::Event::Deactivated => {
|
contacts_popover::Event::Dismissed => {
|
||||||
self.popover.take();
|
self.popover.take();
|
||||||
cx.remove_window(popover.window_id());
|
cx.remove_window(popover.window_id());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue