Eliminate GPUI View, ViewContext, and WindowContext types (#22632)
There's still a bit more work to do on this, but this PR is compiling (with warnings) after eliminating the key types. When the tasks below are complete, this will be the new narrative for GPUI: - `Entity<T>` - This replaces `View<T>`/`Model<T>`. It represents a unit of state, and if `T` implements `Render`, then `Entity<T>` implements `Element`. - `&mut App` This replaces `AppContext` and represents the app. - `&mut Context<T>` This replaces `ModelContext` and derefs to `App`. It is provided by the framework when updating an entity. - `&mut Window` Broken out of `&mut WindowContext` which no longer exists. Every method that once took `&mut WindowContext` now takes `&mut Window, &mut App` and every method that took `&mut ViewContext<T>` now takes `&mut Window, &mut Context<T>` Not pictured here are the two other failed attempts. It's been quite a month! Tasks: - [x] Remove `View`, `ViewContext`, `WindowContext` and thread through `Window` - [x] [@cole-miller @mikayla-maki] Redraw window when entities change - [x] [@cole-miller @mikayla-maki] Get examples and Zed running - [x] [@cole-miller @mikayla-maki] Fix Zed rendering - [x] [@mikayla-maki] Fix todo! macros and comments - [x] Fix a bug where the editor would not be redrawn because of view caching - [x] remove publicness window.notify() and replace with `AppContext::notify` - [x] remove `observe_new_window_models`, replace with `observe_new_models` with an optional window - [x] Fix a bug where the project panel would not be redrawn because of the wrong refresh() call being used - [x] Fix the tests - [x] Fix warnings by eliminating `Window` params or using `_` - [x] Fix conflicts - [x] Simplify generic code where possible - [x] Rename types - [ ] Update docs ### issues post merge - [x] Issues switching between normal and insert mode - [x] Assistant re-rendering failure - [x] Vim test failures - [x] Mac build issue Release Notes: - N/A --------- Co-authored-by: Antonio Scandurra <me@as-cii.com> Co-authored-by: Cole Miller <cole@zed.dev> Co-authored-by: Mikayla <mikayla@zed.dev> Co-authored-by: Joseph <joseph@zed.dev> Co-authored-by: max <max@zed.dev> Co-authored-by: Michael Sloan <michael@zed.dev> Co-authored-by: Mikayla Maki <mikaylamaki@Mikaylas-MacBook-Pro.local> Co-authored-by: Mikayla <mikayla.c.maki@gmail.com> Co-authored-by: joão <joao@zed.dev>
This commit is contained in:
parent
21b4a0d50e
commit
6fca1d2b0b
648 changed files with 36248 additions and 28208 deletions
|
@ -1,4 +1,4 @@
|
|||
use gpui::{impl_actions, OwnedMenu, OwnedMenuItem, View};
|
||||
use gpui::{impl_actions, Entity, OwnedMenu, OwnedMenuItem};
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use smallvec::SmallVec;
|
||||
|
@ -27,7 +27,7 @@ pub struct ApplicationMenu {
|
|||
}
|
||||
|
||||
impl ApplicationMenu {
|
||||
pub fn new(cx: &mut ViewContext<Self>) -> Self {
|
||||
pub fn new(_: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||
let menus = cx.get_menus().unwrap_or_default();
|
||||
Self {
|
||||
entries: menus
|
||||
|
@ -75,10 +75,14 @@ impl ApplicationMenu {
|
|||
cleaned
|
||||
}
|
||||
|
||||
fn build_menu_from_items(entry: MenuEntry, cx: &mut WindowContext) -> View<ContextMenu> {
|
||||
ContextMenu::build(cx, |menu, cx| {
|
||||
fn build_menu_from_items(
|
||||
entry: MenuEntry,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) -> Entity<ContextMenu> {
|
||||
ContextMenu::build(window, cx, |menu, window, cx| {
|
||||
// Grab current focus handle so menu can shown items in context with the focused element
|
||||
let menu = menu.when_some(cx.focused(), |menu, focused| menu.context(focused));
|
||||
let menu = menu.when_some(window.focused(cx), |menu, focused| menu.context(focused));
|
||||
let sanitized_items = Self::sanitize_menu_items(entry.menu.items);
|
||||
|
||||
sanitized_items
|
||||
|
@ -114,7 +118,9 @@ impl ApplicationMenu {
|
|||
.occlude()
|
||||
.child(
|
||||
PopoverMenu::new(SharedString::from(format!("{}-menu-popover", menu_name)))
|
||||
.menu(move |cx| Self::build_menu_from_items(entry.clone(), cx).into())
|
||||
.menu(move |window, cx| {
|
||||
Self::build_menu_from_items(entry.clone(), window, cx).into()
|
||||
})
|
||||
.trigger(
|
||||
IconButton::new(
|
||||
SharedString::from(format!("{}-menu-trigger", menu_name)),
|
||||
|
@ -123,7 +129,7 @@ impl ApplicationMenu {
|
|||
.style(ButtonStyle::Subtle)
|
||||
.icon_size(IconSize::Small)
|
||||
.when(!handle.is_deployed(), |this| {
|
||||
this.tooltip(|cx| Tooltip::text("Open Application Menu", cx))
|
||||
this.tooltip(Tooltip::text("Open Application Menu"))
|
||||
}),
|
||||
)
|
||||
.with_handle(handle),
|
||||
|
@ -147,7 +153,9 @@ impl ApplicationMenu {
|
|||
.occlude()
|
||||
.child(
|
||||
PopoverMenu::new(SharedString::from(format!("{}-menu-popover", menu_name)))
|
||||
.menu(move |cx| Self::build_menu_from_items(entry.clone(), cx).into())
|
||||
.menu(move |window, cx| {
|
||||
Self::build_menu_from_items(entry.clone(), window, cx).into()
|
||||
})
|
||||
.trigger(
|
||||
Button::new(
|
||||
SharedString::from(format!("{}-menu-trigger", menu_name)),
|
||||
|
@ -158,19 +166,24 @@ impl ApplicationMenu {
|
|||
)
|
||||
.with_handle(current_handle.clone()),
|
||||
)
|
||||
.on_hover(move |hover_enter, cx| {
|
||||
.on_hover(move |hover_enter, window, cx| {
|
||||
if *hover_enter && !current_handle.is_deployed() {
|
||||
all_handles.iter().for_each(|h| h.hide(cx));
|
||||
|
||||
// We need to defer this so that this menu handle can take focus from the previous menu
|
||||
let handle = current_handle.clone();
|
||||
cx.defer(move |cx| handle.show(cx));
|
||||
window.defer(cx, move |window, cx| handle.show(window, cx));
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
pub fn open_menu(&mut self, action: &OpenApplicationMenu, _cx: &mut ViewContext<Self>) {
|
||||
pub fn open_menu(
|
||||
&mut self,
|
||||
action: &OpenApplicationMenu,
|
||||
_window: &mut Window,
|
||||
_cx: &mut Context<Self>,
|
||||
) {
|
||||
self.pending_menu_open = Some(action.0.clone());
|
||||
}
|
||||
|
||||
|
@ -178,7 +191,8 @@ impl ApplicationMenu {
|
|||
pub fn navigate_menus_in_direction(
|
||||
&mut self,
|
||||
action: &NavigateApplicationMenuInDirection,
|
||||
cx: &mut ViewContext<Self>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
let current_index = self
|
||||
.entries
|
||||
|
@ -210,7 +224,7 @@ impl ApplicationMenu {
|
|||
|
||||
// We need to defer this so that this menu handle can take focus from the previous menu
|
||||
let next_handle = self.entries[next_index].handle.clone();
|
||||
cx.defer(move |_, cx| next_handle.show(cx));
|
||||
cx.defer_in(window, move |_, window, cx| next_handle.show(window, cx));
|
||||
}
|
||||
|
||||
pub fn all_menus_shown(&self) -> bool {
|
||||
|
@ -220,7 +234,7 @@ impl ApplicationMenu {
|
|||
}
|
||||
|
||||
impl Render for ApplicationMenu {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let all_menus_shown = self.all_menus_shown();
|
||||
|
||||
if let Some(pending_menu_open) = self.pending_menu_open.take() {
|
||||
|
@ -240,14 +254,14 @@ impl Render for ApplicationMenu {
|
|||
if handles_to_hide.is_empty() {
|
||||
// We need to wait for the next frame to show all menus first,
|
||||
// before we can handle show/hide operations
|
||||
cx.window_context().on_next_frame(move |cx| {
|
||||
window.on_next_frame(move |window, cx| {
|
||||
handles_to_hide.iter().for_each(|handle| handle.hide(cx));
|
||||
cx.defer(move |cx| handle_to_show.show(cx));
|
||||
window.defer(cx, move |window, cx| handle_to_show.show(window, cx));
|
||||
});
|
||||
} else {
|
||||
// Since menus are already shown, we can directly handle show/hide operations
|
||||
handles_to_hide.iter().for_each(|handle| handle.hide(cx));
|
||||
cx.defer(move |_, cx| handle_to_show.show(cx));
|
||||
cx.defer_in(window, move |_, window, cx| handle_to_show.show(window, cx));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::sync::Arc;
|
|||
|
||||
use call::{ActiveCall, ParticipantLocation, Room};
|
||||
use client::{proto::PeerId, User};
|
||||
use gpui::{actions, AppContext, Task, WindowContext};
|
||||
use gpui::{actions, App, Task, Window};
|
||||
use gpui::{canvas, point, AnyElement, Hsla, IntoElement, MouseButton, Path, Styled};
|
||||
use rpc::proto::{self};
|
||||
use theme::ActiveTheme;
|
||||
|
@ -16,7 +16,7 @@ actions!(
|
|||
[ToggleScreenSharing, ToggleMute, ToggleDeafen, LeaveCall]
|
||||
);
|
||||
|
||||
fn toggle_screen_sharing(_: &ToggleScreenSharing, cx: &mut WindowContext) {
|
||||
fn toggle_screen_sharing(_: &ToggleScreenSharing, window: &mut Window, cx: &mut App) {
|
||||
let call = ActiveCall::global(cx).read(cx);
|
||||
if let Some(room) = call.room().cloned() {
|
||||
let toggle_screen_sharing = room.update(cx, |room, cx| {
|
||||
|
@ -36,11 +36,11 @@ fn toggle_screen_sharing(_: &ToggleScreenSharing, cx: &mut WindowContext) {
|
|||
room.share_screen(cx)
|
||||
}
|
||||
});
|
||||
toggle_screen_sharing.detach_and_prompt_err("Sharing Screen Failed", cx, |e, _| Some(format!("{:?}\n\nPlease check that you have given Zed permissions to record your screen in Settings.", e)));
|
||||
toggle_screen_sharing.detach_and_prompt_err("Sharing Screen Failed", window, cx, |e, _, _| Some(format!("{:?}\n\nPlease check that you have given Zed permissions to record your screen in Settings.", e)));
|
||||
}
|
||||
}
|
||||
|
||||
fn toggle_mute(_: &ToggleMute, cx: &mut AppContext) {
|
||||
fn toggle_mute(_: &ToggleMute, cx: &mut App) {
|
||||
let call = ActiveCall::global(cx).read(cx);
|
||||
if let Some(room) = call.room().cloned() {
|
||||
room.update(cx, |room, cx| {
|
||||
|
@ -60,7 +60,7 @@ fn toggle_mute(_: &ToggleMute, cx: &mut AppContext) {
|
|||
}
|
||||
}
|
||||
|
||||
fn toggle_deafen(_: &ToggleDeafen, cx: &mut AppContext) {
|
||||
fn toggle_deafen(_: &ToggleDeafen, cx: &mut App) {
|
||||
if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() {
|
||||
room.update(cx, |room, cx| room.toggle_deafen(cx));
|
||||
}
|
||||
|
@ -68,8 +68,8 @@ fn toggle_deafen(_: &ToggleDeafen, cx: &mut AppContext) {
|
|||
|
||||
fn render_color_ribbon(color: Hsla) -> impl Element {
|
||||
canvas(
|
||||
move |_, _| {},
|
||||
move |bounds, _, cx| {
|
||||
move |_, _, _| {},
|
||||
move |bounds, _, window, _| {
|
||||
let height = bounds.size.height;
|
||||
let horizontal_offset = height;
|
||||
let vertical_offset = px(height.0 / 2.0);
|
||||
|
@ -84,7 +84,7 @@ fn render_color_ribbon(color: Hsla) -> impl Element {
|
|||
bounds.top_right() + point(px(0.0), vertical_offset),
|
||||
);
|
||||
path.line_to(bounds.bottom_left());
|
||||
cx.paint_path(path, color);
|
||||
window.paint_path(path, color);
|
||||
},
|
||||
)
|
||||
.h_1()
|
||||
|
@ -92,7 +92,11 @@ fn render_color_ribbon(color: Hsla) -> impl Element {
|
|||
}
|
||||
|
||||
impl TitleBar {
|
||||
pub(crate) fn render_collaborator_list(&self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
pub(crate) fn render_collaborator_list(
|
||||
&self,
|
||||
_: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> impl IntoElement {
|
||||
let room = ActiveCall::global(cx).read(cx).room().cloned();
|
||||
let current_user = self.user_store.read(cx).current_user();
|
||||
let client = self.client.clone();
|
||||
|
@ -128,7 +132,7 @@ impl TitleBar {
|
|||
|
||||
this.children(current_user_face_pile.map(|face_pile| {
|
||||
v_flex()
|
||||
.on_mouse_down(MouseButton::Left, |_, cx| cx.stop_propagation())
|
||||
.on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
|
||||
.child(face_pile)
|
||||
.child(render_color_ribbon(player_colors.local().cursor))
|
||||
}))
|
||||
|
@ -165,13 +169,13 @@ impl TitleBar {
|
|||
.cursor_pointer()
|
||||
.on_click({
|
||||
let peer_id = collaborator.peer_id;
|
||||
cx.listener(move |this, _, cx| {
|
||||
cx.listener(move |this, _, window, cx| {
|
||||
this.workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
if is_following {
|
||||
workspace.unfollow(peer_id, cx);
|
||||
workspace.unfollow(peer_id, window, cx);
|
||||
} else {
|
||||
workspace.follow(peer_id, cx);
|
||||
workspace.follow(peer_id, window, cx);
|
||||
}
|
||||
})
|
||||
.ok();
|
||||
|
@ -179,7 +183,7 @@ impl TitleBar {
|
|||
})
|
||||
.tooltip({
|
||||
let login = collaborator.user.github_login.clone();
|
||||
move |cx| Tooltip::text(format!("Follow {login}"), cx)
|
||||
Tooltip::text(format!("Follow {login}"))
|
||||
}),
|
||||
)
|
||||
}))
|
||||
|
@ -199,7 +203,7 @@ impl TitleBar {
|
|||
room: &Room,
|
||||
project_id: Option<u64>,
|
||||
current_user: &Arc<User>,
|
||||
cx: &ViewContext<Self>,
|
||||
cx: &App,
|
||||
) -> Option<Div> {
|
||||
if room.role_for_user(user.id) == Some(proto::ChannelRole::Guest) {
|
||||
return None;
|
||||
|
@ -235,12 +239,7 @@ impl TitleBar {
|
|||
AvatarAudioStatusIndicator::new(ui::AudioStatus::Muted)
|
||||
.tooltip({
|
||||
let github_login = user.github_login.clone();
|
||||
move |cx| {
|
||||
Tooltip::text(
|
||||
format!("{} is muted", github_login),
|
||||
cx,
|
||||
)
|
||||
}
|
||||
Tooltip::text(format!("{} is muted", github_login))
|
||||
}),
|
||||
)
|
||||
}),
|
||||
|
@ -277,14 +276,18 @@ impl TitleBar {
|
|||
)
|
||||
}
|
||||
|
||||
pub(crate) fn render_call_controls(&self, cx: &mut ViewContext<Self>) -> Vec<AnyElement> {
|
||||
pub(crate) fn render_call_controls(
|
||||
&self,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Vec<AnyElement> {
|
||||
let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() else {
|
||||
return Vec::new();
|
||||
};
|
||||
|
||||
let is_connecting_to_project = self
|
||||
.workspace
|
||||
.update(cx, |workspace, cx| workspace.has_active_modal(cx))
|
||||
.update(cx, |workspace, cx| workspace.has_active_modal(window, cx))
|
||||
.unwrap_or(false);
|
||||
|
||||
let room = room.read(cx);
|
||||
|
@ -310,23 +313,18 @@ impl TitleBar {
|
|||
"toggle_sharing",
|
||||
if is_shared { "Unshare" } else { "Share" },
|
||||
)
|
||||
.tooltip(move |cx| {
|
||||
Tooltip::text(
|
||||
if is_shared {
|
||||
"Stop sharing project with call participants"
|
||||
} else {
|
||||
"Share project with call participants"
|
||||
},
|
||||
cx,
|
||||
)
|
||||
})
|
||||
.tooltip(Tooltip::text(if is_shared {
|
||||
"Stop sharing project with call participants"
|
||||
} else {
|
||||
"Share project with call participants"
|
||||
}))
|
||||
.style(ButtonStyle::Subtle)
|
||||
.selected_style(ButtonStyle::Tinted(TintColor::Accent))
|
||||
.toggle_state(is_shared)
|
||||
.label_size(LabelSize::Small)
|
||||
.on_click(cx.listener(move |this, _, cx| {
|
||||
.on_click(cx.listener(move |this, _, window, cx| {
|
||||
if is_shared {
|
||||
this.unshare_project(&Default::default(), cx);
|
||||
this.unshare_project(&Default::default(), window, cx);
|
||||
} else {
|
||||
this.share_project(&Default::default(), cx);
|
||||
}
|
||||
|
@ -341,9 +339,9 @@ impl TitleBar {
|
|||
.child(
|
||||
IconButton::new("leave-call", ui::IconName::Exit)
|
||||
.style(ButtonStyle::Subtle)
|
||||
.tooltip(|cx| Tooltip::text("Leave call", cx))
|
||||
.tooltip(Tooltip::text("Leave call"))
|
||||
.icon_size(IconSize::Small)
|
||||
.on_click(move |_, cx| {
|
||||
.on_click(move |_, _window, cx| {
|
||||
ActiveCall::global(cx)
|
||||
.update(cx, |call, cx| call.hang_up(cx))
|
||||
.detach_and_log_err(cx);
|
||||
|
@ -362,27 +360,28 @@ impl TitleBar {
|
|||
ui::IconName::Mic
|
||||
},
|
||||
)
|
||||
.tooltip(move |cx| {
|
||||
.tooltip(move |window, cx| {
|
||||
if is_muted {
|
||||
if is_deafened {
|
||||
Tooltip::with_meta(
|
||||
"Unmute Microphone",
|
||||
None,
|
||||
"Audio will be unmuted",
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
} else {
|
||||
Tooltip::text("Unmute Microphone", cx)
|
||||
Tooltip::simple("Unmute Microphone", cx)
|
||||
}
|
||||
} else {
|
||||
Tooltip::text("Mute Microphone", cx)
|
||||
Tooltip::simple("Mute Microphone", cx)
|
||||
}
|
||||
})
|
||||
.style(ButtonStyle::Subtle)
|
||||
.icon_size(IconSize::Small)
|
||||
.toggle_state(is_muted)
|
||||
.selected_style(ButtonStyle::Tinted(TintColor::Error))
|
||||
.on_click(move |_, cx| {
|
||||
.on_click(move |_, _window, cx| {
|
||||
toggle_mute(&Default::default(), cx);
|
||||
})
|
||||
.into_any_element(),
|
||||
|
@ -401,26 +400,32 @@ impl TitleBar {
|
|||
.selected_style(ButtonStyle::Tinted(TintColor::Error))
|
||||
.icon_size(IconSize::Small)
|
||||
.toggle_state(is_deafened)
|
||||
.tooltip(move |cx| {
|
||||
.tooltip(move |window, cx| {
|
||||
if is_deafened {
|
||||
let label = "Unmute Audio";
|
||||
|
||||
if !muted_by_user {
|
||||
Tooltip::with_meta(label, None, "Microphone will be unmuted", cx)
|
||||
Tooltip::with_meta(
|
||||
label,
|
||||
None,
|
||||
"Microphone will be unmuted",
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
} else {
|
||||
Tooltip::text(label, cx)
|
||||
Tooltip::simple(label, cx)
|
||||
}
|
||||
} else {
|
||||
let label = "Mute Audio";
|
||||
|
||||
if !muted_by_user {
|
||||
Tooltip::with_meta(label, None, "Microphone will be muted", cx)
|
||||
Tooltip::with_meta(label, None, "Microphone will be muted", window, cx)
|
||||
} else {
|
||||
Tooltip::text(label, cx)
|
||||
Tooltip::simple(label, cx)
|
||||
}
|
||||
}
|
||||
})
|
||||
.on_click(move |_, cx| toggle_deafen(&Default::default(), cx))
|
||||
.on_click(move |_, _, cx| toggle_deafen(&Default::default(), cx))
|
||||
.into_any_element(),
|
||||
);
|
||||
}
|
||||
|
@ -432,17 +437,14 @@ impl TitleBar {
|
|||
.icon_size(IconSize::Small)
|
||||
.toggle_state(is_screen_sharing)
|
||||
.selected_style(ButtonStyle::Tinted(TintColor::Accent))
|
||||
.tooltip(move |cx| {
|
||||
Tooltip::text(
|
||||
if is_screen_sharing {
|
||||
"Stop Sharing Screen"
|
||||
} else {
|
||||
"Share Screen"
|
||||
},
|
||||
cx,
|
||||
)
|
||||
.tooltip(Tooltip::text(if is_screen_sharing {
|
||||
"Stop Sharing Screen"
|
||||
} else {
|
||||
"Share Screen"
|
||||
}))
|
||||
.on_click(move |_, window, cx| {
|
||||
toggle_screen_sharing(&Default::default(), window, cx)
|
||||
})
|
||||
.on_click(move |_, cx| toggle_screen_sharing(&Default::default(), cx))
|
||||
.into_any_element(),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -18,12 +18,12 @@ impl LinuxWindowControls {
|
|||
}
|
||||
|
||||
impl RenderOnce for LinuxWindowControls {
|
||||
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
h_flex()
|
||||
.id("generic-window-controls")
|
||||
.px_3()
|
||||
.gap_3()
|
||||
.on_mouse_down(MouseButton::Left, |_, cx| cx.stop_propagation())
|
||||
.on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
|
||||
.child(WindowControl::new(
|
||||
"minimize",
|
||||
WindowControlType::Minimize,
|
||||
|
@ -31,7 +31,7 @@ impl RenderOnce for LinuxWindowControls {
|
|||
))
|
||||
.child(WindowControl::new(
|
||||
"maximize-or-restore",
|
||||
if cx.is_maximized() {
|
||||
if window.is_maximized() {
|
||||
WindowControlType::Restore
|
||||
} else {
|
||||
WindowControlType::Maximize
|
||||
|
|
|
@ -33,7 +33,7 @@ impl WindowsWindowControls {
|
|||
}
|
||||
|
||||
impl RenderOnce for WindowsWindowControls {
|
||||
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||
fn render(self, window: &mut Window, _: &mut App) -> impl IntoElement {
|
||||
let close_button_hover_color = Rgba {
|
||||
r: 232.0 / 255.0,
|
||||
g: 17.0 / 255.0,
|
||||
|
@ -41,7 +41,7 @@ impl RenderOnce for WindowsWindowControls {
|
|||
a: 1.0,
|
||||
};
|
||||
|
||||
let button_hover_color = match cx.appearance() {
|
||||
let button_hover_color = match window.appearance() {
|
||||
WindowAppearance::Light | WindowAppearance::VibrantLight => Rgba {
|
||||
r: 0.1,
|
||||
g: 0.1,
|
||||
|
@ -72,7 +72,7 @@ impl RenderOnce for WindowsWindowControls {
|
|||
))
|
||||
.child(WindowsCaptionButton::new(
|
||||
"maximize-or-restore",
|
||||
if cx.is_maximized() {
|
||||
if window.is_maximized() {
|
||||
WindowsCaptionButtonIcon::Restore
|
||||
} else {
|
||||
WindowsCaptionButtonIcon::Maximize
|
||||
|
@ -117,7 +117,7 @@ impl WindowsCaptionButton {
|
|||
}
|
||||
|
||||
impl RenderOnce for WindowsCaptionButton {
|
||||
fn render(self, _cx: &mut WindowContext) -> impl IntoElement {
|
||||
fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement {
|
||||
// todo(windows) report this width to the Windows platform API
|
||||
// NOTE: this is intentionally hard coded. An option to use the 'native' size
|
||||
// could be added when the width is reported to the Windows platform API
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use gpui::{Render, View};
|
||||
use gpui::{Entity, Render};
|
||||
use story::{Story, StoryItem, StorySection};
|
||||
|
||||
use ui::prelude::*;
|
||||
|
@ -6,19 +6,19 @@ use ui::prelude::*;
|
|||
use crate::application_menu::ApplicationMenu;
|
||||
|
||||
pub struct ApplicationMenuStory {
|
||||
menu: View<ApplicationMenu>,
|
||||
menu: Entity<ApplicationMenu>,
|
||||
}
|
||||
|
||||
impl ApplicationMenuStory {
|
||||
pub fn new(cx: &mut WindowContext) -> Self {
|
||||
pub fn new(window: &mut Window, cx: &mut App) -> Self {
|
||||
Self {
|
||||
menu: cx.new_view(ApplicationMenu::new),
|
||||
menu: cx.new(|cx| ApplicationMenu::new(window, cx)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for ApplicationMenuStory {
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
Story::container()
|
||||
.child(Story::title_for::<ApplicationMenu>())
|
||||
.child(StorySection::new().child(StoryItem::new(
|
||||
|
|
|
@ -19,9 +19,9 @@ use feature_flags::{FeatureFlagAppExt, GitUiFeatureFlag, ZedPro};
|
|||
use git_ui::repository_selector::RepositorySelector;
|
||||
use git_ui::repository_selector::RepositorySelectorPopoverMenu;
|
||||
use gpui::{
|
||||
actions, div, px, Action, AnyElement, AppContext, Decorations, Element, InteractiveElement,
|
||||
Interactivity, IntoElement, Model, MouseButton, ParentElement, Render, Stateful,
|
||||
StatefulInteractiveElement, Styled, Subscription, View, ViewContext, VisualContext, WeakView,
|
||||
actions, div, px, Action, AnyElement, App, Context, Decorations, Element, Entity,
|
||||
InteractiveElement, Interactivity, IntoElement, MouseButton, ParentElement, Render, Stateful,
|
||||
StatefulInteractiveElement, Styled, Subscription, WeakEntity, Window,
|
||||
};
|
||||
use project::Project;
|
||||
use rpc::proto;
|
||||
|
@ -57,20 +57,23 @@ actions!(
|
|||
]
|
||||
);
|
||||
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
cx.observe_new_views(|workspace: &mut Workspace, cx| {
|
||||
let item = cx.new_view(|cx| TitleBar::new("title-bar", workspace, cx));
|
||||
workspace.set_titlebar_item(item.into(), cx);
|
||||
pub fn init(cx: &mut App) {
|
||||
cx.observe_new(|workspace: &mut Workspace, window, cx| {
|
||||
let Some(window) = window else {
|
||||
return;
|
||||
};
|
||||
let item = cx.new(|cx| TitleBar::new("title-bar", workspace, window, cx));
|
||||
workspace.set_titlebar_item(item.into(), window, cx);
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
workspace.register_action(|workspace, action: &OpenApplicationMenu, cx| {
|
||||
workspace.register_action(|workspace, action: &OpenApplicationMenu, window, cx| {
|
||||
if let Some(titlebar) = workspace
|
||||
.titlebar_item()
|
||||
.and_then(|item| item.downcast::<TitleBar>().ok())
|
||||
{
|
||||
titlebar.update(cx, |titlebar, cx| {
|
||||
if let Some(ref menu) = titlebar.application_menu {
|
||||
menu.update(cx, |menu, cx| menu.open_menu(action, cx));
|
||||
menu.update(cx, |menu, cx| menu.open_menu(action, window, cx));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -78,7 +81,7 @@ pub fn init(cx: &mut AppContext) {
|
|||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
workspace.register_action(
|
||||
|workspace, action: &NavigateApplicationMenuInDirection, cx| {
|
||||
|workspace, action: &NavigateApplicationMenuInDirection, window, cx| {
|
||||
if let Some(titlebar) = workspace
|
||||
.titlebar_item()
|
||||
.and_then(|item| item.downcast::<TitleBar>().ok())
|
||||
|
@ -86,7 +89,7 @@ pub fn init(cx: &mut AppContext) {
|
|||
titlebar.update(cx, |titlebar, cx| {
|
||||
if let Some(ref menu) = titlebar.application_menu {
|
||||
menu.update(cx, |menu, cx| {
|
||||
menu.navigate_menus_in_direction(action, cx)
|
||||
menu.navigate_menus_in_direction(action, window, cx)
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -101,25 +104,25 @@ pub struct TitleBar {
|
|||
platform_style: PlatformStyle,
|
||||
content: Stateful<Div>,
|
||||
children: SmallVec<[AnyElement; 2]>,
|
||||
repository_selector: View<RepositorySelector>,
|
||||
project: Model<Project>,
|
||||
user_store: Model<UserStore>,
|
||||
repository_selector: Entity<RepositorySelector>,
|
||||
project: Entity<Project>,
|
||||
user_store: Entity<UserStore>,
|
||||
client: Arc<Client>,
|
||||
workspace: WeakView<Workspace>,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
should_move: bool,
|
||||
application_menu: Option<View<ApplicationMenu>>,
|
||||
application_menu: Option<Entity<ApplicationMenu>>,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
git_ui_enabled: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
impl Render for TitleBar {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let close_action = Box::new(workspace::CloseWindow);
|
||||
let height = Self::height(cx);
|
||||
let supported_controls = cx.window_controls();
|
||||
let decorations = cx.window_decorations();
|
||||
let height = Self::height(window);
|
||||
let supported_controls = window.window_controls();
|
||||
let decorations = window.window_decorations();
|
||||
let titlebar_color = if cfg!(any(target_os = "linux", target_os = "freebsd")) {
|
||||
if cx.is_window_active() && !self.should_move {
|
||||
if window.is_window_active() && !self.should_move {
|
||||
cx.theme().colors().title_bar_background
|
||||
} else {
|
||||
cx.theme().colors().title_bar_inactive_background
|
||||
|
@ -133,7 +136,7 @@ impl Render for TitleBar {
|
|||
.w_full()
|
||||
.h(height)
|
||||
.map(|this| {
|
||||
if cx.is_fullscreen() {
|
||||
if window.is_fullscreen() {
|
||||
this.pl_2()
|
||||
} else if self.platform_style == PlatformStyle::Mac {
|
||||
this.pl(px(platform_mac::TRAFFIC_LIGHT_PADDING))
|
||||
|
@ -166,9 +169,9 @@ impl Render for TitleBar {
|
|||
.w_full()
|
||||
// Note: On Windows the title bar behavior is handled by the platform implementation.
|
||||
.when(self.platform_style != PlatformStyle::Windows, |this| {
|
||||
this.on_click(|event, cx| {
|
||||
this.on_click(|event, window, _| {
|
||||
if event.up.click_count == 2 {
|
||||
cx.zoom_window();
|
||||
window.zoom_window();
|
||||
}
|
||||
})
|
||||
})
|
||||
|
@ -190,15 +193,15 @@ impl Render for TitleBar {
|
|||
.children(self.render_project_branch(cx))
|
||||
})
|
||||
})
|
||||
.on_mouse_down(MouseButton::Left, |_, cx| cx.stop_propagation()),
|
||||
.on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation()),
|
||||
)
|
||||
.child(self.render_collaborator_list(cx))
|
||||
.child(self.render_collaborator_list(window, cx))
|
||||
.child(
|
||||
h_flex()
|
||||
.gap_1()
|
||||
.pr_1()
|
||||
.on_mouse_down(MouseButton::Left, |_, cx| cx.stop_propagation())
|
||||
.children(self.render_call_controls(cx))
|
||||
.on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
|
||||
.children(self.render_call_controls(window, cx))
|
||||
.map(|el| {
|
||||
let status = self.client.status();
|
||||
let status = &*status.borrow();
|
||||
|
@ -212,44 +215,47 @@ impl Render for TitleBar {
|
|||
}),
|
||||
),
|
||||
)
|
||||
.when(!cx.is_fullscreen(), |title_bar| match self.platform_style {
|
||||
PlatformStyle::Mac => title_bar,
|
||||
PlatformStyle::Linux => {
|
||||
if matches!(decorations, Decorations::Client { .. }) {
|
||||
title_bar
|
||||
.child(platform_linux::LinuxWindowControls::new(close_action))
|
||||
.when(supported_controls.window_menu, |titlebar| {
|
||||
titlebar.on_mouse_down(gpui::MouseButton::Right, move |ev, cx| {
|
||||
cx.show_window_menu(ev.position)
|
||||
.when(!window.is_fullscreen(), |title_bar| {
|
||||
match self.platform_style {
|
||||
PlatformStyle::Mac => title_bar,
|
||||
PlatformStyle::Linux => {
|
||||
if matches!(decorations, Decorations::Client { .. }) {
|
||||
title_bar
|
||||
.child(platform_linux::LinuxWindowControls::new(close_action))
|
||||
.when(supported_controls.window_menu, |titlebar| {
|
||||
titlebar.on_mouse_down(
|
||||
gpui::MouseButton::Right,
|
||||
move |ev, window, _| window.show_window_menu(ev.position),
|
||||
)
|
||||
})
|
||||
})
|
||||
.on_mouse_move(cx.listener(move |this, _ev, cx| {
|
||||
if this.should_move {
|
||||
.on_mouse_move(cx.listener(move |this, _ev, window, _| {
|
||||
if this.should_move {
|
||||
this.should_move = false;
|
||||
window.start_window_move();
|
||||
}
|
||||
}))
|
||||
.on_mouse_down_out(cx.listener(move |this, _ev, _window, _cx| {
|
||||
this.should_move = false;
|
||||
cx.start_window_move();
|
||||
}
|
||||
}))
|
||||
.on_mouse_down_out(cx.listener(move |this, _ev, _cx| {
|
||||
this.should_move = false;
|
||||
}))
|
||||
.on_mouse_up(
|
||||
gpui::MouseButton::Left,
|
||||
cx.listener(move |this, _ev, _cx| {
|
||||
this.should_move = false;
|
||||
}),
|
||||
)
|
||||
.on_mouse_down(
|
||||
gpui::MouseButton::Left,
|
||||
cx.listener(move |this, _ev, _cx| {
|
||||
this.should_move = true;
|
||||
}),
|
||||
)
|
||||
} else {
|
||||
title_bar
|
||||
}))
|
||||
.on_mouse_up(
|
||||
gpui::MouseButton::Left,
|
||||
cx.listener(move |this, _ev, _window, _cx| {
|
||||
this.should_move = false;
|
||||
}),
|
||||
)
|
||||
.on_mouse_down(
|
||||
gpui::MouseButton::Left,
|
||||
cx.listener(move |this, _ev, _window, _cx| {
|
||||
this.should_move = true;
|
||||
}),
|
||||
)
|
||||
} else {
|
||||
title_bar
|
||||
}
|
||||
}
|
||||
PlatformStyle::Windows => {
|
||||
title_bar.child(platform_windows::WindowsWindowControls::new(height))
|
||||
}
|
||||
}
|
||||
PlatformStyle::Windows => {
|
||||
title_bar.child(platform_windows::WindowsWindowControls::new(height))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -259,7 +265,8 @@ impl TitleBar {
|
|||
pub fn new(
|
||||
id: impl Into<ElementId>,
|
||||
workspace: &Workspace,
|
||||
cx: &mut ViewContext<Self>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Self {
|
||||
let project = workspace.project().clone();
|
||||
let user_store = workspace.app_state().user_store.clone();
|
||||
|
@ -270,13 +277,13 @@ impl TitleBar {
|
|||
let application_menu = match platform_style {
|
||||
PlatformStyle::Mac => {
|
||||
if option_env!("ZED_USE_CROSS_PLATFORM_MENU").is_some() {
|
||||
Some(cx.new_view(ApplicationMenu::new))
|
||||
Some(cx.new(|cx| ApplicationMenu::new(window, cx)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
PlatformStyle::Linux | PlatformStyle::Windows => {
|
||||
Some(cx.new_view(ApplicationMenu::new))
|
||||
Some(cx.new(|cx| ApplicationMenu::new(window, cx)))
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -288,7 +295,7 @@ impl TitleBar {
|
|||
);
|
||||
subscriptions.push(cx.observe(&project, |_, _, cx| cx.notify()));
|
||||
subscriptions.push(cx.observe(&active_call, |this, _, cx| this.active_call_changed(cx)));
|
||||
subscriptions.push(cx.observe_window_activation(Self::window_activation_changed));
|
||||
subscriptions.push(cx.observe_window_activation(window, Self::window_activation_changed));
|
||||
subscriptions.push(cx.observe(&user_store, |_, _, cx| cx.notify()));
|
||||
|
||||
let is_git_ui_enabled = Arc::new(AtomicBool::new(false));
|
||||
|
@ -304,7 +311,7 @@ impl TitleBar {
|
|||
content: div().id(id.into()),
|
||||
children: SmallVec::new(),
|
||||
application_menu,
|
||||
repository_selector: cx.new_view(|cx| RepositorySelector::new(project.clone(), cx)),
|
||||
repository_selector: cx.new(|cx| RepositorySelector::new(project.clone(), window, cx)),
|
||||
workspace: workspace.weak_handle(),
|
||||
should_move: false,
|
||||
project,
|
||||
|
@ -316,12 +323,12 @@ impl TitleBar {
|
|||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
pub fn height(cx: &mut WindowContext) -> Pixels {
|
||||
(1.75 * cx.rem_size()).max(px(34.))
|
||||
pub fn height(window: &mut Window) -> Pixels {
|
||||
(1.75 * window.rem_size()).max(px(34.))
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn height(_cx: &mut WindowContext) -> Pixels {
|
||||
pub fn height(_window: &mut Window) -> Pixels {
|
||||
// todo(windows) instead of hard coded size report the actual size to the Windows platform API
|
||||
px(32.)
|
||||
}
|
||||
|
@ -332,7 +339,7 @@ impl TitleBar {
|
|||
self
|
||||
}
|
||||
|
||||
fn render_ssh_project_host(&self, cx: &mut ViewContext<Self>) -> Option<AnyElement> {
|
||||
fn render_ssh_project_host(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
|
||||
let options = self.project.read(cx).ssh_connection_options(cx)?;
|
||||
let host: SharedString = options.connection_string().into();
|
||||
|
||||
|
@ -390,17 +397,23 @@ impl TitleBar {
|
|||
.text_ellipsis(),
|
||||
),
|
||||
)
|
||||
.tooltip(move |cx| {
|
||||
Tooltip::with_meta("Remote Project", Some(&OpenRemote), meta.clone(), cx)
|
||||
.tooltip(move |window, cx| {
|
||||
Tooltip::with_meta(
|
||||
"Remote Project",
|
||||
Some(&OpenRemote),
|
||||
meta.clone(),
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
.on_click(|_, cx| {
|
||||
cx.dispatch_action(OpenRemote.boxed_clone());
|
||||
.on_click(|_, window, cx| {
|
||||
window.dispatch_action(OpenRemote.boxed_clone(), cx);
|
||||
})
|
||||
.into_any_element(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_project_host(&self, cx: &mut ViewContext<Self>) -> Option<AnyElement> {
|
||||
pub fn render_project_host(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
|
||||
if self.project.read(cx).is_via_ssh() {
|
||||
return self.render_ssh_project_host(cx);
|
||||
}
|
||||
|
@ -428,21 +441,16 @@ impl TitleBar {
|
|||
.color(Color::Player(participant_index.0))
|
||||
.style(ButtonStyle::Subtle)
|
||||
.label_size(LabelSize::Small)
|
||||
.tooltip(move |cx| {
|
||||
Tooltip::text(
|
||||
format!(
|
||||
"{} is sharing this project. Click to follow.",
|
||||
host_user.github_login.clone()
|
||||
),
|
||||
cx,
|
||||
)
|
||||
})
|
||||
.tooltip(Tooltip::text(format!(
|
||||
"{} is sharing this project. Click to follow.",
|
||||
host_user.github_login.clone()
|
||||
)))
|
||||
.on_click({
|
||||
let host_peer_id = host.peer_id;
|
||||
cx.listener(move |this, _, cx| {
|
||||
cx.listener(move |this, _, window, cx| {
|
||||
this.workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
workspace.follow(host_peer_id, cx);
|
||||
workspace.follow(host_peer_id, window, cx);
|
||||
})
|
||||
.log_err();
|
||||
})
|
||||
|
@ -451,7 +459,7 @@ impl TitleBar {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn render_project_name(&self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
pub fn render_project_name(&self, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let name = {
|
||||
let mut names = self.project.read(cx).visible_worktrees(cx).map(|worktree| {
|
||||
let worktree = worktree.read(cx);
|
||||
|
@ -471,30 +479,29 @@ impl TitleBar {
|
|||
.when(!is_project_selected, |b| b.color(Color::Muted))
|
||||
.style(ButtonStyle::Subtle)
|
||||
.label_size(LabelSize::Small)
|
||||
.tooltip(move |cx| {
|
||||
.tooltip(move |window, cx| {
|
||||
Tooltip::for_action(
|
||||
"Recent Projects",
|
||||
&zed_actions::OpenRecent {
|
||||
create_new_window: false,
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
.on_click(cx.listener(move |_, _, cx| {
|
||||
cx.dispatch_action(
|
||||
.on_click(cx.listener(move |_, _, window, cx| {
|
||||
window.dispatch_action(
|
||||
OpenRecent {
|
||||
create_new_window: false,
|
||||
}
|
||||
.boxed_clone(),
|
||||
cx,
|
||||
);
|
||||
}))
|
||||
}
|
||||
|
||||
// NOTE: Not sure we want to keep this in the titlebar, but for while we are working on Git it is helpful in the short term
|
||||
pub fn render_current_repository(
|
||||
&self,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Option<impl IntoElement> {
|
||||
pub fn render_current_repository(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> {
|
||||
if !self.git_ui_enabled.load(Ordering::SeqCst) {
|
||||
return None;
|
||||
}
|
||||
|
@ -528,7 +535,7 @@ impl TitleBar {
|
|||
))
|
||||
}
|
||||
|
||||
pub fn render_project_branch(&self, cx: &mut ViewContext<Self>) -> Option<impl IntoElement> {
|
||||
pub fn render_project_branch(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> {
|
||||
let entry = {
|
||||
let mut names_and_branches =
|
||||
self.project.read(cx).visible_worktrees(cx).map(|worktree| {
|
||||
|
@ -548,24 +555,25 @@ impl TitleBar {
|
|||
.color(Color::Muted)
|
||||
.style(ButtonStyle::Subtle)
|
||||
.label_size(LabelSize::Small)
|
||||
.tooltip(move |cx| {
|
||||
.tooltip(move |window, cx| {
|
||||
Tooltip::with_meta(
|
||||
"Recent Branches",
|
||||
Some(&zed_actions::branches::OpenRecent),
|
||||
"Local branches only",
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
.on_click(move |_, cx| {
|
||||
.on_click(move |_, window, cx| {
|
||||
let _ = workspace.update(cx, |_this, cx| {
|
||||
cx.dispatch_action(zed_actions::branches::OpenRecent.boxed_clone());
|
||||
window.dispatch_action(zed_actions::branches::OpenRecent.boxed_clone(), cx);
|
||||
});
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
fn window_activation_changed(&mut self, cx: &mut ViewContext<Self>) {
|
||||
if cx.is_window_active() {
|
||||
fn window_activation_changed(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
if window.is_window_active() {
|
||||
ActiveCall::global(cx)
|
||||
.update(cx, |call, cx| call.set_location(Some(&self.project), cx))
|
||||
.detach_and_log_err(cx);
|
||||
|
@ -576,16 +584,16 @@ impl TitleBar {
|
|||
}
|
||||
self.workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
workspace.update_active_view_for_followers(cx);
|
||||
workspace.update_active_view_for_followers(window, cx);
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
|
||||
fn active_call_changed(&mut self, cx: &mut ViewContext<Self>) {
|
||||
fn active_call_changed(&mut self, cx: &mut Context<Self>) {
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
fn share_project(&mut self, _: &ShareProject, cx: &mut ViewContext<Self>) {
|
||||
fn share_project(&mut self, _: &ShareProject, cx: &mut Context<Self>) {
|
||||
let active_call = ActiveCall::global(cx);
|
||||
let project = self.project.clone();
|
||||
active_call
|
||||
|
@ -593,7 +601,7 @@ impl TitleBar {
|
|||
.detach_and_log_err(cx);
|
||||
}
|
||||
|
||||
fn unshare_project(&mut self, _: &UnshareProject, cx: &mut ViewContext<Self>) {
|
||||
fn unshare_project(&mut self, _: &UnshareProject, _: &mut Window, cx: &mut Context<Self>) {
|
||||
let active_call = ActiveCall::global(cx);
|
||||
let project = self.project.clone();
|
||||
active_call
|
||||
|
@ -604,7 +612,7 @@ impl TitleBar {
|
|||
fn render_connection_status(
|
||||
&self,
|
||||
status: &client::Status,
|
||||
cx: &mut ViewContext<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Option<AnyElement> {
|
||||
match status {
|
||||
client::Status::ConnectionError
|
||||
|
@ -615,7 +623,7 @@ impl TitleBar {
|
|||
div()
|
||||
.id("disconnected")
|
||||
.child(Icon::new(IconName::Disconnected).size(IconSize::Small))
|
||||
.tooltip(|cx| Tooltip::text("Disconnected", cx))
|
||||
.tooltip(Tooltip::text("Disconnected"))
|
||||
.into_any_element(),
|
||||
),
|
||||
client::Status::UpgradeRequired => {
|
||||
|
@ -633,14 +641,14 @@ impl TitleBar {
|
|||
Some(
|
||||
Button::new("connection-status", label)
|
||||
.label_size(LabelSize::Small)
|
||||
.on_click(|_, cx| {
|
||||
.on_click(|_, window, cx| {
|
||||
if let Some(auto_updater) = auto_update::AutoUpdater::get(cx) {
|
||||
if auto_updater.read(cx).status().is_updated() {
|
||||
workspace::reload(&Default::default(), cx);
|
||||
return;
|
||||
}
|
||||
}
|
||||
auto_update::check(&Default::default(), cx);
|
||||
auto_update::check(&Default::default(), window, cx);
|
||||
})
|
||||
.into_any_element(),
|
||||
)
|
||||
|
@ -649,29 +657,30 @@ impl TitleBar {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn render_sign_in_button(&mut self, _: &mut ViewContext<Self>) -> Button {
|
||||
pub fn render_sign_in_button(&mut self, _: &mut Context<Self>) -> Button {
|
||||
let client = self.client.clone();
|
||||
Button::new("sign_in", "Sign in")
|
||||
.label_size(LabelSize::Small)
|
||||
.on_click(move |_, cx| {
|
||||
.on_click(move |_, window, cx| {
|
||||
let client = client.clone();
|
||||
cx.spawn(move |mut cx| async move {
|
||||
client
|
||||
.authenticate_and_connect(true, &cx)
|
||||
.await
|
||||
.notify_async_err(&mut cx);
|
||||
})
|
||||
.detach();
|
||||
window
|
||||
.spawn(cx, move |mut cx| async move {
|
||||
client
|
||||
.authenticate_and_connect(true, &cx)
|
||||
.await
|
||||
.notify_async_err(&mut cx);
|
||||
})
|
||||
.detach();
|
||||
})
|
||||
}
|
||||
|
||||
pub fn render_user_menu_button(&mut self, cx: &mut ViewContext<Self>) -> impl Element {
|
||||
pub fn render_user_menu_button(&mut self, cx: &mut Context<Self>) -> impl Element {
|
||||
let user_store = self.user_store.read(cx);
|
||||
if let Some(user) = user_store.current_user() {
|
||||
let plan = user_store.current_plan();
|
||||
PopoverMenu::new("user-menu")
|
||||
.menu(move |cx| {
|
||||
ContextMenu::build(cx, |menu, cx| {
|
||||
.menu(move |window, cx| {
|
||||
ContextMenu::build(window, cx, |menu, _, cx| {
|
||||
menu.when(cx.has_flag::<ZedPro>(), |menu| {
|
||||
menu.action(
|
||||
format!(
|
||||
|
@ -722,13 +731,13 @@ impl TitleBar {
|
|||
),
|
||||
)
|
||||
.style(ButtonStyle::Subtle)
|
||||
.tooltip(move |cx| Tooltip::text("Toggle User Menu", cx)),
|
||||
.tooltip(Tooltip::text("Toggle User Menu")),
|
||||
)
|
||||
.anchor(gpui::Corner::TopRight)
|
||||
} else {
|
||||
PopoverMenu::new("user-menu")
|
||||
.menu(|cx| {
|
||||
ContextMenu::build(cx, |menu, _| {
|
||||
.menu(|window, cx| {
|
||||
ContextMenu::build(window, cx, |menu, _, _| {
|
||||
menu.action("Settings", zed_actions::OpenSettings.boxed_clone())
|
||||
.action("Key Bindings", Box::new(zed_actions::OpenKeymap))
|
||||
.action(
|
||||
|
@ -750,7 +759,7 @@ impl TitleBar {
|
|||
.trigger(
|
||||
IconButton::new("user-menu", IconName::ChevronDown)
|
||||
.icon_size(IconSize::Small)
|
||||
.tooltip(move |cx| Tooltip::text("Toggle User Menu", cx)),
|
||||
.tooltip(Tooltip::text("Toggle User Menu")),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ pub struct WindowControlStyle {
|
|||
}
|
||||
|
||||
impl WindowControlStyle {
|
||||
pub fn default(cx: &WindowContext) -> Self {
|
||||
pub fn default(cx: &mut App) -> Self {
|
||||
let colors = cx.theme().colors();
|
||||
|
||||
Self {
|
||||
|
@ -82,7 +82,7 @@ pub struct WindowControl {
|
|||
}
|
||||
|
||||
impl WindowControl {
|
||||
pub fn new(id: impl Into<ElementId>, icon: WindowControlType, cx: &WindowContext) -> Self {
|
||||
pub fn new(id: impl Into<ElementId>, icon: WindowControlType, cx: &mut App) -> Self {
|
||||
let style = WindowControlStyle::default(cx);
|
||||
|
||||
Self {
|
||||
|
@ -97,7 +97,7 @@ impl WindowControl {
|
|||
id: impl Into<ElementId>,
|
||||
icon: WindowControlType,
|
||||
close_action: Box<dyn Action>,
|
||||
cx: &WindowContext,
|
||||
cx: &mut App,
|
||||
) -> Self {
|
||||
let style = WindowControlStyle::default(cx);
|
||||
|
||||
|
@ -125,7 +125,7 @@ impl WindowControl {
|
|||
}
|
||||
|
||||
impl RenderOnce for WindowControl {
|
||||
fn render(self, _cx: &mut WindowContext) -> impl IntoElement {
|
||||
fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement {
|
||||
let icon = svg()
|
||||
.size_4()
|
||||
.flex_none()
|
||||
|
@ -145,18 +145,19 @@ impl RenderOnce for WindowControl {
|
|||
.hover(|this| this.bg(self.style.background_hover))
|
||||
.active(|this| this.bg(self.style.background_hover))
|
||||
.child(icon)
|
||||
.on_mouse_move(|_, cx| cx.stop_propagation())
|
||||
.on_click(move |_, cx| {
|
||||
.on_mouse_move(|_, _, cx| cx.stop_propagation())
|
||||
.on_click(move |_, window, cx| {
|
||||
cx.stop_propagation();
|
||||
match self.icon {
|
||||
WindowControlType::Minimize => cx.minimize_window(),
|
||||
WindowControlType::Restore => cx.zoom_window(),
|
||||
WindowControlType::Maximize => cx.zoom_window(),
|
||||
WindowControlType::Close => cx.dispatch_action(
|
||||
WindowControlType::Minimize => window.minimize_window(),
|
||||
WindowControlType::Restore => window.zoom_window(),
|
||||
WindowControlType::Maximize => window.zoom_window(),
|
||||
WindowControlType::Close => window.dispatch_action(
|
||||
self.close_action
|
||||
.as_ref()
|
||||
.expect("Use WindowControl::new_close() for close control.")
|
||||
.boxed_clone(),
|
||||
cx,
|
||||
),
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue