diff --git a/crates/gpui2/src/app/async_context.rs b/crates/gpui2/src/app/async_context.rs index 6802b5c1e1..06da000ca6 100644 --- a/crates/gpui2/src/app/async_context.rs +++ b/crates/gpui2/src/app/async_context.rs @@ -1,6 +1,6 @@ use crate::{ - AnyWindowHandle, AppContext, Context, Executor, MainThread, Model, ModelContext, Render, - Result, Task, View, ViewContext, VisualContext, WindowContext, WindowHandle, + AnyView, AnyWindowHandle, AppContext, Context, Executor, MainThread, Model, ModelContext, + Render, Result, Task, View, ViewContext, VisualContext, WindowContext, WindowHandle, }; use anyhow::Context as _; use derive_more::{Deref, DerefMut}; @@ -293,6 +293,10 @@ impl Context for AsyncWindowContext { impl VisualContext for AsyncWindowContext { type ViewContext<'a, V: 'static> = ViewContext<'a, V>; + fn root_view(&self) -> Result { + self.app.update_window(self.window, |cx| cx.root_view()) + } + fn build_view( &mut self, build_view_state: impl FnOnce(&mut Self::ViewContext<'_, V>) -> V, diff --git a/crates/gpui2/src/gpui2.rs b/crates/gpui2/src/gpui2.rs index 5e5ac119d8..74cfed1959 100644 --- a/crates/gpui2/src/gpui2.rs +++ b/crates/gpui2/src/gpui2.rs @@ -215,6 +215,10 @@ impl Context for MainThread { impl VisualContext for MainThread { type ViewContext<'a, V: 'static> = MainThread>; + fn root_view(&self) -> AnyView { + self.0.root_view() + } + fn build_view( &mut self, build_view_state: impl FnOnce(&mut Self::ViewContext<'_, V>) -> V, diff --git a/crates/gpui2/src/window.rs b/crates/gpui2/src/window.rs index 1df49899ca..e6046e14cf 100644 --- a/crates/gpui2/src/window.rs +++ b/crates/gpui2/src/window.rs @@ -1,14 +1,14 @@ use crate::{ px, size, Action, AnyBox, AnyDrag, AnyView, AppContext, AsyncWindowContext, AvailableSpace, Bounds, BoxShadow, Context, Corners, DevicePixels, DispatchContext, DisplayId, Edges, Effect, - Entity, EntityId, EventEmitter, FileDropEvent, FocusEvent, FontId, GlobalElementId, GlyphId, - Hsla, ImageData, InputEvent, IsZero, KeyListener, KeyMatch, KeyMatcher, Keystroke, LayoutId, - MainThread, MainThreadOnly, Model, ModelContext, Modifiers, MonochromeSprite, MouseButton, - MouseDownEvent, MouseMoveEvent, MouseUpEvent, Path, Pixels, PlatformAtlas, PlatformWindow, - Point, PolychromeSprite, Quad, Render, RenderGlyphParams, RenderImageParams, RenderSvgParams, - ScaledPixels, SceneBuilder, Shadow, SharedString, Size, Style, Subscription, TaffyLayoutEngine, - Task, Underline, UnderlineStyle, View, VisualContext, WeakView, WindowOptions, - SUBPIXEL_VARIANTS, + Entity, EntityId, EventEmitter, FileDropEvent, Flatten, FocusEvent, FontId, GlobalElementId, + GlyphId, Hsla, ImageData, InputEvent, IsZero, KeyListener, KeyMatch, KeyMatcher, Keystroke, + LayoutId, MainThread, MainThreadOnly, Model, ModelContext, Modifiers, MonochromeSprite, + MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Path, Pixels, PlatformAtlas, + PlatformWindow, Point, PolychromeSprite, Quad, Render, RenderGlyphParams, RenderImageParams, + RenderSvgParams, ScaledPixels, SceneBuilder, Shadow, SharedString, Size, Style, Subscription, + TaffyLayoutEngine, Task, Underline, UnderlineStyle, View, VisualContext, WeakView, + WindowOptions, SUBPIXEL_VARIANTS, }; use anyhow::Result; use collections::HashMap; @@ -316,8 +316,6 @@ impl<'a> WindowContext<'a> { Self { app, window } } - // fn replace_root(&mut ) - /// Obtain a handle to the window that belongs to this context. pub fn window_handle(&self) -> AnyWindowHandle { self.window.handle @@ -1312,6 +1310,13 @@ impl Context for WindowContext<'_> { impl VisualContext for WindowContext<'_> { type ViewContext<'a, V: 'static> = ViewContext<'a, V>; + fn root_view(&self) -> Self::Result { + self.window + .root_view + .clone() + .expect("we only take the root_view value when we draw") + } + fn build_view( &mut self, build_view_state: impl FnOnce(&mut Self::ViewContext<'_, V>) -> V, @@ -1966,6 +1971,10 @@ impl Context for ViewContext<'_, V> { impl VisualContext for ViewContext<'_, V> { type ViewContext<'a, W: 'static> = ViewContext<'a, W>; + fn root_view(&self) -> Self::Result { + self.window_cx.root_view() + } + fn build_view( &mut self, build_view: impl FnOnce(&mut Self::ViewContext<'_, W>) -> W, @@ -2034,20 +2043,20 @@ impl WindowHandle { } } - pub fn update_root( + pub fn update_root( &self, - cx: &mut AppContext, + cx: &mut C, update: impl FnOnce(&mut V, &mut ViewContext) -> R, - ) -> Result { + ) -> Result + where + C: Context, + { cx.update_window(self.any_handle, |cx| { - let root_view = cx - .window - .root_view - .clone() - .unwrap() - .downcast::() - .unwrap(); - root_view.update(cx, update) + let x = Ok(cx.root_view()).flatten(); + + // let root_view = x.unwrap().downcast::().unwrap(); + // root_view.update(cx, update) + todo!() }) } } diff --git a/crates/workspace2/src/workspace2.rs b/crates/workspace2/src/workspace2.rs index 08cfbc1ee5..e2413c819c 100644 --- a/crates/workspace2/src/workspace2.rs +++ b/crates/workspace2/src/workspace2.rs @@ -887,11 +887,9 @@ impl Workspace { .await .log_err(); - cx.update_global(|_, cx| { - window.update_root(&mut cx, |_, cx| { - // todo!() - // cx.activate_window() - }); + window.update_root(&mut cx, |_, cx| { + // todo!() + // cx.activate_window() }); let workspace = workspace.downgrade();