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
File diff suppressed because it is too large
Load diff
|
@ -1,4 +1,4 @@
|
|||
use gpui::{div, Action, Div, InteractiveElement, View, ViewContext};
|
||||
use gpui::{div, Action, Context, Div, Entity, InteractiveElement, Window};
|
||||
use workspace::Workspace;
|
||||
|
||||
use crate::BufferSearchBar;
|
||||
|
@ -8,20 +8,21 @@ pub trait SearchActionsRegistrar {
|
|||
fn register_handler<A: Action>(&mut self, callback: impl ActionExecutor<A>);
|
||||
}
|
||||
|
||||
type SearchBarActionCallback<A> = fn(&mut BufferSearchBar, &A, &mut ViewContext<BufferSearchBar>);
|
||||
type SearchBarActionCallback<A> =
|
||||
fn(&mut BufferSearchBar, &A, &mut Window, &mut Context<BufferSearchBar>);
|
||||
|
||||
type GetSearchBar<T> =
|
||||
for<'a, 'b> fn(&'a T, &'a mut ViewContext<'b, T>) -> Option<View<BufferSearchBar>>;
|
||||
for<'a, 'b> fn(&'a T, &'a mut Window, &mut Context<'b, T>) -> Option<Entity<BufferSearchBar>>;
|
||||
|
||||
/// Registers search actions on a div that can be taken out.
|
||||
pub struct DivRegistrar<'a, 'b, T: 'static> {
|
||||
div: Option<Div>,
|
||||
cx: &'a mut ViewContext<'b, T>,
|
||||
cx: &'a mut Context<'b, T>,
|
||||
search_getter: GetSearchBar<T>,
|
||||
}
|
||||
|
||||
impl<'a, 'b, T: 'static> DivRegistrar<'a, 'b, T> {
|
||||
pub fn new(search_getter: GetSearchBar<T>, cx: &'a mut ViewContext<'b, T>) -> Self {
|
||||
pub fn new(search_getter: GetSearchBar<T>, cx: &'a mut Context<'b, T>) -> Self {
|
||||
Self {
|
||||
div: Some(div()),
|
||||
cx,
|
||||
|
@ -39,12 +40,12 @@ impl<T: 'static> SearchActionsRegistrar for DivRegistrar<'_, '_, T> {
|
|||
fn register_handler<A: Action>(&mut self, callback: impl ActionExecutor<A>) {
|
||||
let getter = self.search_getter;
|
||||
self.div = self.div.take().map(|div| {
|
||||
div.on_action(self.cx.listener(move |this, action, cx| {
|
||||
let should_notify = (getter)(this, cx)
|
||||
div.on_action(self.cx.listener(move |this, action, window, cx| {
|
||||
let should_notify = (getter)(this, window, cx)
|
||||
.clone()
|
||||
.map(|search_bar| {
|
||||
search_bar.update(cx, |search_bar, cx| {
|
||||
callback.execute(search_bar, action, cx)
|
||||
callback.execute(search_bar, action, window, cx)
|
||||
})
|
||||
})
|
||||
.unwrap_or(false);
|
||||
|
@ -61,8 +62,8 @@ impl<T: 'static> SearchActionsRegistrar for DivRegistrar<'_, '_, T> {
|
|||
/// Register actions for an active pane.
|
||||
impl SearchActionsRegistrar for Workspace {
|
||||
fn register_handler<A: Action>(&mut self, callback: impl ActionExecutor<A>) {
|
||||
self.register_action(move |workspace, action: &A, cx| {
|
||||
if workspace.has_active_modal(cx) {
|
||||
self.register_action(move |workspace, action: &A, window, cx| {
|
||||
if workspace.has_active_modal(window, cx) {
|
||||
cx.propagate();
|
||||
return;
|
||||
}
|
||||
|
@ -73,7 +74,7 @@ impl SearchActionsRegistrar for Workspace {
|
|||
this.toolbar().update(cx, move |this, cx| {
|
||||
if let Some(search_bar) = this.item_of_type::<BufferSearchBar>() {
|
||||
let should_notify = search_bar.update(cx, move |search_bar, cx| {
|
||||
callback.execute(search_bar, action, cx)
|
||||
callback.execute(search_bar, action, window, cx)
|
||||
});
|
||||
if should_notify {
|
||||
cx.notify();
|
||||
|
@ -94,7 +95,8 @@ pub trait ActionExecutor<A: Action>: 'static + Clone {
|
|||
&self,
|
||||
search_bar: &mut BufferSearchBar,
|
||||
action: &A,
|
||||
cx: &mut ViewContext<BufferSearchBar>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<BufferSearchBar>,
|
||||
) -> DidHandleAction;
|
||||
}
|
||||
|
||||
|
@ -111,10 +113,11 @@ impl<A: Action> ActionExecutor<A> for ForDismissed<A> {
|
|||
&self,
|
||||
search_bar: &mut BufferSearchBar,
|
||||
action: &A,
|
||||
cx: &mut ViewContext<BufferSearchBar>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<BufferSearchBar>,
|
||||
) -> DidHandleAction {
|
||||
if search_bar.is_dismissed() {
|
||||
self.0(search_bar, action, cx);
|
||||
self.0(search_bar, action, window, cx);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
@ -135,12 +138,13 @@ impl<A: Action> ActionExecutor<A> for ForDeployed<A> {
|
|||
&self,
|
||||
search_bar: &mut BufferSearchBar,
|
||||
action: &A,
|
||||
cx: &mut ViewContext<BufferSearchBar>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<BufferSearchBar>,
|
||||
) -> DidHandleAction {
|
||||
if search_bar.is_dismissed() || search_bar.active_searchable_item.is_none() {
|
||||
false
|
||||
} else {
|
||||
self.0(search_bar, action, cx);
|
||||
self.0(search_bar, action, window, cx);
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -160,10 +164,11 @@ impl<A: Action> ActionExecutor<A> for WithResults<A> {
|
|||
&self,
|
||||
search_bar: &mut BufferSearchBar,
|
||||
action: &A,
|
||||
cx: &mut ViewContext<BufferSearchBar>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<BufferSearchBar>,
|
||||
) -> DidHandleAction {
|
||||
if search_bar.active_match_index.is_some() {
|
||||
self.0(search_bar, action, cx);
|
||||
self.0(search_bar, action, window, cx);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,7 +1,7 @@
|
|||
use bitflags::bitflags;
|
||||
pub use buffer_search::BufferSearchBar;
|
||||
use editor::SearchSettings;
|
||||
use gpui::{actions, Action, AppContext, FocusHandle, IntoElement};
|
||||
use gpui::{actions, Action, App, FocusHandle, IntoElement};
|
||||
use project::search::SearchQuery;
|
||||
pub use project_search::ProjectSearchView;
|
||||
use ui::{prelude::*, Tooltip};
|
||||
|
@ -13,7 +13,7 @@ pub mod buffer_search;
|
|||
pub mod project_search;
|
||||
pub(crate) mod search_bar;
|
||||
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
pub fn init(cx: &mut App) {
|
||||
menu::init();
|
||||
buffer_search::init(cx);
|
||||
project_search::init(cx);
|
||||
|
@ -107,7 +107,7 @@ impl SearchOptions {
|
|||
&self,
|
||||
active: bool,
|
||||
focus_handle: FocusHandle,
|
||||
action: impl Fn(&gpui::ClickEvent, &mut WindowContext) + 'static,
|
||||
action: impl Fn(&gpui::ClickEvent, &mut Window, &mut App) + 'static,
|
||||
) -> impl IntoElement {
|
||||
IconButton::new(self.label(), self.icon())
|
||||
.on_click(action)
|
||||
|
@ -117,20 +117,20 @@ impl SearchOptions {
|
|||
.tooltip({
|
||||
let action = self.to_toggle_action();
|
||||
let label = self.label();
|
||||
move |cx| Tooltip::for_action_in(label, &*action, &focus_handle, cx)
|
||||
move |window, cx| Tooltip::for_action_in(label, &*action, &focus_handle, window, cx)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn show_no_more_matches(cx: &mut WindowContext) {
|
||||
cx.defer(|cx| {
|
||||
pub(crate) fn show_no_more_matches(window: &mut Window, cx: &mut App) {
|
||||
window.defer(cx, |window, cx| {
|
||||
struct NotifType();
|
||||
let notification_id = NotificationId::unique::<NotifType>();
|
||||
let Some(workspace) = cx.window_handle().downcast::<Workspace>() else {
|
||||
let Some(workspace) = window.window_handle().downcast::<Workspace>() else {
|
||||
return;
|
||||
};
|
||||
workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
.update(cx, |workspace, _, cx| {
|
||||
workspace.show_toast(
|
||||
Toast::new(notification_id.clone(), "No more matches").autohide(),
|
||||
cx,
|
||||
|
|
|
@ -14,7 +14,7 @@ pub(super) fn render_nav_button(
|
|||
icon,
|
||||
)
|
||||
.shape(IconButtonShape::Square)
|
||||
.on_click(|_, cx| cx.dispatch_action(action.boxed_clone()))
|
||||
.tooltip(move |cx| Tooltip::for_action_in(tooltip, action, &focus_handle, cx))
|
||||
.on_click(|_, window, cx| window.dispatch_action(action.boxed_clone(), cx))
|
||||
.tooltip(move |window, cx| Tooltip::for_action_in(tooltip, action, &focus_handle, window, cx))
|
||||
.disabled(!active)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue