mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-26 03:59:55 +00:00
WIP: start on menu bar extra
This commit is contained in:
parent
95e08edbb8
commit
9f81699e01
4 changed files with 158 additions and 1 deletions
40
crates/collab_ui/src/active_call_popover.rs
Normal file
40
crates/collab_ui/src/active_call_popover.rs
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
use gpui::{color::Color, elements::*, Entity, RenderContext, View, ViewContext};
|
||||||
|
|
||||||
|
pub enum Event {
|
||||||
|
Deactivated,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ActiveCallPopover {
|
||||||
|
_subscription: gpui::Subscription,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Entity for ActiveCallPopover {
|
||||||
|
type Event = Event;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl View for ActiveCallPopover {
|
||||||
|
fn ui_name() -> &'static str {
|
||||||
|
"ActiveCallPopover"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
|
||||||
|
Empty::new()
|
||||||
|
.contained()
|
||||||
|
.with_background_color(Color::red())
|
||||||
|
.boxed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveCallPopover {
|
||||||
|
pub fn new(cx: &mut ViewContext<Self>) -> Self {
|
||||||
|
Self {
|
||||||
|
_subscription: cx.observe_window_activation(Self::window_activation_changed),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn window_activation_changed(&mut self, is_active: bool, cx: &mut ViewContext<Self>) {
|
||||||
|
if !is_active {
|
||||||
|
cx.emit(Event::Deactivated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,10 @@
|
||||||
|
mod active_call_popover;
|
||||||
mod collab_titlebar_item;
|
mod collab_titlebar_item;
|
||||||
mod contact_finder;
|
mod contact_finder;
|
||||||
mod contact_notification;
|
mod contact_notification;
|
||||||
mod contacts_popover;
|
mod contacts_popover;
|
||||||
mod incoming_call_notification;
|
mod incoming_call_notification;
|
||||||
|
mod menu_bar_extra;
|
||||||
mod notifications;
|
mod notifications;
|
||||||
mod project_shared_notification;
|
mod project_shared_notification;
|
||||||
|
|
||||||
|
@ -14,11 +16,12 @@ 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) {
|
||||||
|
collab_titlebar_item::init(cx);
|
||||||
contact_notification::init(cx);
|
contact_notification::init(cx);
|
||||||
contact_finder::init(cx);
|
contact_finder::init(cx);
|
||||||
contacts_popover::init(cx);
|
contacts_popover::init(cx);
|
||||||
collab_titlebar_item::init(cx);
|
|
||||||
incoming_call_notification::init(cx);
|
incoming_call_notification::init(cx);
|
||||||
|
menu_bar_extra::init(cx);
|
||||||
project_shared_notification::init(cx);
|
project_shared_notification::init(cx);
|
||||||
|
|
||||||
cx.add_global_action(move |action: &JoinProject, cx| {
|
cx.add_global_action(move |action: &JoinProject, cx| {
|
||||||
|
|
110
crates/collab_ui/src/menu_bar_extra.rs
Normal file
110
crates/collab_ui/src/menu_bar_extra.rs
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
use crate::active_call_popover::{self, ActiveCallPopover};
|
||||||
|
use call::ActiveCall;
|
||||||
|
use gpui::{
|
||||||
|
actions,
|
||||||
|
color::Color,
|
||||||
|
elements::*,
|
||||||
|
geometry::{rect::RectF, vector::vec2f},
|
||||||
|
Appearance, Entity, MouseButton, MutableAppContext, RenderContext, View, ViewContext,
|
||||||
|
ViewHandle, WindowKind,
|
||||||
|
};
|
||||||
|
|
||||||
|
actions!(menu_bar_extra, [ToggleActiveCallPopover]);
|
||||||
|
|
||||||
|
pub fn init(cx: &mut MutableAppContext) {
|
||||||
|
cx.add_action(MenuBarExtra::toggle_active_call_popover);
|
||||||
|
|
||||||
|
let mut status_bar_item_id = None;
|
||||||
|
cx.observe(&ActiveCall::global(cx), move |call, cx| {
|
||||||
|
if let Some(status_bar_item_id) = status_bar_item_id.take() {
|
||||||
|
cx.remove_status_bar_item(status_bar_item_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if call.read(cx).room().is_some() {
|
||||||
|
let (id, _) = cx.add_status_bar_item(|_| MenuBarExtra::new());
|
||||||
|
status_bar_item_id = Some(id);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct MenuBarExtra {
|
||||||
|
popover: Option<ViewHandle<ActiveCallPopover>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Entity for MenuBarExtra {
|
||||||
|
type Event = ();
|
||||||
|
}
|
||||||
|
|
||||||
|
impl View for MenuBarExtra {
|
||||||
|
fn ui_name() -> &'static str {
|
||||||
|
"MenuBarExtra"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||||
|
let color = match cx.appearance {
|
||||||
|
Appearance::Light | Appearance::VibrantLight => Color::black(),
|
||||||
|
Appearance::Dark | Appearance::VibrantDark => Color::white(),
|
||||||
|
};
|
||||||
|
MouseEventHandler::<Self>::new(0, cx, |_, _| {
|
||||||
|
Svg::new("icons/zed_22.svg")
|
||||||
|
.with_color(color)
|
||||||
|
.aligned()
|
||||||
|
.boxed()
|
||||||
|
})
|
||||||
|
.on_click(MouseButton::Left, |_, cx| {
|
||||||
|
cx.dispatch_action(ToggleActiveCallPopover);
|
||||||
|
})
|
||||||
|
.boxed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MenuBarExtra {
|
||||||
|
fn new() -> Self {
|
||||||
|
Self { popover: None }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn toggle_active_call_popover(
|
||||||
|
&mut self,
|
||||||
|
_: &ToggleActiveCallPopover,
|
||||||
|
cx: &mut ViewContext<Self>,
|
||||||
|
) {
|
||||||
|
match self.popover.take() {
|
||||||
|
Some(popover) => {
|
||||||
|
cx.remove_window(popover.window_id());
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
let window_bounds = cx.window_bounds();
|
||||||
|
let size = vec2f(360., 460.);
|
||||||
|
let origin = window_bounds.lower_left()
|
||||||
|
+ vec2f(window_bounds.width() / 2. - size.x() / 2., 0.);
|
||||||
|
let (_, popover) = cx.add_window(
|
||||||
|
gpui::WindowOptions {
|
||||||
|
bounds: gpui::WindowBounds::Fixed(RectF::new(origin, size)),
|
||||||
|
titlebar: None,
|
||||||
|
center: false,
|
||||||
|
kind: WindowKind::PopUp,
|
||||||
|
is_movable: false,
|
||||||
|
},
|
||||||
|
|cx| ActiveCallPopover::new(cx),
|
||||||
|
);
|
||||||
|
cx.subscribe(&popover, Self::on_popover_event).detach();
|
||||||
|
self.popover = Some(popover);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_popover_event(
|
||||||
|
&mut self,
|
||||||
|
popover: ViewHandle<ActiveCallPopover>,
|
||||||
|
event: &active_call_popover::Event,
|
||||||
|
cx: &mut ViewContext<Self>,
|
||||||
|
) {
|
||||||
|
match event {
|
||||||
|
active_call_popover::Event::Deactivated => {
|
||||||
|
self.popover.take();
|
||||||
|
cx.remove_window(popover.window_id());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1990,6 +1990,10 @@ impl MutableAppContext {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn remove_status_bar_item(&mut self, id: usize) {
|
||||||
|
self.remove_window(id);
|
||||||
|
}
|
||||||
|
|
||||||
fn register_platform_window(
|
fn register_platform_window(
|
||||||
&mut self,
|
&mut self,
|
||||||
window_id: usize,
|
window_id: usize,
|
||||||
|
|
Loading…
Reference in a new issue