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",
"log",
"menu",
"picker",
"postage",
"project",
"serde",
@ -1141,30 +1142,6 @@ dependencies = [
"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]]
name = "context_menu"
version = "0.1.0"
@ -7165,7 +7142,6 @@ dependencies = [
"collab_ui",
"collections",
"command_palette",
"contacts_panel",
"context_menu",
"ctor",
"diagnostics",

View File

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

View File

@ -29,6 +29,7 @@ editor = { path = "../editor" }
fuzzy = { path = "../fuzzy" }
gpui = { path = "../gpui" }
menu = { path = "../menu" }
picker = { path = "../picker" }
project = { path = "../project" }
settings = { path = "../settings" }
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 client::{Authenticate, PeerId};
use client::{Authenticate, ContactEventKind, PeerId, UserStore};
use clock::ReplicaId;
use contacts_popover::ContactsPopover;
use gpui::{
@ -9,8 +9,8 @@ use gpui::{
elements::*,
geometry::{rect::RectF, vector::vec2f, PathBuilder},
json::{self, ToJson},
Border, CursorStyle, Entity, ImageData, MouseButton, MutableAppContext, RenderContext,
Subscription, View, ViewContext, ViewHandle, WeakViewHandle,
Border, CursorStyle, Entity, ImageData, ModelHandle, MouseButton, MutableAppContext,
RenderContext, Subscription, View, ViewContext, ViewHandle, WeakViewHandle,
};
use settings::Settings;
use std::{ops::Range, sync::Arc};
@ -29,6 +29,7 @@ pub fn init(cx: &mut MutableAppContext) {
pub struct CollabTitlebarItem {
workspace: WeakViewHandle<Workspace>,
user_store: ModelHandle<UserStore>,
contacts_popover: Option<ViewHandle<ContactsPopover>>,
_subscriptions: Vec<Subscription>,
}
@ -71,7 +72,11 @@ impl View for 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 mut subscriptions = Vec::new();
subscriptions.push(cx.observe(workspace, |_, _, cx| cx.notify()));
@ -79,9 +84,33 @@ impl CollabTitlebarItem {
subscriptions.push(cx.observe_window_activation(|this, 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 {
workspace: workspace.downgrade(),
user_store: user_store.clone(),
contacts_popover: None,
_subscriptions: subscriptions,
}
@ -160,6 +189,26 @@ impl CollabTitlebarItem {
cx: &mut RenderContext<Self>,
) -> ElementBox {
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()
.with_child(
MouseEventHandler::<ToggleContactsPopover>::new(0, cx, |state, _| {
@ -185,6 +234,7 @@ impl CollabTitlebarItem {
.aligned()
.boxed(),
)
.with_children(badge)
.with_children(self.contacts_popover.as_ref().map(|popover| {
Overlay::new(
ChildView::new(popover)

View File

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

View File

@ -9,8 +9,6 @@ use std::sync::Arc;
use util::TryFutureExt;
use workspace::Workspace;
use crate::render_icon_button;
actions!(contact_finder, [Toggle]);
pub fn init(cx: &mut MutableAppContext) {
@ -117,11 +115,10 @@ impl PickerDelegate for ContactFinder {
let icon_path = match request_status {
ContactRequestStatus::None | ContactRequestStatus::RequestReceived => {
"icons/check_8.svg"
}
ContactRequestStatus::RequestSent | ContactRequestStatus::RequestAccepted => {
"icons/x_mark_8.svg"
Some("icons/check_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) {
&theme.contact_finder.disabled_contact_button
@ -145,12 +142,21 @@ impl PickerDelegate for ContactFinder {
.left()
.boxed(),
)
.with_child(
render_icon_button(button_style, icon_path)
.with_children(icon_path.map(|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()
.flex_float()
.boxed(),
)
.boxed()
}))
.contained()
.with_style(style.container)
.constrained()

View File

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

View File

@ -1,22 +1,27 @@
use std::sync::Arc;
use crate::contact_finder;
use call::ActiveCall;
use client::{Contact, User, UserStore};
use editor::{Cancel, Editor};
use fuzzy::{match_strings, StringMatchCandidate};
use gpui::{
elements::*, impl_internal_actions, keymap, AppContext, ClipboardItem, CursorStyle, Entity,
ModelHandle, MouseButton, MutableAppContext, RenderContext, Subscription, View, ViewContext,
ViewHandle,
elements::*, impl_actions, impl_internal_actions, keymap, AppContext, ClipboardItem,
CursorStyle, Entity, ModelHandle, MouseButton, MutableAppContext, RenderContext, Subscription,
View, ViewContext, ViewHandle,
};
use menu::{Confirm, SelectNext, SelectPrev};
use project::Project;
use serde::Deserialize;
use settings::Settings;
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) {
cx.add_action(ContactsPopover::remove_contact);
cx.add_action(ContactsPopover::respond_to_contact_request);
cx.add_action(ContactsPopover::clear_filter);
cx.add_action(ContactsPopover::select_next);
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 {
Dismissed,
}
@ -186,6 +203,24 @@ impl ContactsPopover {
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>) {
let did_clear = self.filter_editor.update(cx, |editor, cx| {
if editor.buffer().read(cx).len(cx) > 0 {
@ -574,18 +609,15 @@ impl ContactsPopover {
};
render_icon_button(button_style, "icons/x_mark_8.svg")
.aligned()
// .flex_float()
.boxed()
})
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, move |_, cx| {
todo!();
// cx.dispatch_action(RespondToContactRequest {
// user_id,
// accept: false,
// })
cx.dispatch_action(RespondToContactRequest {
user_id,
accept: false,
})
})
// .flex_float()
.contained()
.with_margin_right(button_spacing)
.boxed(),
@ -602,11 +634,10 @@ impl ContactsPopover {
})
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, move |_, cx| {
todo!()
// cx.dispatch_action(RespondToContactRequest {
// user_id,
// accept: true,
// })
cx.dispatch_action(RespondToContactRequest {
user_id,
accept: true,
})
})
.boxed(),
]);
@ -626,8 +657,7 @@ impl ContactsPopover {
.with_padding(Padding::uniform(2.))
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, move |_, cx| {
todo!()
// cx.dispatch_action(RemoveContact(user_id))
cx.dispatch_action(RemoveContact(user_id))
})
.flex_float()
.boxed(),
@ -692,8 +722,7 @@ impl View for ContactsPopover {
})
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, |_, cx| {
todo!()
// cx.dispatch_action(contact_finder::Toggle)
cx.dispatch_action(contact_finder::Toggle)
})
.boxed(),
)

View File

@ -1,9 +1,7 @@
use crate::render_icon_button;
use client::User;
use gpui::{
elements::{Flex, Image, Label, MouseEventHandler, Padding, ParentElement, Text},
platform::CursorStyle,
Action, Element, ElementBox, MouseButton, RenderContext, View,
elements::*, platform::CursorStyle, Action, Element, ElementBox, MouseButton, RenderContext,
View,
};
use settings::Settings;
use std::sync::Arc;
@ -53,11 +51,18 @@ pub fn render_user_notification<V: View, A: Action + Clone>(
)
.with_child(
MouseEventHandler::<Dismiss>::new(user.id as usize, cx, |state, _| {
render_icon_button(
theme.dismiss_button.style_for(state, false),
"icons/x_mark_thin_8.svg",
)
.boxed()
let style = theme.dismiss_button.style_for(state, false);
Svg::new("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()
})
.with_cursor_style(CursorStyle::PointingHand)
.with_padding(Padding::uniform(5.))

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 share_button: Interactive<ContainedText>,
pub toggle_contacts_button: Interactive<IconButton>,
pub toggle_contacts_badge: ContainerStyle,
pub contacts_popover: AddParticipantPopover,
}

View File

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

View File

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

View File

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

View File

@ -12,8 +12,6 @@ use breadcrumbs::Breadcrumbs;
pub use client;
use collab_ui::CollabTitlebarItem;
use collections::VecDeque;
pub use contacts_panel;
use contacts_panel::ContactsPanel;
pub use editor;
use editor::{Editor, MultiBuffer};
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);
},
);
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);
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);
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| {
sidebar.add_item(
"icons/folder_tree_16.svg",
@ -297,14 +285,6 @@ pub fn initialize_workspace(
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 =
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"),
},
},
toggleContactsBadge: {
cornerRadius: 3,
padding: 2,
margin: { top: 3, left: 3 },
border: { width: 1, color: workspaceBackground(theme) },
background: iconColor(theme, "feature"),
},
shareButton: {
...titlebarButton
},