Move contacts panel features into collab_ui

This commit is contained in:
Antonio Scandurra 2022-10-06 14:00:14 +02:00
parent 7763acbdd5
commit 40163da679
17 changed files with 152 additions and 1134 deletions

26
Cargo.lock generated
View file

@ -1091,6 +1091,7 @@ dependencies = [
"gpui", "gpui",
"log", "log",
"menu", "menu",
"picker",
"postage", "postage",
"project", "project",
"serde", "serde",
@ -1141,30 +1142,6 @@ dependencies = [
"cache-padded", "cache-padded",
] ]
[[package]]
name = "contacts_panel"
version = "0.1.0"
dependencies = [
"anyhow",
"client",
"collections",
"editor",
"futures",
"fuzzy",
"gpui",
"language",
"log",
"menu",
"picker",
"postage",
"project",
"serde",
"settings",
"theme",
"util",
"workspace",
]
[[package]] [[package]]
name = "context_menu" name = "context_menu"
version = "0.1.0" version = "0.1.0"
@ -7165,7 +7142,6 @@ dependencies = [
"collab_ui", "collab_ui",
"collections", "collections",
"command_palette", "command_palette",
"contacts_panel",
"context_menu", "context_menu",
"ctor", "ctor",
"diagnostics", "diagnostics",

View file

@ -395,7 +395,6 @@
"context": "Workspace", "context": "Workspace",
"bindings": { "bindings": {
"shift-escape": "dock::FocusDock", "shift-escape": "dock::FocusDock",
"cmd-shift-c": "contacts_panel::ToggleFocus",
"cmd-shift-b": "workspace::ToggleRightSidebar" "cmd-shift-b": "workspace::ToggleRightSidebar"
} }
}, },

View file

@ -29,6 +29,7 @@ editor = { path = "../editor" }
fuzzy = { path = "../fuzzy" } fuzzy = { path = "../fuzzy" }
gpui = { path = "../gpui" } gpui = { path = "../gpui" }
menu = { path = "../menu" } menu = { path = "../menu" }
picker = { path = "../picker" }
project = { path = "../project" } project = { path = "../project" }
settings = { path = "../settings" } settings = { path = "../settings" }
theme = { path = "../theme" } theme = { path = "../theme" }

View file

