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:
Nathan Sobo 2025-01-25 20:02:45 -07:00 committed by GitHub
parent 21b4a0d50e
commit 6fca1d2b0b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
648 changed files with 36248 additions and 28208 deletions

View file

@ -1,13 +1,13 @@
use std::path::PathBuf;
use gpui::{ClickEvent, DismissEvent, EventEmitter, FocusHandle, FocusableView, Render, WeakView};
use gpui::{ClickEvent, DismissEvent, EventEmitter, FocusHandle, Focusable, Render, WeakEntity};
use project::project_settings::ProjectSettings;
use remote::SshConnectionOptions;
use settings::Settings;
use ui::{
div, h_flex, rems, Button, ButtonCommon, ButtonStyle, Clickable, ElevationIndex, FluentBuilder,
Headline, HeadlineSize, IconName, IconPosition, InteractiveElement, IntoElement, Label, Modal,
ModalFooter, ModalHeader, ParentElement, Section, Styled, StyledExt, ViewContext,
div, h_flex, rems, Button, ButtonCommon, ButtonStyle, Clickable, Context, ElevationIndex,
FluentBuilder, Headline, HeadlineSize, IconName, IconPosition, InteractiveElement, IntoElement,
Label, Modal, ModalFooter, ModalHeader, ParentElement, Section, Styled, StyledExt, Window,
};
use workspace::{notifications::DetachAndPromptErr, ModalView, OpenOptions, Workspace};
@ -19,20 +19,24 @@ enum Host {
}
pub struct DisconnectedOverlay {
workspace: WeakView<Workspace>,
workspace: WeakEntity<Workspace>,
host: Host,
focus_handle: FocusHandle,
finished: bool,
}
impl EventEmitter<DismissEvent> for DisconnectedOverlay {}
impl FocusableView for DisconnectedOverlay {
fn focus_handle(&self, _cx: &gpui::AppContext) -> gpui::FocusHandle {
impl Focusable for DisconnectedOverlay {
fn focus_handle(&self, _cx: &gpui::App) -> gpui::FocusHandle {
self.focus_handle.clone()
}
}
impl ModalView for DisconnectedOverlay {
fn on_before_dismiss(&mut self, _: &mut ViewContext<Self>) -> workspace::DismissDecision {
fn on_before_dismiss(
&mut self,
_window: &mut Window,
_: &mut Context<Self>,
) -> workspace::DismissDecision {
return workspace::DismissDecision::Dismiss(self.finished);
}
fn fade_out_background(&self) -> bool {
@ -41,40 +45,52 @@ impl ModalView for DisconnectedOverlay {
}
impl DisconnectedOverlay {
pub fn register(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
cx.subscribe(workspace.project(), |workspace, project, event, cx| {
if !matches!(
event,
project::Event::DisconnectedFromHost | project::Event::DisconnectedFromSshRemote
) {
return;
}
let handle = cx.view().downgrade();
pub fn register(
workspace: &mut Workspace,
window: Option<&mut Window>,
cx: &mut Context<Workspace>,
) {
let Some(window) = window else {
return;
};
cx.subscribe_in(
workspace.project(),
window,
|workspace, project, event, window, cx| {
if !matches!(
event,
project::Event::DisconnectedFromHost
| project::Event::DisconnectedFromSshRemote
) {
return;
}
let handle = cx.model().downgrade();
let ssh_connection_options = project.read(cx).ssh_connection_options(cx);
let host = if let Some(ssh_connection_options) = ssh_connection_options {
Host::SshRemoteProject(ssh_connection_options)
} else {
Host::RemoteProject
};
let ssh_connection_options = project.read(cx).ssh_connection_options(cx);
let host = if let Some(ssh_connection_options) = ssh_connection_options {
Host::SshRemoteProject(ssh_connection_options)
} else {
Host::RemoteProject
};
workspace.toggle_modal(cx, |cx| DisconnectedOverlay {
finished: false,
workspace: handle,
host,
focus_handle: cx.focus_handle(),
});
})
workspace.toggle_modal(window, cx, |_, cx| DisconnectedOverlay {
finished: false,
workspace: handle,
host,
focus_handle: cx.focus_handle(),
});
},
)
.detach();
}
fn handle_reconnect(&mut self, _: &ClickEvent, cx: &mut ViewContext<Self>) {
fn handle_reconnect(&mut self, _: &ClickEvent, window: &mut Window, cx: &mut Context<Self>) {
self.finished = true;
cx.emit(DismissEvent);
match &self.host {
Host::SshRemoteProject(ssh_connection_options) => {
self.reconnect_to_ssh_remote(ssh_connection_options.clone(), cx);
self.reconnect_to_ssh_remote(ssh_connection_options.clone(), window, cx);
}
_ => {}
}
@ -83,7 +99,8 @@ impl DisconnectedOverlay {
fn reconnect_to_ssh_remote(
&self,
connection_options: SshConnectionOptions,
cx: &mut ViewContext<Self>,
window: &mut Window,
cx: &mut Context<Self>,
) {
let Some(workspace) = self.workspace.upgrade() else {
return;
@ -93,7 +110,7 @@ impl DisconnectedOverlay {
return;
};
let Some(window) = cx.window_handle().downcast::<Workspace>() else {
let Some(window_handle) = window.window_handle().downcast::<Workspace>() else {
return;
};
@ -101,13 +118,13 @@ impl DisconnectedOverlay {
let paths = ssh_project.paths.iter().map(PathBuf::from).collect();
cx.spawn(move |_, mut cx| async move {
cx.spawn_in(window, move |_, mut cx| async move {
open_ssh_project(
connection_options,
paths,
app_state,
OpenOptions {
replace_window: Some(window),
replace_window: Some(window_handle),
..Default::default()
},
&mut cx,
@ -115,17 +132,17 @@ impl DisconnectedOverlay {
.await?;
Ok(())
})
.detach_and_prompt_err("Failed to reconnect", cx, |_, _| None);
.detach_and_prompt_err("Failed to reconnect", window, cx, |_, _, _| None);
}
fn cancel(&mut self, _: &menu::Cancel, cx: &mut ViewContext<Self>) {
fn cancel(&mut self, _: &menu::Cancel, _: &mut Window, cx: &mut Context<Self>) {
self.finished = true;
cx.emit(DismissEvent)
}
}
impl Render for DisconnectedOverlay {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let can_reconnect = matches!(self.host, Host::SshRemoteProject(_));
let message = match &self.host {
@ -171,8 +188,8 @@ impl Render for DisconnectedOverlay {
Button::new("close-window", "Close Window")
.style(ButtonStyle::Filled)
.layer(ElevationIndex::ModalSurface)
.on_click(cx.listener(move |_, _, cx| {
cx.remove_window();
.on_click(cx.listener(move |_, _, window, _| {
window.remove_window();
})),
)
.when(can_reconnect, |el| {

View file

@ -6,8 +6,8 @@ pub use ssh_connections::{is_connecting_over_ssh, open_ssh_project};
use disconnected_overlay::DisconnectedOverlay;
use fuzzy::{StringMatch, StringMatchCandidate};
use gpui::{
Action, AnyElement, AppContext, DismissEvent, EventEmitter, FocusHandle, FocusableView,
Subscription, Task, View, ViewContext, WeakView,
Action, AnyElement, App, Context, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable,
Subscription, Task, WeakEntity, Window,
};
use ordered_float::OrderedFloat;
use picker::{
@ -29,16 +29,15 @@ use workspace::{
};
use zed_actions::{OpenRecent, OpenRemote};
pub fn init(cx: &mut AppContext) {
pub fn init(cx: &mut App) {
SshSettings::register(cx);
cx.observe_new_views(RecentProjects::register).detach();
cx.observe_new_views(RemoteServerProjects::register)
.detach();
cx.observe_new_views(DisconnectedOverlay::register).detach();
cx.observe_new(RecentProjects::register).detach();
cx.observe_new(RemoteServerProjects::register).detach();
cx.observe_new(DisconnectedOverlay::register).detach();
}
pub struct RecentProjects {
pub picker: View<Picker<RecentProjectsDelegate>>,
pub picker: Entity<Picker<RecentProjectsDelegate>>,
rem_width: f32,
_subscription: Subscription,
}
@ -46,28 +45,33 @@ pub struct RecentProjects {
impl ModalView for RecentProjects {}
impl RecentProjects {
fn new(delegate: RecentProjectsDelegate, rem_width: f32, cx: &mut ViewContext<Self>) -> Self {
let picker = cx.new_view(|cx| {
fn new(
delegate: RecentProjectsDelegate,
rem_width: f32,
window: &mut Window,
cx: &mut Context<Self>,
) -> Self {
let picker = cx.new(|cx| {
// We want to use a list when we render paths, because the items can have different heights (multiple paths).
if delegate.render_paths {
Picker::list(delegate, cx)
Picker::list(delegate, window, cx)
} else {
Picker::uniform_list(delegate, cx)
Picker::uniform_list(delegate, window, cx)
}
});
let _subscription = cx.subscribe(&picker, |_, _, _, cx| cx.emit(DismissEvent));
// We do not want to block the UI on a potentially lengthy call to DB, so we're gonna swap
// out workspace locations once the future runs to completion.
cx.spawn(|this, mut cx| async move {
cx.spawn_in(window, |this, mut cx| async move {
let workspaces = WORKSPACE_DB
.recent_workspaces_on_disk()
.await
.log_err()
.unwrap_or_default();
this.update(&mut cx, move |this, cx| {
this.update_in(&mut cx, move |this, window, cx| {
this.picker.update(cx, move |picker, cx| {
picker.delegate.set_workspaces(workspaces);
picker.update_matches(picker.query(cx), cx)
picker.update_matches(picker.query(cx), window, cx)
})
})
.ok()
@ -80,17 +84,21 @@ impl RecentProjects {
}
}
fn register(workspace: &mut Workspace, _cx: &mut ViewContext<Workspace>) {
workspace.register_action(|workspace, open_recent: &OpenRecent, cx| {
fn register(
workspace: &mut Workspace,
_window: Option<&mut Window>,
_cx: &mut Context<Workspace>,
) {
workspace.register_action(|workspace, open_recent: &OpenRecent, window, cx| {
let Some(recent_projects) = workspace.active_modal::<Self>(cx) else {
Self::open(workspace, open_recent.create_new_window, cx);
Self::open(workspace, open_recent.create_new_window, window, cx);
return;
};
recent_projects.update(cx, |recent_projects, cx| {
recent_projects
.picker
.update(cx, |picker, cx| picker.cycle_selection(cx))
.update(cx, |picker, cx| picker.cycle_selection(window, cx))
});
});
}
@ -98,40 +106,41 @@ impl RecentProjects {
pub fn open(
workspace: &mut Workspace,
create_new_window: bool,
cx: &mut ViewContext<Workspace>,
window: &mut Window,
cx: &mut Context<Workspace>,
) {
let weak = cx.view().downgrade();
workspace.toggle_modal(cx, |cx| {
let weak = cx.model().downgrade();
workspace.toggle_modal(window, cx, |window, cx| {
let delegate = RecentProjectsDelegate::new(weak, create_new_window, true);
Self::new(delegate, 34., cx)
Self::new(delegate, 34., window, cx)
})
}
}
impl EventEmitter<DismissEvent> for RecentProjects {}
impl FocusableView for RecentProjects {
fn focus_handle(&self, cx: &AppContext) -> FocusHandle {
impl Focusable for RecentProjects {
fn focus_handle(&self, cx: &App) -> FocusHandle {
self.picker.focus_handle(cx)
}
}
impl Render for RecentProjects {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
v_flex()
.w(rems(self.rem_width))
.child(self.picker.clone())
.on_mouse_down_out(cx.listener(|this, _, cx| {
.on_mouse_down_out(cx.listener(|this, _, window, cx| {
this.picker.update(cx, |this, cx| {
this.cancel(&Default::default(), cx);
this.cancel(&Default::default(), window, cx);
})
}))
}
}
pub struct RecentProjectsDelegate {
workspace: WeakView<Workspace>,
workspace: WeakEntity<Workspace>,
workspaces: Vec<(WorkspaceId, SerializedWorkspaceLocation)>,
selected_match_index: usize,
matches: Vec<StringMatch>,
@ -143,7 +152,7 @@ pub struct RecentProjectsDelegate {
}
impl RecentProjectsDelegate {
fn new(workspace: WeakView<Workspace>, create_new_window: bool, render_paths: bool) -> Self {
fn new(workspace: WeakEntity<Workspace>, create_new_window: bool, render_paths: bool) -> Self {
Self {
workspace,
workspaces: Vec::new(),
@ -168,16 +177,16 @@ impl EventEmitter<DismissEvent> for RecentProjectsDelegate {}
impl PickerDelegate for RecentProjectsDelegate {
type ListItem = ListItem;
fn placeholder_text(&self, cx: &mut WindowContext) -> Arc<str> {
fn placeholder_text(&self, window: &mut Window, _: &mut App) -> Arc<str> {
let (create_window, reuse_window) = if self.create_new_window {
(
cx.keystroke_text_for(&menu::Confirm),
cx.keystroke_text_for(&menu::SecondaryConfirm),
window.keystroke_text_for(&menu::Confirm),
window.keystroke_text_for(&menu::SecondaryConfirm),
)
} else {
(
cx.keystroke_text_for(&menu::SecondaryConfirm),
cx.keystroke_text_for(&menu::Confirm),
window.keystroke_text_for(&menu::SecondaryConfirm),
window.keystroke_text_for(&menu::Confirm),
)
};
Arc::from(format!(
@ -193,14 +202,20 @@ impl PickerDelegate for RecentProjectsDelegate {
self.selected_match_index
}
fn set_selected_index(&mut self, ix: usize, _cx: &mut ViewContext<Picker<Self>>) {
fn set_selected_index(
&mut self,
ix: usize,
_window: &mut Window,
_cx: &mut Context<Picker<Self>>,
) {
self.selected_match_index = ix;
}
fn update_matches(
&mut self,
query: String,
cx: &mut ViewContext<Picker<Self>>,
_: &mut Window,
cx: &mut Context<Picker<Self>>,
) -> gpui::Task<()> {
let query = query.trim_start();
let smart_case = query.chars().any(|c| c.is_uppercase());
@ -244,7 +259,7 @@ impl PickerDelegate for RecentProjectsDelegate {
Task::ready(())
}
fn confirm(&mut self, secondary: bool, cx: &mut ViewContext<Picker<Self>>) {
fn confirm(&mut self, secondary: bool, window: &mut Window, cx: &mut Context<Picker<Self>>) {
if let Some((selected_match, workspace)) = self
.matches
.get(self.selected_index())
@ -266,20 +281,22 @@ impl PickerDelegate for RecentProjectsDelegate {
SerializedWorkspaceLocation::Local(paths, _) => {
let paths = paths.paths().to_vec();
if replace_current_window {
cx.spawn(move |workspace, mut cx| async move {
cx.spawn_in(window, move |workspace, mut cx| async move {
let continue_replacing = workspace
.update(&mut cx, |workspace, cx| {
.update_in(&mut cx, |workspace, window, cx| {
workspace.prepare_to_close(
CloseIntent::ReplaceWindow,
window,
cx,
)
})?
.await?;
if continue_replacing {
workspace
.update(&mut cx, |workspace, cx| {
workspace
.open_workspace_for_paths(true, paths, cx)
.update_in(&mut cx, |workspace, window, cx| {
workspace.open_workspace_for_paths(
true, paths, window, cx,
)
})?
.await
} else {
@ -287,14 +304,14 @@ impl PickerDelegate for RecentProjectsDelegate {
}
})
} else {
workspace.open_workspace_for_paths(false, paths, cx)
workspace.open_workspace_for_paths(false, paths, window, cx)
}
}
SerializedWorkspaceLocation::Ssh(ssh_project) => {
let app_state = workspace.app_state().clone();
let replace_window = if replace_current_window {
cx.window_handle().downcast::<Workspace>()
window.window_handle().downcast::<Workspace>()
} else {
None
};
@ -313,7 +330,7 @@ impl PickerDelegate for RecentProjectsDelegate {
let paths = ssh_project.paths.iter().map(PathBuf::from).collect();
cx.spawn(|_, mut cx| async move {
cx.spawn_in(window, |_, mut cx| async move {
open_ssh_project(
connection_options,
paths,
@ -332,9 +349,9 @@ impl PickerDelegate for RecentProjectsDelegate {
}
}
fn dismissed(&mut self, _: &mut ViewContext<Picker<Self>>) {}
fn dismissed(&mut self, _window: &mut Window, _: &mut Context<Picker<Self>>) {}
fn no_matches_text(&self, _cx: &mut WindowContext) -> SharedString {
fn no_matches_text(&self, _window: &mut Window, _cx: &mut App) -> SharedString {
if self.workspaces.is_empty() {
"Recently opened projects will show up here".into()
} else {
@ -346,7 +363,8 @@ impl PickerDelegate for RecentProjectsDelegate {
&self,
ix: usize,
selected: bool,
cx: &mut ViewContext<Picker<Self>>,
window: &mut Window,
cx: &mut Context<Picker<Self>>,
) -> Option<Self::ListItem> {
let hit = self.matches.get(ix)?;
@ -398,7 +416,7 @@ impl PickerDelegate for RecentProjectsDelegate {
if !self.render_paths {
highlighted.paths.clear();
}
highlighted.render(cx)
highlighted.render(window, cx)
}),
)
.map(|el| {
@ -406,13 +424,13 @@ impl PickerDelegate for RecentProjectsDelegate {
.child(
IconButton::new("delete", IconName::Close)
.icon_size(IconSize::Small)
.on_click(cx.listener(move |this, _event, cx| {
.on_click(cx.listener(move |this, _event, window, cx| {
cx.stop_propagation();
cx.prevent_default();
window.prevent_default();
this.delegate.delete_recent_project(ix, cx)
this.delegate.delete_recent_project(ix, window, cx)
}))
.tooltip(|cx| Tooltip::text("Delete from Recent Projects...", cx)),
.tooltip(Tooltip::text("Delete from Recent Projects...")),
)
.into_any_element();
@ -422,9 +440,9 @@ impl PickerDelegate for RecentProjectsDelegate {
el.end_hover_slot::<AnyElement>(delete_button)
}
})
.tooltip(move |cx| {
.tooltip(move |_, cx| {
let tooltip_highlighted_location = highlighted_match.clone();
cx.new_view(move |_| MatchTooltip {
cx.new(|_| MatchTooltip {
highlighted_location: tooltip_highlighted_location,
})
.into()
@ -432,7 +450,11 @@ impl PickerDelegate for RecentProjectsDelegate {
)
}
fn render_footer(&self, cx: &mut ViewContext<Picker<Self>>) -> Option<AnyElement> {
fn render_footer(
&self,
window: &mut Window,
cx: &mut Context<Picker<Self>>,
) -> Option<AnyElement> {
Some(
h_flex()
.w_full()
@ -443,13 +465,17 @@ impl PickerDelegate for RecentProjectsDelegate {
.border_color(cx.theme().colors().border_variant)
.child(
Button::new("remote", "Open Remote Folder")
.key_binding(KeyBinding::for_action(&OpenRemote, cx))
.on_click(|_, cx| cx.dispatch_action(OpenRemote.boxed_clone())),
.key_binding(KeyBinding::for_action(&OpenRemote, window))
.on_click(|_, window, cx| {
window.dispatch_action(OpenRemote.boxed_clone(), cx)
}),
)
.child(
Button::new("local", "Open Local Folder")
.key_binding(KeyBinding::for_action(&workspace::Open, cx))
.on_click(|_, cx| cx.dispatch_action(workspace::Open.boxed_clone())),
.key_binding(KeyBinding::for_action(&workspace::Open, window))
.on_click(|_, window, cx| {
window.dispatch_action(workspace::Open.boxed_clone(), cx)
}),
)
.into_any(),
)
@ -506,20 +532,27 @@ fn highlights_for_path(
)
}
impl RecentProjectsDelegate {
fn delete_recent_project(&self, ix: usize, cx: &mut ViewContext<Picker<Self>>) {
fn delete_recent_project(
&self,
ix: usize,
window: &mut Window,
cx: &mut Context<Picker<Self>>,
) {
if let Some(selected_match) = self.matches.get(ix) {
let (workspace_id, _) = self.workspaces[selected_match.candidate_id];
cx.spawn(move |this, mut cx| async move {
cx.spawn_in(window, move |this, mut cx| async move {
let _ = WORKSPACE_DB.delete_workspace_by_id(workspace_id).await;
let workspaces = WORKSPACE_DB
.recent_workspaces_on_disk()
.await
.unwrap_or_default();
this.update(&mut cx, move |picker, cx| {
this.update_in(&mut cx, move |picker, window, cx| {
picker.delegate.set_workspaces(workspaces);
picker.delegate.set_selected_index(ix.saturating_sub(1), cx);
picker
.delegate
.set_selected_index(ix.saturating_sub(1), window, cx);
picker.delegate.reset_selected_match_index = false;
picker.update_matches(picker.query(cx), cx)
picker.update_matches(picker.query(cx), window, cx)
})
})
.detach();
@ -529,7 +562,7 @@ impl RecentProjectsDelegate {
fn is_current_workspace(
&self,
workspace_id: WorkspaceId,
cx: &mut ViewContext<Picker<Self>>,
cx: &mut Context<Picker<Self>>,
) -> bool {
if let Some(workspace) = self.workspace.upgrade() {
let workspace = workspace.read(cx);
@ -546,8 +579,8 @@ struct MatchTooltip {
}
impl Render for MatchTooltip {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
tooltip_container(cx, |div, _| {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
tooltip_container(window, cx, |div, _, _| {
self.highlighted_location.render_paths_children(div)
})
}
@ -602,7 +635,7 @@ mod tests {
let workspace = cx.update(|cx| cx.windows()[0].downcast::<Workspace>().unwrap());
workspace
.update(cx, |workspace, _| assert!(!workspace.is_edited()))
.update(cx, |workspace, _, _| assert!(!workspace.is_edited()))
.unwrap();
let editor = workspace
@ -615,17 +648,17 @@ mod tests {
})
.unwrap();
workspace
.update(cx, |_, cx| {
editor.update(cx, |editor, cx| editor.insert("EDIT", cx));
.update(cx, |_, window, cx| {
editor.update(cx, |editor, cx| editor.insert("EDIT", window, cx));
})
.unwrap();
workspace
.update(cx, |workspace, _| assert!(workspace.is_edited(), "After inserting more text into the editor without saving, we should have a dirty project"))
.update(cx, |workspace, _, _| assert!(workspace.is_edited(), "After inserting more text into the editor without saving, we should have a dirty project"))
.unwrap();
let recent_projects_picker = open_recent_projects(&workspace, cx);
workspace
.update(cx, |_, cx| {
.update(cx, |_, _, cx| {
recent_projects_picker.update(cx, |picker, cx| {
assert_eq!(picker.query(cx), "");
let delegate = &mut picker.delegate;
@ -649,7 +682,7 @@ mod tests {
);
cx.dispatch_action(*workspace, menu::Confirm);
workspace
.update(cx, |workspace, cx| {
.update(cx, |workspace, _, cx| {
assert!(
workspace.active_modal::<RecentProjects>(cx).is_none(),
"Should remove the modal after selecting new recent project"
@ -667,7 +700,7 @@ mod tests {
"Should have no pending prompt after cancelling"
);
workspace
.update(cx, |workspace, _| {
.update(cx, |workspace, _, _| {
assert!(
workspace.is_edited(),
"Should be in the same dirty project after cancelling"
@ -679,7 +712,7 @@ mod tests {
fn open_recent_projects(
workspace: &WindowHandle<Workspace>,
cx: &mut TestAppContext,
) -> View<Picker<RecentProjectsDelegate>> {
) -> Entity<Picker<RecentProjectsDelegate>> {
cx.dispatch_action(
(*workspace).into(),
OpenRecent {
@ -687,7 +720,7 @@ mod tests {
},
);
workspace
.update(cx, |workspace, cx| {
.update(cx, |workspace, _, cx| {
workspace
.active_modal::<RecentProjects>(cx)
.unwrap()

File diff suppressed because it is too large Load diff

View file

@ -7,11 +7,10 @@ use editor::Editor;
use extension_host::ExtensionStore;
use futures::channel::oneshot;
use gpui::{
percentage, Animation, AnimationExt, AnyWindowHandle, AsyncAppContext, DismissEvent,
EventEmitter, FocusableView, FontFeatures, ParentElement as _, PromptLevel, Render,
SemanticVersion, SharedString, Task, TextStyleRefinement, Transformation, View, WeakView,
percentage, Animation, AnimationExt, AnyWindowHandle, App, AsyncAppContext, DismissEvent,
Entity, EventEmitter, Focusable, FontFeatures, ParentElement as _, PromptLevel, Render,
SemanticVersion, SharedString, Task, TextStyleRefinement, Transformation, WeakEntity,
};
use gpui::{AppContext, Model};
use language::CursorShape;
use markdown::{Markdown, MarkdownStyle};
@ -23,8 +22,8 @@ use serde::{Deserialize, Serialize};
use settings::{Settings, SettingsSources};
use theme::ThemeSettings;
use ui::{
prelude::*, ActiveTheme, Color, Icon, IconName, IconSize, InteractiveElement, IntoElement,
Label, LabelCommon, Styled, ViewContext, VisualContext, WindowContext,
prelude::*, ActiveTheme, Color, Context, Icon, IconName, IconSize, InteractiveElement,
IntoElement, Label, LabelCommon, Styled, Window,
};
use workspace::{AppState, ModalView, Workspace};
@ -118,7 +117,7 @@ impl Settings for SshSettings {
type FileContent = RemoteSettingsContent;
fn load(sources: SettingsSources<Self::FileContent>, _: &mut AppContext) -> Result<Self> {
fn load(sources: SettingsSources<Self::FileContent>, _: &mut App) -> Result<Self> {
sources.json_merge()
}
}
@ -127,9 +126,9 @@ pub struct SshPrompt {
connection_string: SharedString,
nickname: Option<SharedString>,
status_message: Option<SharedString>,
prompt: Option<(View<Markdown>, oneshot::Sender<Result<String>>)>,
prompt: Option<(Entity<Markdown>, oneshot::Sender<Result<String>>)>,
cancellation: Option<oneshot::Sender<()>>,
editor: View<Editor>,
editor: Entity<Editor>,
}
impl Drop for SshPrompt {
@ -141,7 +140,7 @@ impl Drop for SshPrompt {
}
pub struct SshConnectionModal {
pub(crate) prompt: View<SshPrompt>,
pub(crate) prompt: Entity<SshPrompt>,
paths: Vec<PathBuf>,
finished: bool,
}
@ -149,7 +148,8 @@ pub struct SshConnectionModal {
impl SshPrompt {
pub(crate) fn new(
connection_options: &SshConnectionOptions,
cx: &mut ViewContext<Self>,
window: &mut Window,
cx: &mut Context<Self>,
) -> Self {
let connection_string = connection_options.connection_string().into();
let nickname = connection_options.nickname.clone().map(|s| s.into());
@ -157,7 +157,7 @@ impl SshPrompt {
Self {
connection_string,
nickname,
editor: cx.new_view(Editor::single_line),
editor: cx.new(|cx| Editor::single_line(window, cx)),
status_message: None,
cancellation: None,
prompt: None,
@ -172,11 +172,12 @@ impl SshPrompt {
&mut self,
prompt: String,
tx: oneshot::Sender<Result<String>>,
cx: &mut ViewContext<Self>,
window: &mut Window,
cx: &mut Context<Self>,
) {
let theme = ThemeSettings::get_global(cx);
let mut text_style = cx.text_style();
let mut text_style = window.text_style();
let refinement = TextStyleRefinement {
font_family: Some(theme.buffer_font.family.clone()),
font_features: Some(FontFeatures::disable_ligatures()),
@ -201,33 +202,32 @@ impl SshPrompt {
selection_background_color: cx.theme().players().local().selection,
..Default::default()
};
let markdown = cx.new_view(|cx| Markdown::new_text(prompt, markdown_style, None, None, cx));
let markdown =
cx.new(|cx| Markdown::new_text(prompt, markdown_style, None, None, window, cx));
self.prompt = Some((markdown, tx));
self.status_message.take();
cx.focus_view(&self.editor);
window.focus(&self.editor.focus_handle(cx));
cx.notify();
}
pub fn set_status(&mut self, status: Option<String>, cx: &mut ViewContext<Self>) {
pub fn set_status(&mut self, status: Option<String>, cx: &mut Context<Self>) {
self.status_message = status.map(|s| s.into());
cx.notify();
}
pub fn confirm(&mut self, cx: &mut ViewContext<Self>) {
pub fn confirm(&mut self, window: &mut Window, cx: &mut Context<Self>) {
if let Some((_, tx)) = self.prompt.take() {
self.status_message = Some("Connecting".into());
self.editor.update(cx, |editor, cx| {
tx.send(Ok(editor.text(cx))).ok();
editor.clear(cx);
editor.clear(window, cx);
});
}
}
}
impl Render for SshPrompt {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
let cx = cx.window_context();
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
v_flex()
.key_context("PasswordPrompt")
.py_2()
@ -273,25 +273,27 @@ impl SshConnectionModal {
pub(crate) fn new(
connection_options: &SshConnectionOptions,
paths: Vec<PathBuf>,
cx: &mut ViewContext<Self>,
window: &mut Window,
cx: &mut Context<Self>,
) -> Self {
Self {
prompt: cx.new_view(|cx| SshPrompt::new(connection_options, cx)),
prompt: cx.new(|cx| SshPrompt::new(connection_options, window, cx)),
finished: false,
paths,
}
}
fn confirm(&mut self, _: &menu::Confirm, cx: &mut ViewContext<Self>) {
self.prompt.update(cx, |prompt, cx| prompt.confirm(cx))
fn confirm(&mut self, _: &menu::Confirm, window: &mut Window, cx: &mut Context<Self>) {
self.prompt
.update(cx, |prompt, cx| prompt.confirm(window, cx))
}
pub fn finished(&mut self, cx: &mut ViewContext<Self>) {
pub fn finished(&mut self, cx: &mut Context<Self>) {
self.finished = true;
cx.emit(DismissEvent);
}
fn dismiss(&mut self, _: &menu::Cancel, cx: &mut ViewContext<Self>) {
fn dismiss(&mut self, _: &menu::Cancel, _: &mut Window, cx: &mut Context<Self>) {
if let Some(tx) = self
.prompt
.update(cx, |prompt, _cx| prompt.cancellation.take())
@ -309,7 +311,7 @@ pub(crate) struct SshConnectionHeader {
}
impl RenderOnce for SshConnectionHeader {
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
let theme = cx.theme();
let mut header_color = theme.colors().text;
@ -357,7 +359,7 @@ impl RenderOnce for SshConnectionHeader {
}
impl Render for SshConnectionModal {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl ui::IntoElement {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl ui::IntoElement {
let nickname = self.prompt.read(cx).nickname.clone();
let connection_string = self.prompt.read(cx).connection_string.clone();
@ -379,7 +381,7 @@ impl Render for SshConnectionModal {
connection_string,
nickname,
}
.render(cx),
.render(window, cx),
)
.child(
div()
@ -393,8 +395,8 @@ impl Render for SshConnectionModal {
}
}
impl FocusableView for SshConnectionModal {
fn focus_handle(&self, cx: &gpui::AppContext) -> gpui::FocusHandle {
impl Focusable for SshConnectionModal {
fn focus_handle(&self, cx: &gpui::App) -> gpui::FocusHandle {
self.prompt.read(cx).editor.focus_handle(cx)
}
}
@ -402,7 +404,11 @@ impl FocusableView for SshConnectionModal {
impl EventEmitter<DismissEvent> for SshConnectionModal {}
impl ModalView for SshConnectionModal {
fn on_before_dismiss(&mut self, _: &mut ViewContext<Self>) -> workspace::DismissDecision {
fn on_before_dismiss(
&mut self,
_window: &mut Window,
_: &mut Context<Self>,
) -> workspace::DismissDecision {
return workspace::DismissDecision::Dismiss(self.finished);
}
@ -414,7 +420,7 @@ impl ModalView for SshConnectionModal {
#[derive(Clone)]
pub struct SshClientDelegate {
window: AnyWindowHandle,
ui: WeakView<SshPrompt>,
ui: WeakEntity<SshPrompt>,
known_password: Option<String>,
}
@ -430,9 +436,9 @@ impl remote::SshClientDelegate for SshClientDelegate {
tx.send(Ok(password)).ok();
} else {
self.window
.update(cx, |_, cx| {
.update(cx, |_, window, cx| {
self.ui.update(cx, |modal, cx| {
modal.set_prompt(prompt, tx, cx);
modal.set_prompt(prompt, tx, window, cx);
})
})
.ok();
@ -498,7 +504,7 @@ impl remote::SshClientDelegate for SshClientDelegate {
impl SshClientDelegate {
fn update_status(&self, status: Option<&str>, cx: &mut AsyncAppContext) {
self.window
.update(cx, |_, cx| {
.update(cx, |_, _, cx| {
self.ui.update(cx, |modal, cx| {
modal.set_status(status.map(|s| s.to_string()), cx);
})
@ -507,17 +513,18 @@ impl SshClientDelegate {
}
}
pub fn is_connecting_over_ssh(workspace: &Workspace, cx: &AppContext) -> bool {
pub fn is_connecting_over_ssh(workspace: &Workspace, cx: &App) -> bool {
workspace.active_modal::<SshConnectionModal>(cx).is_some()
}
pub fn connect_over_ssh(
unique_identifier: ConnectionIdentifier,
connection_options: SshConnectionOptions,
ui: View<SshPrompt>,
cx: &mut WindowContext,
) -> Task<Result<Option<Model<SshRemoteClient>>>> {
let window = cx.window_handle();
ui: Entity<SshPrompt>,
window: &mut Window,
cx: &mut App,
) -> Task<Result<Option<Entity<SshRemoteClient>>>> {
let window = window.window_handle();
let known_password = connection_options.password.clone();
let (tx, rx) = oneshot::channel();
ui.update(cx, |ui, _cx| ui.set_cancellation_tx(tx));
@ -546,7 +553,7 @@ pub async fn open_ssh_project(
window
} else {
let options = cx.update(|cx| (app_state.build_window_options)(None, cx))?;
cx.open_window(options, |cx| {
cx.open_window(options, |window, cx| {
let project = project::Project::local(
app_state.client.clone(),
app_state.node_runtime.clone(),
@ -556,7 +563,7 @@ pub async fn open_ssh_project(
None,
cx,
);
cx.new_view(|cx| Workspace::new(None, project, app_state.clone(), cx))
cx.new(|cx| Workspace::new(None, project, app_state.clone(), window, cx))
})?
};
@ -565,10 +572,10 @@ pub async fn open_ssh_project(
let delegate = window.update(cx, {
let connection_options = connection_options.clone();
let paths = paths.clone();
move |workspace, cx| {
cx.activate_window();
workspace.toggle_modal(cx, |cx| {
SshConnectionModal::new(&connection_options, paths, cx)
move |workspace, window, cx| {
window.activate_window();
workspace.toggle_modal(window, cx, |window, cx| {
SshConnectionModal::new(&connection_options, paths, window, cx)
});
let ui = workspace
@ -582,7 +589,7 @@ pub async fn open_ssh_project(
});
Some(Arc::new(SshClientDelegate {
window: cx.window_handle(),
window: window.window_handle(),
ui: ui.downgrade(),
known_password: connection_options.password.clone(),
}))
@ -606,7 +613,7 @@ pub async fn open_ssh_project(
.await;
window
.update(cx, |workspace, cx| {
.update(cx, |workspace, _, cx| {
if let Some(ui) = workspace.active_modal::<SshConnectionModal>(cx) {
ui.update(cx, |modal, cx| modal.finished(cx))
}
@ -616,12 +623,13 @@ pub async fn open_ssh_project(
if let Err(e) = did_open_ssh_project {
log::error!("Failed to open project: {:?}", e);
let response = window
.update(cx, |_, cx| {
cx.prompt(
.update(cx, |_, window, cx| {
window.prompt(
PromptLevel::Critical,
"Failed to connect over SSH",
Some(&e.to_string()),
&["Retry", "Ok"],
cx,
)
})?
.await;
@ -632,7 +640,7 @@ pub async fn open_ssh_project(
}
window
.update(cx, |workspace, cx| {
.update(cx, |workspace, _, cx| {
if let Some(client) = workspace.project().read(cx).ssh_client().clone() {
ExtensionStore::global(cx)
.update(cx, |store, cx| store.register_ssh_client(client, cx));