mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-27 12:54:42 +00:00
Reinstate all of the contacts popovers' functionality in the new collaboration panel
This commit is contained in:
parent
7f9df6dd24
commit
969ecfcfa2
6 changed files with 1342 additions and 1577 deletions
File diff suppressed because it is too large
Load diff
|
@ -1,140 +0,0 @@
|
|||
mod contact_finder;
|
||||
mod contacts_list;
|
||||
|
||||
use client::UserStore;
|
||||
use gpui::{
|
||||
actions, elements::*, platform::MouseButton, AppContext, Entity, ModelHandle, View,
|
||||
ViewContext, ViewHandle, WeakViewHandle,
|
||||
};
|
||||
use picker::PickerEvent;
|
||||
use project::Project;
|
||||
use workspace::Workspace;
|
||||
|
||||
use self::{contacts_list::ContactList, contact_finder::{ContactFinder, build_contact_finder}};
|
||||
|
||||
actions!(contacts_popover, [ToggleContactFinder]);
|
||||
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
cx.add_action(Contacts::toggle_contact_finder);
|
||||
contact_finder::init(cx);
|
||||
contacts_list::init(cx);
|
||||
}
|
||||
|
||||
pub enum Event {
|
||||
Dismissed,
|
||||
}
|
||||
|
||||
enum Child {
|
||||
ContactList(ViewHandle<ContactList>),
|
||||
ContactFinder(ViewHandle<ContactFinder>),
|
||||
}
|
||||
|
||||
pub struct Contacts {
|
||||
child: Child,
|
||||
project: ModelHandle<Project>,
|
||||
user_store: ModelHandle<UserStore>,
|
||||
workspace: WeakViewHandle<Workspace>,
|
||||
_subscription: Option<gpui::Subscription>,
|
||||
}
|
||||
|
||||
impl Contacts {
|
||||
pub fn new(
|
||||
project: ModelHandle<Project>,
|
||||
user_store: ModelHandle<UserStore>,
|
||||
workspace: WeakViewHandle<Workspace>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Self {
|
||||
let mut this = Self {
|
||||
child: Child::ContactList(cx.add_view(|cx| {
|
||||
ContactList::new(project.clone(), user_store.clone(), workspace.clone(), cx)
|
||||
})),
|
||||
project,
|
||||
user_store,
|
||||
workspace,
|
||||
_subscription: None,
|
||||
};
|
||||
this.show_contact_list(String::new(), cx);
|
||||
this
|
||||
}
|
||||
|
||||
fn toggle_contact_finder(&mut self, _: &ToggleContactFinder, cx: &mut ViewContext<Self>) {
|
||||
match &self.child {
|
||||
Child::ContactList(list) => self.show_contact_finder(list.read(cx).editor_text(cx), cx),
|
||||
Child::ContactFinder(finder) => self.show_contact_list(finder.read(cx).query(cx), cx),
|
||||
}
|
||||
}
|
||||
|
||||
fn show_contact_finder(&mut self, editor_text: String, cx: &mut ViewContext<Contacts>) {
|
||||
let child = cx.add_view(|cx| {
|
||||
let finder = build_contact_finder(self.user_store.clone(), cx);
|
||||
finder.set_query(editor_text, cx);
|
||||
finder
|
||||
});
|
||||
cx.focus(&child);
|
||||
self._subscription = Some(cx.subscribe(&child, |_, _, event, cx| match event {
|
||||
PickerEvent::Dismiss => cx.emit(Event::Dismissed),
|
||||
}));
|
||||
self.child = Child::ContactFinder(child);
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
fn show_contact_list(&mut self, editor_text: String, cx: &mut ViewContext<Contacts>) {
|
||||
let child = cx.add_view(|cx| {
|
||||
ContactList::new(
|
||||
self.project.clone(),
|
||||
self.user_store.clone(),
|
||||
self.workspace.clone(),
|
||||
cx,
|
||||
)
|
||||
.with_editor_text(editor_text, cx)
|
||||
});
|
||||
cx.focus(&child);
|
||||
self._subscription = Some(cx.subscribe(&child, |this, _, event, cx| match event {
|
||||
contacts_list::Event::Dismissed => cx.emit(Event::Dismissed),
|
||||
contacts_list::Event::ToggleContactFinder => {
|
||||
this.toggle_contact_finder(&Default::default(), cx)
|
||||
}
|
||||
}));
|
||||
self.child = Child::ContactList(child);
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
impl Entity for Contacts {
|
||||
type Event = Event;
|
||||
}
|
||||
|
||||
impl View for Contacts {
|
||||
fn ui_name() -> &'static str {
|
||||
"ContactsPopover"
|
||||
}
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
|
||||
let theme = theme::current(cx).clone();
|
||||
let child = match &self.child {
|
||||
Child::ContactList(child) => ChildView::new(child, cx),
|
||||
Child::ContactFinder(child) => ChildView::new(child, cx),
|
||||
};
|
||||
|
||||
MouseEventHandler::<Contacts, Self>::new(0, cx, |_, _| {
|
||||
Flex::column()
|
||||
.with_child(child)
|
||||
.contained()
|
||||
.with_style(theme.contacts_popover.container)
|
||||
.constrained()
|
||||
.with_width(theme.contacts_popover.width)
|
||||
.with_height(theme.contacts_popover.height)
|
||||
})
|
||||
.on_down_out(MouseButton::Left, move |_, _, cx| cx.emit(Event::Dismissed))
|
||||
.into_any()
|
||||
}
|
||||
|
||||
fn focus_in(&mut self, _: gpui::AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||
if cx.is_self_focused() {
|
||||
match &self.child {
|
||||
Child::ContactList(child) => cx.focus(child),
|
||||
Child::ContactFinder(child) => cx.focus(child),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -271,8 +271,16 @@ impl<V: View, E: Element<V>> AnyElementState<V> for ElementState<V, E> {
|
|||
| ElementState::PostLayout { mut element, .. }
|
||||
| ElementState::PostPaint { mut element, .. } => {
|
||||
let (size, layout) = element.layout(constraint, view, cx);
|
||||
debug_assert!(size.x().is_finite(), "Element for {:?} had infinite x size after layout", element.view_name());
|
||||
debug_assert!(size.y().is_finite(), "Element for {:?} had infinite x size after layout", element.view_name());
|
||||
debug_assert!(
|
||||
size.x().is_finite(),
|
||||
"Element for {:?} had infinite x size after layout",
|
||||
element.view_name()
|
||||
);
|
||||
debug_assert!(
|
||||
size.y().is_finite(),
|
||||
"Element for {:?} had infinite y size after layout",
|
||||
element.view_name()
|
||||
);
|
||||
|
||||
result = size;
|
||||
ElementState::PostLayout {
|
||||
|
|
|
@ -5,10 +5,10 @@ export default function contacts_popover(): any {
|
|||
const theme = useTheme()
|
||||
|
||||
return {
|
||||
background: background(theme.middle),
|
||||
corner_radius: 6,
|
||||
// background: background(theme.middle),
|
||||
// corner_radius: 6,
|
||||
padding: { top: 6, bottom: 6 },
|
||||
shadow: theme.popover_shadow,
|
||||
// shadow: theme.popover_shadow,
|
||||
border: border(theme.middle),
|
||||
width: 300,
|
||||
height: 400,
|
||||
|
|
Loading…
Reference in a new issue