@ -1,6 +1,6 @@
use crate::contacts_popover; use crate::{contact_notification::ContactNotification, contacts_popover};
use call::{ActiveCall, ParticipantLocation}; use call::{ActiveCall, ParticipantLocation};
use client::{Authenticate, PeerId}; use client::{Authenticate, ContactEventKind, PeerId, UserStore};
use clock::ReplicaId; use clock::ReplicaId;
use contacts_popover::ContactsPopover; use contacts_popover::ContactsPopover;
use gpui::{ use gpui::{
@ -9,8 +9,8 @@ use gpui::{
elements::*, elements::*,
geometry::{rect::RectF, vector::vec2f, PathBuilder}, geometry::{rect::RectF, vector::vec2f, PathBuilder},
json::{self, ToJson}, json::{self, ToJson},
Border, CursorStyle, Entity, ImageData, MouseButton, MutableAppContext, RenderContext, Border, CursorStyle, Entity, ImageData, ModelHandle, MouseButton, MutableAppContext,
Subscription, View, ViewContext, ViewHandle, WeakViewHandle, RenderContext, Subscription, View, ViewContext, ViewHandle, WeakViewHandle,
}; };
use settings::Settings; use settings::Settings;
use std::{ops::Range, sync::Arc}; use std::{ops::Range, sync::Arc};
@ -29,6 +29,7 @@ pub fn init(cx: &mut MutableAppContext) {
pub struct CollabTitlebarItem { pub struct CollabTitlebarItem {
workspace: WeakViewHandle<Workspace>, workspace: WeakViewHandle<Workspace>,
user_store: ModelHandle<UserStore>,
contacts_popover: Option<ViewHandle<ContactsPopover>>, contacts_popover: Option<ViewHandle<ContactsPopover>>,
_subscriptions: Vec<Subscription>, _subscriptions: Vec<Subscription>,
} }
@ -71,7 +72,11 @@ impl View for CollabTitlebarItem {
} }
impl CollabTitlebarItem { impl CollabTitlebarItem {
pub fn new(workspace: &ViewHandle<Workspace>, cx: &mut ViewContext<Self>) -> Self { pub fn new(
workspace: &ViewHandle<Workspace>,
user_store: &ModelHandle<UserStore>,
cx: &mut ViewContext<Self>,
) -> Self {
let active_call = ActiveCall::global(cx); let active_call = ActiveCall::global(cx);
let mut subscriptions = Vec::new(); let mut subscriptions = Vec::new();
subscriptions.push(cx.observe(workspace, |_, _, cx| cx.notify())); subscriptions.push(cx.observe(workspace, |_, _, cx| cx.notify()));
@ -79,9 +84,33 @@ impl CollabTitlebarItem {
subscriptions.push(cx.observe_window_activation(|this, active, cx| { subscriptions.push(cx.observe_window_activation(|this, active, cx| {
this.window_activation_changed(active, cx) this.window_activation_changed(active, cx)
})); }));
subscriptions.push(cx.observe(user_store, |_, _, cx| cx.notify()));
subscriptions.push(
cx.subscribe(user_store, move |this, user_store, event, cx| {
if let Some(workspace) = this.workspace.upgrade(cx) {
workspace.update(cx, |workspace, cx| {
if let client::Event::Contact { user, kind } = event {
if let ContactEventKind::Requested | ContactEventKind::Accepted = kind {
workspace.show_notification(user.id as usize, cx, |cx| {
cx.add_view(|cx| {
ContactNotification::new(
user.clone(),
*kind,
user_store,
cx,
)
})
})
}
}
});
}
}),
);
Self { Self {
workspace: workspace.downgrade(), workspace: workspace.downgrade(),
user_store: user_store.clone(),
contacts_popover: None, contacts_popover: None,
_subscriptions: subscriptions, _subscriptions: subscriptions,
} }
@ -160,6 +189,26 @@ impl CollabTitlebarItem {
cx: &mut RenderContext<Self>, cx: &mut RenderContext<Self>,
) -> ElementBox { ) -> ElementBox {
let titlebar = &theme.workspace.titlebar; let titlebar = &theme.workspace.titlebar;
let badge = if self
.user_store
.read(cx)
.incoming_contact_requests()
.is_empty()
{
None
} else {
Some(
Empty::new()
.collapsed()
.contained()
.with_style(titlebar.toggle_contacts_badge)
.contained()
.with_margin_left(titlebar.toggle_contacts_button.default.icon_width)
.with_margin_top(titlebar.toggle_contacts_button.default.icon_width)
.aligned()
.boxed(),
)
};
Stack::new() Stack::new()
.with_child( .with_child(
MouseEventHandler::<ToggleContactsPopover>::new(0, cx, |state, _| { MouseEventHandler::<ToggleContactsPopover>::new(0, cx, |state, _| {
@ -185,6 +234,7 @@ impl CollabTitlebarItem {
.aligned() .aligned()
.boxed(), .boxed(),
) )
.with_children(badge)
.with_children(self.contacts_popover.as_ref().map(|popover| { .with_children(self.contacts_popover.as_ref().map(|popover| {
Overlay::new( Overlay::new(
ChildView::new(popover) ChildView::new(popover)

View file

@ -1,6 +1,9 @@
mod collab_titlebar_item; mod collab_titlebar_item;
mod contact_finder;
mod contact_notification;
mod contacts_popover; mod contacts_popover;
mod incoming_call_notification; mod incoming_call_notification;
mod notifications;
mod project_shared_notification; mod project_shared_notification;
use call::ActiveCall; use call::ActiveCall;
@ -11,6 +14,8 @@ use std::sync::Arc;
use workspace::{AppState, JoinProject, ToggleFollow, Workspace}; use workspace::{AppState, JoinProject, ToggleFollow, Workspace};
pub fn init(app_state: Arc<AppState>, cx: &mut MutableAppContext) { pub fn init(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
contact_notification::init(cx);
contact_finder::init(cx);
contacts_popover::init(cx); contacts_popover::init(cx);
collab_titlebar_item::init(cx); collab_titlebar_item::init(cx);
incoming_call_notification::init(cx); incoming_call_notification::init(cx);

View file

@ -9,8 +9,6 @@ use std::sync::Arc;
use util::TryFutureExt; use util::TryFutureExt;
use workspace::Workspace; use workspace::Workspace;
use crate::render_icon_button;
actions!(contact_finder, [Toggle]); actions!(contact_finder, [Toggle]);
pub fn init(cx: &mut MutableAppContext) { pub fn init(cx: &mut MutableAppContext) {
@ -117,11 +115,10 @@ impl PickerDelegate for ContactFinder {
let icon_path = match request_status { let icon_path = match request_status {
ContactRequestStatus::None | ContactRequestStatus::RequestReceived => { ContactRequestStatus::None | ContactRequestStatus::RequestReceived => {
"icons/check_8.svg" Some("icons/check_8.svg")
}
ContactRequestStatus::RequestSent | ContactRequestStatus::RequestAccepted => {
"icons/x_mark_8.svg"
} }
ContactRequestStatus::RequestSent => Some("icons/x_mark_8.svg"),
ContactRequestStatus::RequestAccepted => None,
}; };
let button_style = if self.user_store.read(cx).is_contact_request_pending(user) { let button_style = if self.user_store.read(cx).is_contact_request_pending(user) {
&theme.contact_finder.disabled_contact_button &theme.contact_finder.disabled_contact_button
@ -145,12 +142,21 @@ impl PickerDelegate for ContactFinder {
.left() .left()
.boxed(), .boxed(),
) )
.with_child( .with_children(icon_path.map(|icon_path| {
render_icon_button(button_style, icon_path) Svg::new(icon_path)
.with_color(button_style.color)
.constrained()
.with_width(button_style.icon_width)
.aligned()
.contained()
.with_style(button_style.container)
.constrained()
.with_width(button_style.button_width)
.with_height(button_style.button_width)
.aligned() .aligned()
.flex_float() .flex_float()
.boxed(), .boxed()
) }))
.contained() .contained()
.with_style(style.container) .with_style(style.container)
.constrained() .constrained()

View file

@ -49,10 +49,7 @@ impl View for ContactNotification {
self.user.clone(), self.user.clone(),
"wants to add you as a contact", "wants to add you as a contact",
Some("They won't know if you decline."), Some("They won't know if you decline."),
RespondToContactRequest { Dismiss(self.user.id),
user_id: self.user.id,
accept: false,
},
vec![ vec![
( (
"Decline", "Decline",

View file

@ -1,22 +1,27 @@
use std::sync::Arc; use std::sync::Arc;
use crate::contact_finder;
use call::ActiveCall; use call::ActiveCall;
use client::{Contact, User, UserStore}; use client::{Contact, User, UserStore};
use editor::{Cancel, Editor}; use editor::{Cancel, Editor};
use fuzzy::{match_strings, StringMatchCandidate}; use fuzzy::{match_strings, StringMatchCandidate};
use gpui::{ use gpui::{
elements::*, impl_internal_actions, keymap, AppContext, ClipboardItem, CursorStyle, Entity, elements::*, impl_actions, impl_internal_actions, keymap, AppContext, ClipboardItem,
ModelHandle, MouseButton, MutableAppContext, RenderContext, Subscription, View, ViewContext, CursorStyle, Entity, ModelHandle, MouseButton, MutableAppContext, RenderContext, Subscription,
ViewHandle, View, ViewContext, ViewHandle,
}; };
use menu::{Confirm, SelectNext, SelectPrev}; use menu::{Confirm, SelectNext, SelectPrev};
use project::Project; use project::Project;
use serde::Deserialize;
use settings::Settings; use settings::Settings;
use theme::IconButton; use theme::IconButton;
impl_internal_actions!(contacts_panel, [ToggleExpanded, Call]); impl_actions!(contacts_popover, [RemoveContact, RespondToContactRequest]);
impl_internal_actions!(contacts_popover, [ToggleExpanded, Call]);
pub fn init(cx: &mut MutableAppContext) { pub fn init(cx: &mut MutableAppContext) {
cx.add_action(ContactsPopover::remove_contact);
cx.add_action(ContactsPopover::respond_to_contact_request);
cx.add_action(ContactsPopover::clear_filter); cx.add_action(ContactsPopover::clear_filter);
cx.add_action(ContactsPopover::select_next); cx.add_action(ContactsPopover::select_next);
cx.add_action(ContactsPopover::select_prev); cx.add_action(ContactsPopover::select_prev);
@ -77,6 +82,18 @@ impl PartialEq for ContactEntry {
} }
} }
#[derive(Clone, Deserialize, PartialEq)]
pub struct RequestContact(pub u64);
#[derive(Clone, Deserialize, PartialEq)]
pub struct RemoveContact(pub u64);
#[derive(Clone, Deserialize, PartialEq)]
pub struct RespondToContactRequest {
pub user_id: u64,
pub accept: bool,
}
pub enum Event { pub enum Event {
Dismissed, Dismissed,
} }
@ -186,6 +203,24 @@ impl ContactsPopover {
this this
} }
fn remove_contact(&mut self, request: &RemoveContact, cx: &mut ViewContext<Self>) {
self.user_store
.update(cx, |store, cx| store.remove_contact(request.0, cx))
.detach();
}
fn respond_to_contact_request(
&mut self,
action: &RespondToContactRequest,
cx: &mut ViewContext<Self>,
) {
self.user_store
.update(cx, |store, cx| {
store.respond_to_contact_request(action.user_id, action.accept, cx)
})
.detach();
}
fn clear_filter(&mut self, _: &Cancel, cx: &mut ViewContext<Self>) { fn clear_filter(&mut self, _: &Cancel, cx: &mut ViewContext<Self>) {
let did_clear = self.filter_editor.update(cx, |editor, cx| { let did_clear = self.filter_editor.update(cx, |editor, cx| {
if editor.buffer().read(cx).len(cx) > 0 { if editor.buffer().read(cx).len(cx) > 0 {
@ -574,18 +609,15 @@ impl ContactsPopover {
}; };
render_icon_button(button_style, "icons/x_mark_8.svg") render_icon_button(button_style, "icons/x_mark_8.svg")
.aligned() .aligned()
// .flex_float()
.boxed() .boxed()
}) })
.with_cursor_style(CursorStyle::PointingHand) .with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, move |_, cx| { .on_click(MouseButton::Left, move |_, cx| {
todo!(); cx.dispatch_action(RespondToContactRequest {
// cx.dispatch_action(RespondToContactRequest { user_id,
// user_id, accept: false,
// accept: false, })
// })
}) })
// .flex_float()
.contained() .contained()
.with_margin_right(button_spacing) .with_margin_right(button_spacing)
.boxed(), .boxed(),
@ -602,11 +634,10 @@ impl ContactsPopover {
}) })
.with_cursor_style(CursorStyle::PointingHand) .with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, move |_, cx| { .on_click(MouseButton::Left, move |_, cx| {
todo!() cx.dispatch_action(RespondToContactRequest {
// cx.dispatch_action(RespondToContactRequest { user_id,
// user_id, accept: true,
// accept: true, })
// })
}) })
.boxed(), .boxed(),
]); ]);
@ -626,8 +657,7 @@ impl ContactsPopover {
.with_padding(Padding::uniform(2.)) .with_padding(Padding::uniform(2.))
.with_cursor_style(CursorStyle::PointingHand) .with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, move |_, cx| { .on_click(MouseButton::Left, move |_, cx| {
todo!() cx.dispatch_action(RemoveContact(user_id))
// cx.dispatch_action(RemoveContact(user_id))
}) })
.flex_float() .flex_float()
.boxed(), .boxed(),
@ -692,8 +722,7 @@ impl View for ContactsPopover {
}) })
.with_cursor_style(CursorStyle::PointingHand) .with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, |_, cx| { .on_click(MouseButton::Left, |_, cx| {
todo!() cx.dispatch_action(contact_finder::Toggle)
// cx.dispatch_action(contact_finder::Toggle)
}) })
.boxed(), .boxed(),
) )

View file

@ -1,9 +1,7 @@
use crate::render_icon_button;
use client::User; use client::User;
use gpui::{ use gpui::{
elements::{Flex, Image, Label, MouseEventHandler, Padding, ParentElement, Text}, elements::*, platform::CursorStyle, Action, Element, ElementBox, MouseButton, RenderContext,
platform::CursorStyle, View,
Action, Element, ElementBox, MouseButton, RenderContext, View,
}; };
use settings::Settings; use settings::Settings;
use std::sync::Arc; use std::sync::Arc;
@ -53,10 +51,17 @@ pub fn render_user_notification<V: View, A: Action + Clone>(
) )
.with_child( .with_child(
MouseEventHandler::<Dismiss>::new(user.id as usize, cx, |state, _| { MouseEventHandler::<Dismiss>::new(user.id as usize, cx, |state, _| {
render_icon_button( let style = theme.dismiss_button.style_for(state, false);
theme.dismiss_button.style_for(state, false), Svg::new("icons/x_mark_thin_8.svg")
"icons/x_mark_thin_8.svg", .with_color(style.color)
) .constrained()
.with_width(style.icon_width)
.aligned()
.contained()
.with_style(style.container)
.constrained()
.with_width(style.button_width)
.with_height(style.button_width)
.boxed() .boxed()
}) })
.with_cursor_style(CursorStyle::PointingHand) .with_cursor_style(CursorStyle::PointingHand)

View file

@ -1,32 +0,0 @@
[package]
name = "contacts_panel"
version = "0.1.0"
edition = "2021"
[lib]
path = "src/contacts_panel.rs"
doctest = false
[dependencies]
client = { path = "../client" }
collections = { path = "../collections" }
editor = { path = "../editor" }
fuzzy = { path = "../fuzzy" }
gpui = { path = "../gpui" }
menu = { path = "../menu" }
picker = { path = "../picker" }
project = { path = "../project" }
settings = { path = "../settings" }
theme = { path = "../theme" }
util = { path = "../util" }
workspace = { path = "../workspace" }
anyhow = "1.0"
futures = "0.3"
log = "0.4"
postage = { version = "0.4.1", features = ["futures-traits"] }
serde = { version = "1.0", features = ["derive", "rc"] }
[dev-dependencies]
language = { path = "../language", features = ["test-support"] }
project = { path = "../project", features = ["test-support"] }
workspace = { path = "../workspace", features = ["test-support"] }

File diff suppressed because it is too large Load diff

View file

@ -78,6 +78,7 @@ pub struct Titlebar {
pub outdated_warning: ContainedText, pub outdated_warning: ContainedText,
pub share_button: Interactive<ContainedText>, pub share_button: Interactive<ContainedText>,
pub toggle_contacts_button: Interactive<IconButton>, pub toggle_contacts_button: Interactive<IconButton>,
pub toggle_contacts_badge: ContainerStyle,
pub contacts_popover: AddParticipantPopover, pub contacts_popover: AddParticipantPopover,
} }

View file

@ -28,7 +28,6 @@ command_palette = { path = "../command_palette" }
context_menu = { path = "../context_menu" } context_menu = { path = "../context_menu" }
client = { path = "../client" } client = { path = "../client" }
clock = { path = "../clock" } clock = { path = "../clock" }
contacts_panel = { path = "../contacts_panel" }
diagnostics = { path = "../diagnostics" } diagnostics = { path = "../diagnostics" }
editor = { path = "../editor" } editor = { path = "../editor" }
file_finder = { path = "../file_finder" } file_finder = { path = "../file_finder" }

View file

@ -112,7 +112,6 @@ fn main() {
go_to_line::init(cx); go_to_line::init(cx);
file_finder::init(cx); file_finder::init(cx);
chat_panel::init(cx); chat_panel::init(cx);
contacts_panel::init(cx);
outline::init(cx); outline::init(cx);
project_symbols::init(cx); project_symbols::init(cx);
project_panel::init(cx); project_panel::init(cx);

View file

@ -244,10 +244,6 @@ pub fn menus() -> Vec<Menu<'static>> {
name: "Project Panel", name: "Project Panel",
action: Box::new(project_panel::ToggleFocus), action: Box::new(project_panel::ToggleFocus),
}, },
MenuItem::Action {
name: "Contacts Panel",
action: Box::new(contacts_panel::ToggleFocus),
},
MenuItem::Action { MenuItem::Action {
name: "Command Palette", name: "Command Palette",
action: Box::new(command_palette::Toggle), action: Box::new(command_palette::Toggle),

View file

@ -12,8 +12,6 @@ use breadcrumbs::Breadcrumbs;
pub use client; pub use client;
use collab_ui::CollabTitlebarItem; use collab_ui::CollabTitlebarItem;
use collections::VecDeque; use collections::VecDeque;
pub use contacts_panel;
use contacts_panel::ContactsPanel;
pub use editor; pub use editor;
use editor::{Editor, MultiBuffer}; use editor::{Editor, MultiBuffer};
use gpui::{ use gpui::{
@ -208,13 +206,6 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::MutableAppContext) {
workspace.toggle_sidebar_item_focus(SidebarSide::Left, 0, cx); workspace.toggle_sidebar_item_focus(SidebarSide::Left, 0, cx);
}, },
); );
cx.add_action(
|workspace: &mut Workspace,
_: &contacts_panel::ToggleFocus,
cx: &mut ViewContext<Workspace>| {
workspace.toggle_sidebar_item_focus(SidebarSide::Right, 0, cx);
},
);
activity_indicator::init(cx); activity_indicator::init(cx);
call::init(app_state.client.clone(), app_state.user_store.clone(), cx); call::init(app_state.client.clone(), app_state.user_store.clone(), cx);
@ -281,14 +272,11 @@ pub fn initialize_workspace(
})); }));
}); });
let collab_titlebar_item = cx.add_view(|cx| CollabTitlebarItem::new(&workspace_handle, cx)); let collab_titlebar_item =
cx.add_view(|cx| CollabTitlebarItem::new(&workspace_handle, &app_state.user_store, cx));
workspace.set_titlebar_item(collab_titlebar_item, cx); workspace.set_titlebar_item(collab_titlebar_item, cx);
let project_panel = ProjectPanel::new(workspace.project().clone(), cx); let project_panel = ProjectPanel::new(workspace.project().clone(), cx);
let contact_panel = cx.add_view(|cx| {
ContactsPanel::new(app_state.user_store.clone(), workspace.weak_handle(), cx)
});
workspace.left_sidebar().update(cx, |sidebar, cx| { workspace.left_sidebar().update(cx, |sidebar, cx| {
sidebar.add_item( sidebar.add_item(
"icons/folder_tree_16.svg", "icons/folder_tree_16.svg",
@ -297,14 +285,6 @@ pub fn initialize_workspace(
cx, cx,
) )
}); });
workspace.right_sidebar().update(cx, |sidebar, cx| {
sidebar.add_item(
"icons/user_group_16.svg",
"Contacts Panel".to_string(),
contact_panel,
cx,
)
});
let diagnostic_summary = let diagnostic_summary =
cx.add_view(|cx| diagnostics::items::DiagnosticIndicator::new(workspace.project(), cx)); cx.add_view(|cx| diagnostics::items::DiagnosticIndicator::new(workspace.project(), cx));

View file

@ -144,6 +144,13 @@ export default function workspace(theme: Theme) {
color: iconColor(theme, "active"), color: iconColor(theme, "active"),
}, },
}, },
toggleContactsBadge: {
cornerRadius: 3,
padding: 2,
margin: { top: 3, left: 3 },
border: { width: 1, color: workspaceBackground(theme) },
background: iconColor(theme, "feature"),
},
shareButton: { shareButton: {
...titlebarButton ...titlebarButton
}, },