Merge pull request #1745 from zed-industries/contact-popover-focus

Fix some issues with contact popover focus
This commit is contained in:
Antonio Scandurra 2022-10-13 08:37:14 +01:00 committed by GitHub
commit 06e9b8276f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 64 additions and 56 deletions

View file

@ -152,7 +152,6 @@ impl CollabTitlebarItem {
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(project, user_store, cx));
cx.focus(&view);
cx.subscribe(&view, |this, _, event, cx| { cx.subscribe(&view, |this, _, event, cx| {
match event { match event {
contacts_popover::Event::Dismissed => { contacts_popover::Event::Dismissed => {

View file

@ -1,4 +1,4 @@
use crate::{contact_finder::ContactFinder, contact_list::ContactList}; use crate::{contact_finder::ContactFinder, contact_list::ContactList, ToggleCollaborationMenu};
use client::UserStore; use client::UserStore;
use gpui::{ use gpui::{
actions, elements::*, ClipboardItem, CursorStyle, Entity, ModelHandle, MouseButton, actions, elements::*, ClipboardItem, CursorStyle, Entity, ModelHandle, MouseButton,
@ -92,63 +92,72 @@ impl View for ContactsPopover {
Child::ContactFinder(child) => ChildView::new(child), Child::ContactFinder(child) => ChildView::new(child),
}; };
Flex::column() MouseEventHandler::<ContactsPopover>::new(0, cx, |_, cx| {
.with_child(child.flex(1., true).boxed()) Flex::column()
.with_children( .with_child(child.flex(1., true).boxed())
self.user_store .with_children(
.read(cx) self.user_store
.invite_info() .read(cx)
.cloned() .invite_info()
.and_then(|info| { .cloned()
enum InviteLink {} .and_then(|info| {
enum InviteLink {}
if info.count > 0 { if info.count > 0 {
Some( Some(
MouseEventHandler::<InviteLink>::new(0, cx, |state, cx| { MouseEventHandler::<InviteLink>::new(0, cx, |state, cx| {
let style = theme let style = theme
.contacts_popover .contacts_popover
.invite_row .invite_row
.style_for(state, false) .style_for(state, false)
.clone(); .clone();
let copied = cx.read_from_clipboard().map_or(false, |item| { let copied =
item.text().as_str() == info.url.as_ref() cx.read_from_clipboard().map_or(false, |item| {
}); item.text().as_str() == info.url.as_ref()
});
Label::new( Label::new(
format!( format!(
"{} invite link ({} left)", "{} invite link ({} left)",
if copied { "Copied" } else { "Copy" }, if copied { "Copied" } else { "Copy" },
info.count info.count
), ),
style.label.clone(), style.label.clone(),
) )
.aligned() .aligned()
.left() .left()
.constrained() .constrained()
.with_height(theme.contacts_popover.invite_row_height) .with_height(theme.contacts_popover.invite_row_height)
.contained() .contained()
.with_style(style.container) .with_style(style.container)
.boxed() .boxed()
}) })
.with_cursor_style(CursorStyle::PointingHand) .with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, move |_, cx| { .on_click(MouseButton::Left, move |_, cx| {
cx.write_to_clipboard(ClipboardItem::new(info.url.to_string())); cx.write_to_clipboard(ClipboardItem::new(
cx.notify(); info.url.to_string(),
}) ));
.boxed(), cx.notify();
) })
} else { .boxed(),
None )
} } else {
}), None
) }
.contained() }),
.with_style(theme.contacts_popover.container) )
.constrained() .contained()
.with_width(theme.contacts_popover.width) .with_style(theme.contacts_popover.container)
.with_height(theme.contacts_popover.height) .constrained()
.boxed() .with_width(theme.contacts_popover.width)
.with_height(theme.contacts_popover.height)
.boxed()
})
.on_down_out(MouseButton::Left, move |_, cx| {
cx.dispatch_action(ToggleCollaborationMenu);
})
.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>) {