diff --git a/crates/gpui2/src/app.rs b/crates/gpui2/src/app.rs index 1b9bc023fca22279ddc4736e44c1a2a5361d8107..0cfc85dda8affc2e5b0675a8fc6066eabbf748db 100644 --- a/crates/gpui2/src/app.rs +++ b/crates/gpui2/src/app.rs @@ -267,20 +267,6 @@ impl AppContext { .collect() } - pub(crate) fn read_window( - &mut self, - handle: AnyWindowHandle, - read: impl FnOnce(&WindowContext) -> R, - ) -> Result { - let window = self - .windows - .get(handle.id) - .ok_or_else(|| anyhow!("window not found"))? - .as_ref() - .unwrap(); - Ok(read(&WindowContext::immutable(self, &window))) - } - pub(crate) fn update_window( &mut self, handle: AnyWindowHandle, diff --git a/crates/gpui2/src/app/async_context.rs b/crates/gpui2/src/app/async_context.rs index ae0a20d8facbf87a78357bb2688bd77b7f6cf320..8afd947e74b1f89d829a3e551c29f1d57bbd9999 100644 --- a/crates/gpui2/src/app/async_context.rs +++ b/crates/gpui2/src/app/async_context.rs @@ -58,16 +58,6 @@ impl AsyncAppContext { Ok(f(&mut *lock)) } - pub fn read_window( - &self, - handle: AnyWindowHandle, - update: impl FnOnce(&WindowContext) -> R, - ) -> Result { - let app = self.app.upgrade().context("app was released")?; - let mut app_context = app.lock(); - app_context.read_window(handle, update) - } - pub fn update_window( &self, handle: AnyWindowHandle, @@ -183,7 +173,7 @@ impl AsyncWindowContext { read: impl FnOnce(&G, &WindowContext) -> R, ) -> Result { self.app - .read_window(self.window, |cx| read(cx.global(), cx)) + .update_window(self.window, |cx| read(cx.global(), cx)) } pub fn update_global( diff --git a/crates/gpui2/src/app/test_context.rs b/crates/gpui2/src/app/test_context.rs index 59bfc17dd8de78bbdfd82a01a71aa5b8a6f3732f..2ab61bfd510bfacefd89325468e44a6a31ee1a02 100644 --- a/crates/gpui2/src/app/test_context.rs +++ b/crates/gpui2/src/app/test_context.rs @@ -67,15 +67,6 @@ impl TestAppContext { f(&mut *lock) } - pub fn read_window( - &self, - handle: AnyWindowHandle, - read: impl FnOnce(&WindowContext) -> R, - ) -> R { - let mut app_context = self.app.lock(); - app_context.read_window(handle, read).unwrap() - } - pub fn update_window( &self, handle: AnyWindowHandle, diff --git a/crates/gpui2/src/window.rs b/crates/gpui2/src/window.rs index c90fce8003a7e4286638f7251e3f42543f723afe..cb1ff6c2ad32b4e0af7c32d72fdecb4767da4d54 100644 --- a/crates/gpui2/src/window.rs +++ b/crates/gpui2/src/window.rs @@ -305,20 +305,13 @@ impl ContentMask { /// Provides access to application state in the context of a single window. Derefs /// to an `AppContext`, so you can also pass a `WindowContext` to any method that takes /// an `AppContext` and call any `AppContext` methods. -pub struct WindowContext<'a, 'w> { +pub struct WindowContext<'a> { pub(crate) app: Reference<'a, AppContext>, - pub(crate) window: Reference<'w, Window>, + pub(crate) window: Reference<'a, Window>, } -impl<'a, 'w> WindowContext<'a, 'w> { - pub(crate) fn immutable(app: &'a AppContext, window: &'w Window) -> Self { - Self { - app: Reference::Immutable(app), - window: Reference::Immutable(window), - } - } - - pub(crate) fn mutable(app: &'a mut AppContext, window: &'w mut Window) -> Self { +impl<'a> WindowContext<'a> { + pub(crate) fn mutable(app: &'a mut AppContext, window: &'a mut Window) -> Self { Self { app: Reference::Mutable(app), window: Reference::Mutable(window), @@ -388,7 +381,7 @@ impl<'a, 'w> WindowContext<'a, 'w> { pub fn subscribe( &mut self, entity: &E, - mut on_event: impl FnMut(E, &Emitter::Event, &mut WindowContext<'_, '_>) + Send + 'static, + mut on_event: impl FnMut(E, &Emitter::Event, &mut WindowContext<'_>) + Send + 'static, ) -> Subscription where Emitter: EventEmitter, @@ -419,7 +412,7 @@ impl<'a, 'w> WindowContext<'a, 'w> { /// of the window. pub fn run_on_main( &mut self, - f: impl FnOnce(&mut MainThread>) -> R + Send + 'static, + f: impl FnOnce(&mut MainThread>) -> R + Send + 'static, ) -> Task> where R: Send + 'static, @@ -1185,7 +1178,7 @@ impl<'a, 'w> WindowContext<'a, 'w> { /// is updated. pub fn observe_global( &mut self, - f: impl Fn(&mut WindowContext<'_, '_>) + Send + 'static, + f: impl Fn(&mut WindowContext<'_>) + Send + 'static, ) -> Subscription { let window_handle = self.window.handle; self.global_observers.insert( @@ -1273,7 +1266,7 @@ impl<'a, 'w> WindowContext<'a, 'w> { } } -impl Context for WindowContext<'_, '_> { +impl Context for WindowContext<'_> { type ModelContext<'a, T> = ModelContext<'a, T>; type Result = T; @@ -1304,7 +1297,7 @@ impl Context for WindowContext<'_, '_> { } } -impl VisualContext for WindowContext<'_, '_> { +impl VisualContext for WindowContext<'_> { type ViewContext<'a, V: 'static> = ViewContext<'a, V>; fn build_view( @@ -1338,7 +1331,7 @@ impl VisualContext for WindowContext<'_, '_> { } } -impl<'a, 'w> std::ops::Deref for WindowContext<'a, 'w> { +impl<'a> std::ops::Deref for WindowContext<'a> { type Target = AppContext; fn deref(&self) -> &Self::Target { @@ -1346,19 +1339,19 @@ impl<'a, 'w> std::ops::Deref for WindowContext<'a, 'w> { } } -impl<'a, 'w> std::ops::DerefMut for WindowContext<'a, 'w> { +impl<'a> std::ops::DerefMut for WindowContext<'a> { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.app } } -impl<'a, 'w> Borrow for WindowContext<'a, 'w> { +impl<'a> Borrow for WindowContext<'a> { fn borrow(&self) -> &AppContext { &self.app } } -impl<'a, 'w> BorrowMut for WindowContext<'a, 'w> { +impl<'a> BorrowMut for WindowContext<'a> { fn borrow_mut(&mut self) -> &mut AppContext { &mut self.app } @@ -1526,13 +1519,13 @@ pub trait BorrowWindow: BorrowMut + BorrowMut { } } -impl Borrow for WindowContext<'_, '_> { +impl Borrow for WindowContext<'_> { fn borrow(&self) -> &Window { &self.window } } -impl BorrowMut for WindowContext<'_, '_> { +impl BorrowMut for WindowContext<'_> { fn borrow_mut(&mut self) -> &mut Window { &mut self.window } @@ -1541,7 +1534,7 @@ impl BorrowMut for WindowContext<'_, '_> { impl BorrowWindow for T where T: BorrowMut + BorrowMut {} pub struct ViewContext<'a, V> { - window_cx: WindowContext<'a, 'a>, + window_cx: WindowContext<'a>, view: &'a View, } @@ -1740,7 +1733,7 @@ impl<'a, V: 'static> ViewContext<'a, V> { move |event: &dyn Any, context_stack: &[&DispatchContext], phase: DispatchPhase, - cx: &mut WindowContext<'_, '_>| { + cx: &mut WindowContext<'_>| { handle .update(cx, |view, cx| { listener(view, event, context_stack, phase, cx) @@ -1952,7 +1945,7 @@ impl VisualContext for ViewContext<'_, V> { } impl<'a, V> std::ops::Deref for ViewContext<'a, V> { - type Target = WindowContext<'a, 'a>; + type Target = WindowContext<'a>; fn deref(&self) -> &Self::Target { &self.window_cx