From 5a3a85b2c860f8d3bdb5daa463021f5f8c567632 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Tue, 27 Sep 2022 13:45:11 +0200 Subject: [PATCH] Introduce a `+` button in the titlebar --- .../src/contacts_titlebar_item.rs | 65 ++++++++++++++++++- crates/room/src/room.rs | 18 +---- crates/theme/src/theme.rs | 1 + crates/zed/src/main.rs | 1 + styles/src/styleTree/workspace.ts | 13 +++- 5 files changed, 78 insertions(+), 20 deletions(-) diff --git a/crates/contacts_titlebar_item/src/contacts_titlebar_item.rs b/crates/contacts_titlebar_item/src/contacts_titlebar_item.rs index 7035585a2fccdf54dfc24010849c4a00975ae1e7..a32b2923af4ea83657c64b2130878165a6f07b91 100644 --- a/crates/contacts_titlebar_item/src/contacts_titlebar_item.rs +++ b/crates/contacts_titlebar_item/src/contacts_titlebar_item.rs @@ -4,15 +4,27 @@ use gpui::{ color::Color, elements::*, geometry::{rect::RectF, vector::vec2f, PathBuilder}, + impl_internal_actions, json::{self, ToJson}, - Border, CursorStyle, Entity, ImageData, MouseButton, RenderContext, Subscription, View, - ViewContext, ViewHandle, WeakViewHandle, + Border, CursorStyle, Entity, ImageData, MouseButton, MutableAppContext, RenderContext, + Subscription, View, ViewContext, ViewHandle, WeakViewHandle, }; use settings::Settings; use std::{ops::Range, sync::Arc}; use theme::Theme; use workspace::{FollowNextCollaborator, ToggleFollow, Workspace}; +impl_internal_actions!(contacts_titlebar_item, [ToggleAddContactsPopover]); + +pub fn init(cx: &mut MutableAppContext) { + cx.add_action(ContactsTitlebarItem::toggle_add_contacts_popover); +} + +#[derive(Clone, PartialEq)] +struct ToggleAddContactsPopover { + button_rect: RectF, +} + pub struct ContactsTitlebarItem { workspace: WeakViewHandle, _subscriptions: Vec, @@ -36,6 +48,7 @@ impl View for ContactsTitlebarItem { let theme = cx.global::().theme.clone(); Flex::row() + .with_children(self.render_toggle_contacts_button(&workspace, &theme, cx)) .with_children(self.render_collaborators(&workspace, &theme, cx)) .with_children(self.render_current_user(&workspace, &theme, cx)) .with_children(self.render_connection_status(&workspace, cx)) @@ -52,6 +65,54 @@ impl ContactsTitlebarItem { } } + fn toggle_add_contacts_popover( + &mut self, + _action: &ToggleAddContactsPopover, + _cx: &mut ViewContext, + ) { + dbg!("!!!!!!!!!"); + } + + fn render_toggle_contacts_button( + &self, + workspace: &ViewHandle, + theme: &Theme, + cx: &mut RenderContext, + ) -> Option { + if !workspace.read(cx).client().status().borrow().is_connected() { + return None; + } + + Some( + MouseEventHandler::::new(0, cx, |state, _| { + let style = theme + .workspace + .titlebar + .add_collaborator_button + .style_for(state, false); + Svg::new("icons/plus_8.svg") + .with_color(style.color) + .constrained() + .with_width(style.icon_width) + .aligned() + .constrained() + .with_width(style.button_width) + .with_height(style.button_width) + .contained() + .with_style(style.container) + .boxed() + }) + .with_cursor_style(CursorStyle::PointingHand) + .on_click(MouseButton::Left, |event, cx| { + cx.dispatch_action(ToggleAddContactsPopover { + button_rect: event.region, + }); + }) + .aligned() + .boxed(), + ) + } + fn render_collaborators( &self, workspace: &ViewHandle, diff --git a/crates/room/src/room.rs b/crates/room/src/room.rs index c6daacd7e2d3f5da67a8fdbcabd339c2bc6d1661..82363d4b19868ff7ef9e3a9ee08acc9979799391 100644 --- a/crates/room/src/room.rs +++ b/crates/room/src/room.rs @@ -87,10 +87,10 @@ impl Room { return Err(anyhow!("room is offline")); } + cx.notify(); self.status = RoomStatus::Offline; self.remote_participants.clear(); self.client.send(proto::LeaveRoom { id: self.id })?; - cx.notify(); Ok(()) } @@ -184,22 +184,6 @@ impl Room { todo!() } - - pub fn mute(&mut self) -> Task> { - if self.status.is_offline() { - return Task::ready(Err(anyhow!("room is offline"))); - } - - todo!() - } - - pub fn unmute(&mut self) -> Task> { - if self.status.is_offline() { - return Task::ready(Err(anyhow!("room is offline"))); - } - - todo!() - } } #[derive(Copy, Clone, PartialEq, Eq)] diff --git a/crates/theme/src/theme.rs b/crates/theme/src/theme.rs index 739a4c76869b82b9ab066bb32eff8bb58a0cd253..ca952a27fe9682748e0936822ddbdcbda38e27d4 100644 --- a/crates/theme/src/theme.rs +++ b/crates/theme/src/theme.rs @@ -74,6 +74,7 @@ pub struct Titlebar { pub avatar: ImageStyle, pub sign_in_prompt: Interactive, pub outdated_warning: ContainedText, + pub add_collaborator_button: Interactive, } #[derive(Clone, Deserialize, Default)] diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 3bfd5e6e1a08791e262eab09ad6ede4771382278..aa84d6475b3ae4497da00c1416158d789871b195 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -108,6 +108,7 @@ fn main() { client::Channel::init(&client); client::init(client.clone(), cx); command_palette::init(cx); + contacts_titlebar_item::init(cx); editor::init(cx); go_to_line::init(cx); file_finder::init(cx); diff --git a/styles/src/styleTree/workspace.ts b/styles/src/styleTree/workspace.ts index 9e81a06d3f092f6e0ae716b3975854ead1d80823..0473c974f7e51e7d392121f25e996b717cfe13b5 100644 --- a/styles/src/styleTree/workspace.ts +++ b/styles/src/styleTree/workspace.ts @@ -16,6 +16,7 @@ export function workspaceBackground(theme: Theme) { export default function workspace(theme: Theme) { const titlebarPadding = 6; + const titlebarHeight = 33; return { background: backgroundColor(theme, 300), @@ -54,7 +55,7 @@ export default function workspace(theme: Theme) { titlebar: { avatarWidth: 18, avatarMargin: 8, - height: 33, + height: titlebarHeight, background: backgroundColor(theme, 100), padding: { left: 80, @@ -118,6 +119,16 @@ export default function workspace(theme: Theme) { }, cornerRadius: 6, }, + addCollaboratorButton: { + cornerRadius: 6, + color: iconColor(theme, "secondary"), + iconWidth: 8, + buttonWidth: 20, + hover: { + background: backgroundColor(theme, "on300", "hovered"), + color: iconColor(theme, "active"), + }, + }, }, toolbar: { height: 34,