zed2: Port ProjectSharedNotification
This commit is contained in:
parent
853daf953b
commit
f3cbce7e86
3 changed files with 97 additions and 256 deletions
|
@ -3,9 +3,9 @@ use std::sync::Arc;
|
||||||
use workspace::AppState;
|
use workspace::AppState;
|
||||||
|
|
||||||
pub mod incoming_call_notification;
|
pub mod incoming_call_notification;
|
||||||
// pub mod project_shared_notification;
|
pub mod project_shared_notification;
|
||||||
|
|
||||||
pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
|
pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
|
||||||
incoming_call_notification::init(app_state, cx);
|
incoming_call_notification::init(app_state, cx);
|
||||||
//project_shared_notification::init(app_state, cx);
|
project_shared_notification::init(app_state, cx);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,8 +33,8 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
|
||||||
height: px(64.),
|
height: px(64.),
|
||||||
};
|
};
|
||||||
|
|
||||||
for window in unique_screens {
|
for screen in unique_screens {
|
||||||
let options = notification_window_options(window, window_size);
|
let options = notification_window_options(screen, window_size);
|
||||||
let window = cx
|
let window = cx
|
||||||
.open_window(options, |cx| {
|
.open_window(options, |cx| {
|
||||||
cx.build_view(|_| {
|
cx.build_view(|_| {
|
||||||
|
@ -47,15 +47,6 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
notification_windows.push(window);
|
notification_windows.push(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
// for screen in cx.platform().screens() {
|
|
||||||
// let window = cx
|
|
||||||
// .add_window(notification_window_options(screen, window_size), |_| {
|
|
||||||
// IncomingCallNotification::new(incoming_call.clone(), app_state.clone())
|
|
||||||
// });
|
|
||||||
|
|
||||||
// notification_windows.push(window);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -84,21 +75,22 @@ impl IncomingCallNotificationState {
|
||||||
let active_call = ActiveCall::global(cx);
|
let active_call = ActiveCall::global(cx);
|
||||||
if accept {
|
if accept {
|
||||||
let join = active_call.update(cx, |active_call, cx| active_call.accept_incoming(cx));
|
let join = active_call.update(cx, |active_call, cx| active_call.accept_incoming(cx));
|
||||||
|
let caller_user_id = self.call.calling_user.id;
|
||||||
let initial_project_id = self.call.initial_project.as_ref().map(|project| project.id);
|
let initial_project_id = self.call.initial_project.as_ref().map(|project| project.id);
|
||||||
let app_state = self.app_state.clone();
|
let app_state = self.app_state.clone();
|
||||||
let cx: &mut AppContext = cx;
|
let cx: &mut AppContext = cx;
|
||||||
cx.spawn(|cx| async move {
|
cx.spawn(|cx| async move {
|
||||||
join.await?;
|
join.await?;
|
||||||
if let Some(_project_id) = initial_project_id {
|
if let Some(project_id) = initial_project_id {
|
||||||
cx.update(|_cx| {
|
cx.update(|cx| {
|
||||||
if let Some(_app_state) = app_state.upgrade() {
|
if let Some(app_state) = app_state.upgrade() {
|
||||||
// workspace::join_remote_project(
|
workspace::join_remote_project(
|
||||||
// project_id,
|
project_id,
|
||||||
// caller_user_id,
|
caller_user_id,
|
||||||
// app_state,
|
app_state,
|
||||||
// cx,
|
cx,
|
||||||
// )
|
)
|
||||||
// .detach_and_log_err(cx);
|
.detach_and_log_err(cx);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.log_err();
|
.log_err();
|
||||||
|
@ -138,135 +130,25 @@ impl IncomingCallNotification {
|
||||||
)))
|
)))
|
||||||
.child(self.render_buttons(cx)),
|
.child(self.render_buttons(cx)),
|
||||||
)
|
)
|
||||||
// let theme = &theme::current(cx).incoming_call_notification;
|
|
||||||
// let default_project = proto::ParticipantProject::default();
|
|
||||||
// let initial_project = self
|
|
||||||
// .call
|
|
||||||
// .initial_project
|
|
||||||
// .as_ref()
|
|
||||||
// .unwrap_or(&default_project);
|
|
||||||
// Flex::row()
|
|
||||||
// .with_children(self.call.calling_user.avatar.clone().map(|avatar| {
|
|
||||||
// Image::from_data(avatar)
|
|
||||||
// .with_style(theme.caller_avatar)
|
|
||||||
// .aligned()
|
|
||||||
// }))
|
|
||||||
// .with_child(
|
|
||||||
// Flex::column()
|
|
||||||
// .with_child(
|
|
||||||
// Label::new(
|
|
||||||
// self.call.calling_user.github_login.clone(),
|
|
||||||
// theme.caller_username.text.clone(),
|
|
||||||
// )
|
|
||||||
// .contained()
|
|
||||||
// .with_style(theme.caller_username.container),
|
|
||||||
// )
|
|
||||||
// .with_child(
|
|
||||||
// Label::new(
|
|
||||||
// format!(
|
|
||||||
// "is sharing a project in Zed{}",
|
|
||||||
// if initial_project.worktree_root_names.is_empty() {
|
|
||||||
// ""
|
|
||||||
// } else {
|
|
||||||
// ":"
|
|
||||||
// }
|
|
||||||
// ),
|
|
||||||
// theme.caller_message.text.clone(),
|
|
||||||
// )
|
|
||||||
// .contained()
|
|
||||||
// .with_style(theme.caller_message.container),
|
|
||||||
// )
|
|
||||||
// .with_children(if initial_project.worktree_root_names.is_empty() {
|
|
||||||
// None
|
|
||||||
// } else {
|
|
||||||
// Some(
|
|
||||||
// Label::new(
|
|
||||||
// initial_project.worktree_root_names.join(", "),
|
|
||||||
// theme.worktree_roots.text.clone(),
|
|
||||||
// )
|
|
||||||
// .contained()
|
|
||||||
// .with_style(theme.worktree_roots.container),
|
|
||||||
// )
|
|
||||||
// })
|
|
||||||
// .contained()
|
|
||||||
// .with_style(theme.caller_metadata)
|
|
||||||
// .aligned(),
|
|
||||||
// )
|
|
||||||
// .contained()
|
|
||||||
// .with_style(theme.caller_container)
|
|
||||||
// .flex(1., true)
|
|
||||||
// .into_any()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_buttons(&self, cx: &mut ViewContext<Self>) -> impl Element {
|
fn render_buttons(&self, cx: &mut ViewContext<Self>) -> impl Element {
|
||||||
h_stack()
|
h_stack()
|
||||||
.child(
|
.child(Button::new("accept", "Accept").render(cx).on_click({
|
||||||
Button::new("accept", "Accept")
|
let state = self.state.clone();
|
||||||
.render(cx)
|
move |_, cx| state.respond(true, cx)
|
||||||
// .bg(green())
|
}))
|
||||||
.on_click({
|
.child(Button::new("decline", "Decline").render(cx).on_click({
|
||||||
let state = self.state.clone();
|
let state = self.state.clone();
|
||||||
move |_, cx| state.respond(true, cx)
|
move |_, cx| state.respond(false, cx)
|
||||||
}),
|
}))
|
||||||
)
|
|
||||||
.child(
|
|
||||||
Button::new("decline", "Decline")
|
|
||||||
.render(cx)
|
|
||||||
// .bg(red())
|
|
||||||
.on_click({
|
|
||||||
let state = self.state.clone();
|
|
||||||
move |_, cx| state.respond(false, cx)
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
|
|
||||||
// enum Accept {}
|
|
||||||
// enum Decline {}
|
|
||||||
|
|
||||||
// let theme = theme::current(cx);
|
|
||||||
// Flex::column()
|
|
||||||
// .with_child(
|
|
||||||
// MouseEventHandler::new::<Accept, _>(0, cx, |_, _| {
|
|
||||||
// let theme = &theme.incoming_call_notification;
|
|
||||||
// Label::new("Accept", theme.accept_button.text.clone())
|
|
||||||
// .aligned()
|
|
||||||
// .contained()
|
|
||||||
// .with_style(theme.accept_button.container)
|
|
||||||
// })
|
|
||||||
// .with_cursor_style(CursorStyle::PointingHand)
|
|
||||||
// .on_click(MouseButton::Left, |_, this, cx| {
|
|
||||||
// this.respond(true, cx);
|
|
||||||
// })
|
|
||||||
// .flex(1., true),
|
|
||||||
// )
|
|
||||||
// .with_child(
|
|
||||||
// MouseEventHandler::new::<Decline, _>(0, cx, |_, _| {
|
|
||||||
// let theme = &theme.incoming_call_notification;
|
|
||||||
// Label::new("Decline", theme.decline_button.text.clone())
|
|
||||||
// .aligned()
|
|
||||||
// .contained()
|
|
||||||
// .with_style(theme.decline_button.container)
|
|
||||||
// })
|
|
||||||
// .with_cursor_style(CursorStyle::PointingHand)
|
|
||||||
// .on_click(MouseButton::Left, |_, this, cx| {
|
|
||||||
// this.respond(false, cx);
|
|
||||||
// })
|
|
||||||
// .flex(1., true),
|
|
||||||
// )
|
|
||||||
// .constrained()
|
|
||||||
// .with_width(theme.incoming_call_notification.button_width)
|
|
||||||
// .into_any()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Render for IncomingCallNotification {
|
impl Render for IncomingCallNotification {
|
||||||
type Element = Div;
|
type Element = Div;
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||||
div().bg(red()).flex_none().child(self.render_caller(cx))
|
div().bg(red()).flex_none().child(self.render_caller(cx))
|
||||||
// Flex::row()
|
|
||||||
// .with_child()
|
|
||||||
// .with_child(self.render_buttons(cx))
|
|
||||||
// .contained()
|
|
||||||
// .with_background_color(background)
|
|
||||||
// .expanded()
|
|
||||||
// .into_any()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,11 @@ use call::{room, ActiveCall};
|
||||||
use client::User;
|
use client::User;
|
||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
elements::*,
|
px, AppContext, Div, Element, ParentElement, Render, RenderOnce, Size, Styled, ViewContext,
|
||||||
geometry::vector::vec2f,
|
VisualContext,
|
||||||
platform::{CursorStyle, MouseButton},
|
|
||||||
AppContext, Entity, View, ViewContext,
|
|
||||||
};
|
};
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
|
use ui::{h_stack, v_stack, Avatar, Button, Clickable, Label};
|
||||||
use workspace::AppState;
|
use workspace::AppState;
|
||||||
|
|
||||||
pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
|
pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
|
||||||
|
@ -21,38 +20,54 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
|
||||||
project_id,
|
project_id,
|
||||||
worktree_root_names,
|
worktree_root_names,
|
||||||
} => {
|
} => {
|
||||||
let theme = &theme::current(cx).project_shared_notification;
|
let window_size = Size {
|
||||||
let window_size = vec2f(theme.window_width, theme.window_height);
|
width: px(380.),
|
||||||
|
height: px(64.),
|
||||||
|
};
|
||||||
|
|
||||||
for screen in cx.platform().screens() {
|
for screen in cx.displays() {
|
||||||
let window =
|
let options = notification_window_options(screen, window_size);
|
||||||
cx.add_window(notification_window_options(screen, window_size), |_| {
|
let window = cx.open_window(options, |cx| {
|
||||||
|
cx.build_view(|_| {
|
||||||
ProjectSharedNotification::new(
|
ProjectSharedNotification::new(
|
||||||
owner.clone(),
|
owner.clone(),
|
||||||
*project_id,
|
*project_id,
|
||||||
worktree_root_names.clone(),
|
worktree_root_names.clone(),
|
||||||
app_state.clone(),
|
app_state.clone(),
|
||||||
)
|
)
|
||||||
});
|
})
|
||||||
|
});
|
||||||
notification_windows
|
notification_windows
|
||||||
.entry(*project_id)
|
.entry(*project_id)
|
||||||
.or_insert(Vec::new())
|
.or_insert(Vec::new())
|
||||||
.push(window);
|
.push(window);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
room::Event::RemoteProjectUnshared { project_id }
|
room::Event::RemoteProjectUnshared { project_id }
|
||||||
| room::Event::RemoteProjectJoined { project_id }
|
| room::Event::RemoteProjectJoined { project_id }
|
||||||
| room::Event::RemoteProjectInvitationDiscarded { project_id } => {
|
| room::Event::RemoteProjectInvitationDiscarded { project_id } => {
|
||||||
if let Some(windows) = notification_windows.remove(&project_id) {
|
if let Some(windows) = notification_windows.remove(&project_id) {
|
||||||
for window in windows {
|
for window in windows {
|
||||||
window.remove(cx);
|
window
|
||||||
|
.update(cx, |_, cx| {
|
||||||
|
// todo!()
|
||||||
|
cx.remove_window();
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
room::Event::Left => {
|
room::Event::Left => {
|
||||||
for (_, windows) in notification_windows.drain() {
|
for (_, windows) in notification_windows.drain() {
|
||||||
for window in windows {
|
for window in windows {
|
||||||
window.remove(cx);
|
window
|
||||||
|
.update(cx, |_, cx| {
|
||||||
|
// todo!()
|
||||||
|
cx.remove_window();
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,116 +117,60 @@ impl ProjectSharedNotification {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_owner(&self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
|
fn render_owner(&self) -> impl Element {
|
||||||
let theme = &theme::current(cx).project_shared_notification;
|
h_stack()
|
||||||
Flex::row()
|
.children(
|
||||||
.with_children(self.owner.avatar.clone().map(|avatar| {
|
self.owner
|
||||||
Image::from_data(avatar)
|
.avatar
|
||||||
.with_style(theme.owner_avatar)
|
.clone()
|
||||||
.aligned()
|
.map(|avatar| Avatar::data(avatar.clone())),
|
||||||
}))
|
)
|
||||||
.with_child(
|
.child(
|
||||||
Flex::column()
|
v_stack()
|
||||||
.with_child(
|
.child(Label::new(self.owner.github_login.clone()))
|
||||||
Label::new(
|
.child(Label::new(format!(
|
||||||
self.owner.github_login.clone(),
|
"is sharing a project in Zed{}",
|
||||||
theme.owner_username.text.clone(),
|
if self.worktree_root_names.is_empty() {
|
||||||
)
|
""
|
||||||
.contained()
|
} else {
|
||||||
.with_style(theme.owner_username.container),
|
":"
|
||||||
)
|
}
|
||||||
.with_child(
|
)))
|
||||||
Label::new(
|
.children(if self.worktree_root_names.is_empty() {
|
||||||
format!(
|
|
||||||
"is sharing a project in Zed{}",
|
|
||||||
if self.worktree_root_names.is_empty() {
|
|
||||||
""
|
|
||||||
} else {
|
|
||||||
":"
|
|
||||||
}
|
|
||||||
),
|
|
||||||
theme.message.text.clone(),
|
|
||||||
)
|
|
||||||
.contained()
|
|
||||||
.with_style(theme.message.container),
|
|
||||||
)
|
|
||||||
.with_children(if self.worktree_root_names.is_empty() {
|
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(
|
Some(Label::new(self.worktree_root_names.join(", ")))
|
||||||
Label::new(
|
}),
|
||||||
self.worktree_root_names.join(", "),
|
|
||||||
theme.worktree_roots.text.clone(),
|
|
||||||
)
|
|
||||||
.contained()
|
|
||||||
.with_style(theme.worktree_roots.container),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.contained()
|
|
||||||
.with_style(theme.owner_metadata)
|
|
||||||
.aligned(),
|
|
||||||
)
|
)
|
||||||
.contained()
|
|
||||||
.with_style(theme.owner_container)
|
|
||||||
.flex(1., true)
|
|
||||||
.into_any()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_buttons(&self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
|
fn render_buttons(&self, cx: &mut ViewContext<Self>) -> impl Element {
|
||||||
enum Open {}
|
let this = cx.view().clone();
|
||||||
enum Dismiss {}
|
v_stack()
|
||||||
|
.child(Button::new("open", "Open").render(cx).on_click({
|
||||||
let theme = theme::current(cx);
|
let this = this.clone();
|
||||||
Flex::column()
|
move |_, cx| {
|
||||||
.with_child(
|
this.update(cx, |this, cx| this.join(cx));
|
||||||
MouseEventHandler::new::<Open, _>(0, cx, |_, _| {
|
}
|
||||||
let theme = &theme.project_shared_notification;
|
}))
|
||||||
Label::new("Open", theme.open_button.text.clone())
|
.child(
|
||||||
.aligned()
|
Button::new("dismiss", "Dismiss")
|
||||||
.contained()
|
.render(cx)
|
||||||
.with_style(theme.open_button.container)
|
.on_click(move |_, cx| {
|
||||||
})
|
this.update(cx, |this, cx| this.dismiss(cx));
|
||||||
.with_cursor_style(CursorStyle::PointingHand)
|
}),
|
||||||
.on_click(MouseButton::Left, move |_, this, cx| this.join(cx))
|
|
||||||
.flex(1., true),
|
|
||||||
)
|
)
|
||||||
.with_child(
|
|
||||||
MouseEventHandler::new::<Dismiss, _>(0, cx, |_, _| {
|
|
||||||
let theme = &theme.project_shared_notification;
|
|
||||||
Label::new("Dismiss", theme.dismiss_button.text.clone())
|
|
||||||
.aligned()
|
|
||||||
.contained()
|
|
||||||
.with_style(theme.dismiss_button.container)
|
|
||||||
})
|
|
||||||
.with_cursor_style(CursorStyle::PointingHand)
|
|
||||||
.on_click(MouseButton::Left, |_, this, cx| {
|
|
||||||
this.dismiss(cx);
|
|
||||||
})
|
|
||||||
.flex(1., true),
|
|
||||||
)
|
|
||||||
.constrained()
|
|
||||||
.with_width(theme.project_shared_notification.button_width)
|
|
||||||
.into_any()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Entity for ProjectSharedNotification {
|
impl Render for ProjectSharedNotification {
|
||||||
type Event = ();
|
type Element = Div;
|
||||||
}
|
|
||||||
|
|
||||||
impl View for ProjectSharedNotification {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||||
fn ui_name() -> &'static str {
|
h_stack()
|
||||||
"ProjectSharedNotification"
|
.size_full()
|
||||||
}
|
.bg(gpui::red())
|
||||||
|
.child(self.render_owner())
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> gpui::AnyElement<Self> {
|
.child(self.render_buttons(cx))
|
||||||
let background = theme::current(cx).project_shared_notification.background;
|
|
||||||
Flex::row()
|
|
||||||
.with_child(self.render_owner(cx))
|
|
||||||
.with_child(self.render_buttons(cx))
|
|
||||||
.contained()
|
|
||||||
.with_background_color(background)
|
|
||||||
.expanded()
|
|
||||||
.into_any()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue