mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-18 08:02:27 +00:00
WIP
This commit is contained in:
parent
a9d7c86307
commit
e8857d959b
4 changed files with 43 additions and 28 deletions
|
@ -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<AnyView> {
|
||||
self.app.update_window(self.window, |cx| cx.root_view())
|
||||
}
|
||||
|
||||
fn build_view<V>(
|
||||
&mut self,
|
||||
build_view_state: impl FnOnce(&mut Self::ViewContext<'_, V>) -> V,
|
||||
|
|
|
@ -215,6 +215,10 @@ impl<C: Context> Context for MainThread<C> {
|
|||
impl<C: VisualContext> VisualContext for MainThread<C> {
|
||||
type ViewContext<'a, V: 'static> = MainThread<C::ViewContext<'a, V>>;
|
||||
|
||||
fn root_view(&self) -> AnyView {
|
||||
self.0.root_view()
|
||||
}
|
||||
|
||||
fn build_view<V>(
|
||||
&mut self,
|
||||
build_view_state: impl FnOnce(&mut Self::ViewContext<'_, V>) -> V,
|
||||
|
|
|
@ -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<AnyView> {
|
||||
self.window
|
||||
.root_view
|
||||
.clone()
|
||||
.expect("we only take the root_view value when we draw")
|
||||
}
|
||||
|
||||
fn build_view<V>(
|
||||
&mut self,
|
||||
build_view_state: impl FnOnce(&mut Self::ViewContext<'_, V>) -> V,
|
||||
|
@ -1966,6 +1971,10 @@ impl<V> Context for ViewContext<'_, V> {
|
|||
impl<V: 'static> VisualContext for ViewContext<'_, V> {
|
||||
type ViewContext<'a, W: 'static> = ViewContext<'a, W>;
|
||||
|
||||
fn root_view(&self) -> Self::Result<AnyView> {
|
||||
self.window_cx.root_view()
|
||||
}
|
||||
|
||||
fn build_view<W: 'static + Send>(
|
||||
&mut self,
|
||||
build_view: impl FnOnce(&mut Self::ViewContext<'_, W>) -> W,
|
||||
|
@ -2034,20 +2043,20 @@ impl<V: 'static + Render> WindowHandle<V> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn update_root<R>(
|
||||
pub fn update_root<C, R>(
|
||||
&self,
|
||||
cx: &mut AppContext,
|
||||
cx: &mut C,
|
||||
update: impl FnOnce(&mut V, &mut ViewContext<V>) -> R,
|
||||
) -> Result<R> {
|
||||
) -> Result<R>
|
||||
where
|
||||
C: Context,
|
||||
{
|
||||
cx.update_window(self.any_handle, |cx| {
|
||||
let root_view = cx
|
||||
.window
|
||||
.root_view
|
||||
.clone()
|
||||
.unwrap()
|
||||
.downcast::<V>()
|
||||
.unwrap();
|
||||
root_view.update(cx, update)
|
||||
let x = Ok(cx.root_view()).flatten();
|
||||
|
||||
// let root_view = x.unwrap().downcast::<V>().unwrap();
|
||||
// root_view.update(cx, update)
|
||||
todo!()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue