Remove menu bar extra

This commit is contained in:
Antonio Scandurra 2022-10-10 18:21:11 +02:00
parent 04fcd18c75
commit 8dc99d42ff
6 changed files with 17 additions and 160 deletions

View file

@ -1,4 +0,0 @@
<svg width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M5 11C5 14.3137 7.68629 17 11 17C14.3137 17 17 14.3137 17 11C17 7.68629 14.3137 5 11 5C7.68629 5 5 7.68629 5 11ZM11 3C6.58172 3 3 6.58172 3 11C3 15.4183 6.58172 19 11 19C15.4183 19 19 15.4183 19 11C19 6.58172 15.4183 3 11 3Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M8.09092 8.09088H14.6364L10.5511 12.4545H12.4546L13.9091 13.9091H7.36365L11.7273 9.54543H9.54547L8.09092 8.09088Z" fill="white"/>
</svg>

Before

Width:  |  Height:  |  Size: 571 B

View file

@ -163,8 +163,7 @@ 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(false, Some(project), user_store, cx));
let view = cx.add_view(|cx| ContactsPopover::new(project, user_store, cx));
cx.focus(&view);
cx.subscribe(&view, |this, _, event, cx| {
match event {

View file

@ -4,7 +4,6 @@ mod contact_list;
mod contact_notification;
mod contacts_popover;
mod incoming_call_notification;
mod menu_bar_extra;
mod notifications;
mod project_shared_notification;
@ -22,7 +21,6 @@ pub fn init(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
contact_finder::init(cx);
contacts_popover::init(cx);
incoming_call_notification::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| {

View file

@ -114,7 +114,7 @@ pub struct ContactList {
entries: Vec<ContactEntry>,
match_candidates: Vec<StringMatchCandidate>,
list_state: ListState,
project: Option<ModelHandle<Project>>,
project: ModelHandle<Project>,
user_store: ModelHandle<UserStore>,
filter_editor: ViewHandle<Editor>,
collapsed_sections: Vec<Section>,
@ -124,7 +124,7 @@ pub struct ContactList {
impl ContactList {
pub fn new(
project: Option<ModelHandle<Project>>,
project: ModelHandle<Project>,
user_store: ModelHandle<UserStore>,
cx: &mut ViewContext<Self>,
) -> Self {
@ -195,7 +195,7 @@ impl ContactList {
),
ContactEntry::Contact(contact) => Self::render_contact(
contact,
this.project.as_ref(),
&this.project,
&theme.contact_list,
is_selected,
cx,
@ -292,7 +292,7 @@ impl ContactList {
self.call(
&Call {
recipient_user_id: contact.user.id,
initial_project: self.project.clone(),
initial_project: Some(self.project.clone()),
},
cx,
);
@ -664,7 +664,7 @@ impl ContactList {
fn render_contact(
contact: &Contact,
project: Option<&ModelHandle<Project>>,
project: &ModelHandle<Project>,
theme: &theme::ContactList,
is_selected: bool,
cx: &mut RenderContext<Self>,
@ -672,7 +672,7 @@ impl ContactList {
let online = contact.online;
let busy = contact.busy;
let user_id = contact.user.id;
let initial_project = project.cloned();
let initial_project = project.clone();
let mut element =
MouseEventHandler::<Contact>::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: initial_project.clone(),
initial_project: Some(initial_project.clone()),
});
}
});

View file

@ -23,9 +23,8 @@ enum Child {
}
pub struct ContactsPopover {
is_popup: bool,
child: Child,
project: Option<ModelHandle<Project>>,
project: ModelHandle<Project>,
user_store: ModelHandle<UserStore>,
_subscription: Option<gpui::Subscription>,
_window_subscription: gpui::Subscription,
@ -33,13 +32,11 @@ pub struct ContactsPopover {
impl ContactsPopover {
pub fn new(
is_popup: bool,
project: Option<ModelHandle<Project>>,
project: ModelHandle<Project>,
user_store: ModelHandle<UserStore>,
cx: &mut ViewContext<Self>,
) -> Self {
let mut this = Self {
is_popup,
child: Child::ContactList(
cx.add_view(|cx| ContactList::new(project.clone(), user_store.clone(), cx)),
),
@ -103,21 +100,13 @@ impl View for ContactsPopover {
Child::ContactFinder(child) => ChildView::new(child),
};
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()
}
child
.contained()
.with_style(theme.contacts_popover.container)
.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>) {

View file

@ -1,125 +0,0 @@
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, ModelHandle, MouseButton, MutableAppContext, RenderContext, View,
ViewContext, ViewHandle, WindowKind,
};
actions!(menu_bar_extra, [ToggleActiveCallPopover]);
pub fn init(user_store: ModelHandle<UserStore>, cx: &mut MutableAppContext) {
cx.add_action(MenuBarExtra::toggle_active_call_popover);
let mut status_bar_item_id = None;
cx.observe(&ActiveCall::global(cx), move |call, cx| {
let had_room = status_bar_item_id.is_some();
let has_room = call.read(cx).room().is_some();
if had_room != has_room {
if let Some(status_bar_item_id) = status_bar_item_id.take() {
cx.remove_status_bar_item(status_bar_item_id);
}
if has_room {
let (id, _) = cx.add_status_bar_item(|_| MenuBarExtra::new(user_store.clone()));
status_bar_item_id = Some(id);
}
}
})
.detach();
}
struct MenuBarExtra {
popover: Option<ViewHandle<ContactsPopover>>,
user_store: ModelHandle<UserStore>,
}
impl Entity for MenuBarExtra {
type Event = ();
fn release(&mut self, cx: &mut MutableAppContext) {
if let Some(popover) = self.popover.take() {
cx.remove_window(popover.window_id());
}
}
}
impl View for MenuBarExtra {
fn ui_name() -> &'static str {
"MenuBarExtra"
}
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
let color = match cx.appearance {
Appearance::Light | Appearance::VibrantLight => Color::black(),
Appearance::Dark | Appearance::VibrantDark => Color::white(),
};
MouseEventHandler::<Self>::new(0, cx, |_, _| {
Svg::new("icons/zed_22.svg")
.with_color(color)
.aligned()
.boxed()
})
.on_click(MouseButton::Left, |_, cx| {
cx.dispatch_action(ToggleActiveCallPopover);
})
.boxed()
}
}
impl MenuBarExtra {
fn new(user_store: ModelHandle<UserStore>) -> Self {
Self {
popover: None,
user_store,
}
}
fn toggle_active_call_popover(
&mut self,
_: &ToggleActiveCallPopover,
cx: &mut ViewContext<Self>,
) {
match self.popover.take() {
Some(popover) => {
cx.remove_window(popover.window_id());
}
None => {
let window_bounds = cx.window_bounds();
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(
gpui::WindowOptions {
bounds: gpui::WindowBounds::Fixed(RectF::new(origin, size)),
titlebar: None,
center: false,
kind: WindowKind::PopUp,
is_movable: false,
},
|cx| ContactsPopover::new(true, None, self.user_store.clone(), cx),
);
cx.subscribe(&popover, Self::on_popover_event).detach();
self.popover = Some(popover);
}
}
}
fn on_popover_event(
&mut self,
popover: ViewHandle<ContactsPopover>,
event: &contacts_popover::Event,
cx: &mut ViewContext<Self>,
) {
match event {
contacts_popover::Event::Dismissed => {
self.popover.take();
cx.remove_window(popover.window_id());
}
}
}
}