Remove more references to 'model' in GPUI APIs (#23693)
Release Notes: - N/A
This commit is contained in:
@@ -603,7 +603,7 @@ impl App {
|
||||
cx.window_update_stack.push(id);
|
||||
let root_view = build_root_view(&mut window, cx);
|
||||
cx.window_update_stack.pop();
|
||||
window.root_model.replace(root_view.into());
|
||||
window.root.replace(root_view.into());
|
||||
window.defer(cx, |window: &mut Window, cx| window.appearance_changed(cx));
|
||||
cx.window_handles.insert(id, window.handle);
|
||||
cx.windows.get_mut(id).unwrap().replace(window);
|
||||
@@ -999,7 +999,7 @@ impl App {
|
||||
.take()
|
||||
.ok_or_else(|| anyhow!("window not found"))?;
|
||||
|
||||
let root_view = window.root_model.clone().unwrap();
|
||||
let root_view = window.root.clone().unwrap();
|
||||
|
||||
cx.window_update_stack.push(window.handle.id);
|
||||
let result = update(root_view, &mut window, cx);
|
||||
@@ -1666,7 +1666,7 @@ impl AppContext for App {
|
||||
.as_ref()
|
||||
.expect("attempted to read a window that is already on the stack");
|
||||
|
||||
let root_view = window.root_model.clone().unwrap();
|
||||
let root_view = window.root.clone().unwrap();
|
||||
let view = root_view
|
||||
.downcast::<T>()
|
||||
.map_err(|_| anyhow!("root view's type has changed"))?;
|
||||
|
||||
@@ -399,9 +399,8 @@ impl VisualContext for AsyncWindowContext {
|
||||
where
|
||||
V: 'static + Render,
|
||||
{
|
||||
self.window.update(self, |_, window, cx| {
|
||||
window.replace_root_model(cx, build_view)
|
||||
})
|
||||
self.window
|
||||
.update(self, |_, window, cx| window.replace_root(cx, build_view))
|
||||
}
|
||||
|
||||
fn focus<V>(&mut self, view: &Entity<V>) -> Self::Result<()>
|
||||
|
||||
@@ -35,14 +35,14 @@ impl<'a, T: 'static> Context<'a, T> {
|
||||
}
|
||||
|
||||
/// Returns a handle to the model belonging to this context.
|
||||
pub fn model(&self) -> Entity<T> {
|
||||
self.weak_model()
|
||||
pub fn entity(&self) -> Entity<T> {
|
||||
self.weak_entity()
|
||||
.upgrade()
|
||||
.expect("The entity must be alive if we have a model context")
|
||||
}
|
||||
|
||||
/// Returns a weak handle to the model belonging to this context.
|
||||
pub fn weak_model(&self) -> WeakEntity<T> {
|
||||
pub fn weak_entity(&self) -> WeakEntity<T> {
|
||||
self.model_state.clone()
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ impl<'a, T: 'static> Context<'a, T> {
|
||||
T: 'static,
|
||||
W: 'static,
|
||||
{
|
||||
let this = self.weak_model();
|
||||
let this = self.weak_entity();
|
||||
self.app.observe_internal(entity, move |e, cx| {
|
||||
if let Some(this) = this.upgrade() {
|
||||
this.update(cx, |this, cx| on_notify(this, e, cx));
|
||||
@@ -79,7 +79,7 @@ impl<'a, T: 'static> Context<'a, T> {
|
||||
T2: 'static + EventEmitter<Evt>,
|
||||
Evt: 'static,
|
||||
{
|
||||
let this = self.weak_model();
|
||||
let this = self.weak_entity();
|
||||
self.app.subscribe_internal(entity, move |e, event, cx| {
|
||||
if let Some(this) = this.upgrade() {
|
||||
this.update(cx, |this, cx| on_event(this, e, event, cx));
|
||||
@@ -117,7 +117,7 @@ impl<'a, T: 'static> Context<'a, T> {
|
||||
T2: 'static,
|
||||
{
|
||||
let entity_id = entity.entity_id();
|
||||
let this = self.weak_model();
|
||||
let this = self.weak_entity();
|
||||
let (subscription, activate) = self.app.release_listeners.insert(
|
||||
entity_id,
|
||||
Box::new(move |entity, cx| {
|
||||
@@ -139,7 +139,7 @@ impl<'a, T: 'static> Context<'a, T> {
|
||||
where
|
||||
T: 'static,
|
||||
{
|
||||
let handle = self.weak_model();
|
||||
let handle = self.weak_entity();
|
||||
let (subscription, activate) = self.global_observers.insert(
|
||||
TypeId::of::<G>(),
|
||||
Box::new(move |cx| handle.update(cx, |view, cx| f(view, cx)).is_ok()),
|
||||
@@ -158,7 +158,7 @@ impl<'a, T: 'static> Context<'a, T> {
|
||||
Fut: 'static + Future<Output = ()>,
|
||||
T: 'static,
|
||||
{
|
||||
let handle = self.weak_model();
|
||||
let handle = self.weak_entity();
|
||||
let (subscription, activate) = self.app.quit_observers.insert(
|
||||
(),
|
||||
Box::new(move |cx| {
|
||||
@@ -189,7 +189,7 @@ impl<'a, T: 'static> Context<'a, T> {
|
||||
Fut: Future<Output = R> + 'static,
|
||||
R: 'static,
|
||||
{
|
||||
let this = self.weak_model();
|
||||
let this = self.weak_entity();
|
||||
self.app.spawn(|cx| f(this, cx))
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ impl<'a, T: 'static> Context<'a, T> {
|
||||
&self,
|
||||
f: impl Fn(&mut T, &E, &mut Window, &mut Context<T>) + 'static,
|
||||
) -> impl Fn(&E, &mut Window, &mut App) + 'static {
|
||||
let view = self.model().downgrade();
|
||||
let view = self.entity().downgrade();
|
||||
move |e: &E, window: &mut Window, cx: &mut App| {
|
||||
view.update(cx, |view, cx| f(view, e, window, cx)).ok();
|
||||
}
|
||||
@@ -221,7 +221,7 @@ impl<'a, T: 'static> Context<'a, T> {
|
||||
) where
|
||||
T: 'static,
|
||||
{
|
||||
let view = self.model();
|
||||
let view = self.entity();
|
||||
window.on_next_frame(move |window, cx| view.update(cx, |view, cx| f(view, window, cx)));
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ impl<'a, T: 'static> Context<'a, T> {
|
||||
window: &Window,
|
||||
f: impl FnOnce(&mut T, &mut Window, &mut Context<T>) + 'static,
|
||||
) {
|
||||
let view = self.model();
|
||||
let view = self.entity();
|
||||
window.defer(self, move |window, cx| {
|
||||
view.update(cx, |view, cx| f(view, window, cx))
|
||||
});
|
||||
@@ -252,7 +252,7 @@ impl<'a, T: 'static> Context<'a, T> {
|
||||
let observed_id = observed.entity_id();
|
||||
let observed = observed.downgrade();
|
||||
let window_handle = window.handle;
|
||||
let observer = self.weak_model();
|
||||
let observer = self.weak_entity();
|
||||
self.new_observer(
|
||||
observed_id,
|
||||
Box::new(move |cx| {
|
||||
@@ -290,7 +290,7 @@ impl<'a, T: 'static> Context<'a, T> {
|
||||
{
|
||||
let emitter = emitter.downgrade();
|
||||
let window_handle = window.handle;
|
||||
let subscriber = self.weak_model();
|
||||
let subscriber = self.weak_entity();
|
||||
self.new_subscription(
|
||||
emitter.entity_id(),
|
||||
(
|
||||
@@ -348,7 +348,7 @@ impl<'a, T: 'static> Context<'a, T> {
|
||||
T: 'static,
|
||||
V2: 'static,
|
||||
{
|
||||
let observer = self.weak_model();
|
||||
let observer = self.weak_entity();
|
||||
let window_handle = window.handle;
|
||||
let (subscription, activate) = self.release_listeners.insert(
|
||||
observed.entity_id(),
|
||||
@@ -371,7 +371,7 @@ impl<'a, T: 'static> Context<'a, T> {
|
||||
window: &mut Window,
|
||||
mut callback: impl FnMut(&mut T, &mut Window, &mut Context<T>) + 'static,
|
||||
) -> Subscription {
|
||||
let view = self.weak_model();
|
||||
let view = self.weak_entity();
|
||||
let (subscription, activate) = window.bounds_observers.insert(
|
||||
(),
|
||||
Box::new(move |window, cx| {
|
||||
@@ -389,7 +389,7 @@ impl<'a, T: 'static> Context<'a, T> {
|
||||
window: &mut Window,
|
||||
mut callback: impl FnMut(&mut T, &mut Window, &mut Context<T>) + 'static,
|
||||
) -> Subscription {
|
||||
let view = self.weak_model();
|
||||
let view = self.weak_entity();
|
||||
let (subscription, activate) = window.activation_observers.insert(
|
||||
(),
|
||||
Box::new(move |window, cx| {
|
||||
@@ -407,7 +407,7 @@ impl<'a, T: 'static> Context<'a, T> {
|
||||
window: &mut Window,
|
||||
mut callback: impl FnMut(&mut T, &mut Window, &mut Context<T>) + 'static,
|
||||
) -> Subscription {
|
||||
let view = self.weak_model();
|
||||
let view = self.weak_entity();
|
||||
let (subscription, activate) = window.appearance_observers.insert(
|
||||
(),
|
||||
Box::new(move |window, cx| {
|
||||
@@ -435,7 +435,7 @@ impl<'a, T: 'static> Context<'a, T> {
|
||||
subscription
|
||||
}
|
||||
|
||||
let view = self.weak_model();
|
||||
let view = self.weak_entity();
|
||||
inner(
|
||||
&mut self.keystroke_observers,
|
||||
Box::new(move |event, window, cx| {
|
||||
@@ -455,7 +455,7 @@ impl<'a, T: 'static> Context<'a, T> {
|
||||
window: &mut Window,
|
||||
mut callback: impl FnMut(&mut T, &mut Window, &mut Context<T>) + 'static,
|
||||
) -> Subscription {
|
||||
let view = self.weak_model();
|
||||
let view = self.weak_entity();
|
||||
let (subscription, activate) = window.pending_input_observers.insert(
|
||||
(),
|
||||
Box::new(move |window, cx| {
|
||||
@@ -475,7 +475,7 @@ impl<'a, T: 'static> Context<'a, T> {
|
||||
window: &mut Window,
|
||||
mut listener: impl FnMut(&mut T, &mut Window, &mut Context<T>) + 'static,
|
||||
) -> Subscription {
|
||||
let view = self.weak_model();
|
||||
let view = self.weak_entity();
|
||||
let focus_id = handle.id;
|
||||
let (subscription, activate) =
|
||||
window.new_focus_listener(Box::new(move |event, window, cx| {
|
||||
@@ -501,7 +501,7 @@ impl<'a, T: 'static> Context<'a, T> {
|
||||
window: &mut Window,
|
||||
mut listener: impl FnMut(&mut T, &mut Window, &mut Context<T>) + 'static,
|
||||
) -> Subscription {
|
||||
let view = self.weak_model();
|
||||
let view = self.weak_entity();
|
||||
let focus_id = handle.id;
|
||||
let (subscription, activate) =
|
||||
window.new_focus_listener(Box::new(move |event, window, cx| {
|
||||
@@ -524,7 +524,7 @@ impl<'a, T: 'static> Context<'a, T> {
|
||||
window: &mut Window,
|
||||
mut listener: impl FnMut(&mut T, &mut Window, &mut Context<T>) + 'static,
|
||||
) -> Subscription {
|
||||
let view = self.weak_model();
|
||||
let view = self.weak_entity();
|
||||
let focus_id = handle.id;
|
||||
let (subscription, activate) =
|
||||
window.new_focus_listener(Box::new(move |event, window, cx| {
|
||||
@@ -550,7 +550,7 @@ impl<'a, T: 'static> Context<'a, T> {
|
||||
window: &mut Window,
|
||||
mut listener: impl FnMut(&mut T, &mut Window, &mut Context<T>) + 'static,
|
||||
) -> Subscription {
|
||||
let view = self.weak_model();
|
||||
let view = self.weak_entity();
|
||||
let (subscription, activate) = window.focus_lost_listeners.insert(
|
||||
(),
|
||||
Box::new(move |window, cx| {
|
||||
@@ -570,7 +570,7 @@ impl<'a, T: 'static> Context<'a, T> {
|
||||
window: &mut Window,
|
||||
mut listener: impl FnMut(&mut T, FocusOutEvent, &mut Window, &mut Context<T>) + 'static,
|
||||
) -> Subscription {
|
||||
let view = self.weak_model();
|
||||
let view = self.weak_entity();
|
||||
let focus_id = handle.id;
|
||||
let (subscription, activate) =
|
||||
window.new_focus_listener(Box::new(move |event, window, cx| {
|
||||
@@ -606,7 +606,7 @@ impl<'a, T: 'static> Context<'a, T> {
|
||||
R: 'static,
|
||||
Fut: Future<Output = R> + 'static,
|
||||
{
|
||||
let view = self.weak_model();
|
||||
let view = self.weak_entity();
|
||||
window.spawn(self, |mut cx| f(view, cx))
|
||||
}
|
||||
|
||||
@@ -617,7 +617,7 @@ impl<'a, T: 'static> Context<'a, T> {
|
||||
mut f: impl FnMut(&mut T, &mut Window, &mut Context<'_, T>) + 'static,
|
||||
) -> Subscription {
|
||||
let window_handle = window.handle;
|
||||
let view = self.weak_model();
|
||||
let view = self.weak_entity();
|
||||
let (subscription, activate) = self.global_observers.insert(
|
||||
TypeId::of::<G>(),
|
||||
Box::new(move |cx| {
|
||||
@@ -639,7 +639,7 @@ impl<'a, T: 'static> Context<'a, T> {
|
||||
window: &mut Window,
|
||||
listener: impl Fn(&mut T, &dyn Any, DispatchPhase, &mut Window, &mut Context<T>) + 'static,
|
||||
) {
|
||||
let handle = self.weak_model();
|
||||
let handle = self.weak_entity();
|
||||
window.on_action(action_type, move |action, phase, window, cx| {
|
||||
handle
|
||||
.update(cx, |view, cx| {
|
||||
@@ -654,7 +654,7 @@ impl<'a, T: 'static> Context<'a, T> {
|
||||
where
|
||||
T: Focusable,
|
||||
{
|
||||
let view = self.model();
|
||||
let view = self.entity();
|
||||
window.defer(self, move |window, cx| {
|
||||
view.read(cx).focus_handle(cx).focus(window)
|
||||
})
|
||||
|
||||
@@ -238,7 +238,7 @@ impl TestAppContext {
|
||||
)
|
||||
.unwrap();
|
||||
drop(cx);
|
||||
let view = window.root_model(self).unwrap();
|
||||
let view = window.root(self).unwrap();
|
||||
let cx = VisualTestContext::from_window(*window.deref(), self).as_mut();
|
||||
cx.run_until_parked();
|
||||
|
||||
@@ -946,7 +946,7 @@ impl VisualContext for VisualTestContext {
|
||||
{
|
||||
self.window
|
||||
.update(&mut self.cx, |_, window, cx| {
|
||||
window.replace_root_model(cx, build_view)
|
||||
window.replace_root(cx, build_view)
|
||||
})
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
+14
-14
@@ -609,7 +609,7 @@ pub struct Window {
|
||||
rem_size_override_stack: SmallVec<[Pixels; 8]>,
|
||||
pub(crate) viewport_size: Size<Pixels>,
|
||||
layout_engine: Option<TaffyLayoutEngine>,
|
||||
pub(crate) root_model: Option<AnyView>,
|
||||
pub(crate) root: Option<AnyView>,
|
||||
pub(crate) element_id_stack: SmallVec<[ElementId; 32]>,
|
||||
pub(crate) text_style_stack: Vec<TextStyleRefinement>,
|
||||
pub(crate) element_offset_stack: Vec<Point<Pixels>>,
|
||||
@@ -887,7 +887,7 @@ impl Window {
|
||||
rem_size_override_stack: SmallVec::new(),
|
||||
viewport_size: content_size,
|
||||
layout_engine: Some(TaffyLayoutEngine::new()),
|
||||
root_model: None,
|
||||
root: None,
|
||||
element_id_stack: SmallVec::default(),
|
||||
text_style_stack: Vec::new(),
|
||||
element_offset_stack: Vec::new(),
|
||||
@@ -1019,27 +1019,27 @@ impl Window {
|
||||
subscription
|
||||
}
|
||||
|
||||
pub fn replace_root_model<V>(
|
||||
pub fn replace_root<E>(
|
||||
&mut self,
|
||||
cx: &mut App,
|
||||
build_view: impl FnOnce(&mut Window, &mut Context<'_, V>) -> V,
|
||||
) -> Entity<V>
|
||||
build_view: impl FnOnce(&mut Window, &mut Context<'_, E>) -> E,
|
||||
) -> Entity<E>
|
||||
where
|
||||
V: 'static + Render,
|
||||
E: 'static + Render,
|
||||
{
|
||||
let view = cx.new(|cx| build_view(self, cx));
|
||||
self.root_model = Some(view.clone().into());
|
||||
self.root = Some(view.clone().into());
|
||||
self.refresh();
|
||||
view
|
||||
}
|
||||
|
||||
pub fn root_model<V>(&mut self) -> Option<Option<Entity<V>>>
|
||||
pub fn root<E>(&self) -> Option<Option<Entity<E>>>
|
||||
where
|
||||
V: 'static + Render,
|
||||
E: 'static + Render,
|
||||
{
|
||||
self.root_model
|
||||
self.root
|
||||
.as_ref()
|
||||
.map(|view| view.clone().downcast::<V>().ok())
|
||||
.map(|view| view.clone().downcast::<E>().ok())
|
||||
}
|
||||
|
||||
/// Obtain a handle to the window that belongs to this context.
|
||||
@@ -1632,7 +1632,7 @@ impl Window {
|
||||
self.tooltip_bounds.take();
|
||||
|
||||
// Layout all root elements.
|
||||
let mut root_element = self.root_model.as_ref().unwrap().clone().into_any();
|
||||
let mut root_element = self.root.as_ref().unwrap().clone().into_any();
|
||||
root_element.prepaint_as_root(Point::default(), self.viewport_size.into(), self, cx);
|
||||
|
||||
let mut sorted_deferred_draws =
|
||||
@@ -3816,7 +3816,7 @@ impl<V: 'static + Render> WindowHandle<V> {
|
||||
.and_then(|window| {
|
||||
window
|
||||
.as_ref()
|
||||
.and_then(|window| window.root_model.clone())
|
||||
.and_then(|window| window.root.clone())
|
||||
.map(|root_view| root_view.downcast::<V>())
|
||||
})
|
||||
.ok_or_else(|| anyhow!("window not found"))?
|
||||
@@ -3838,7 +3838,7 @@ impl<V: 'static + Render> WindowHandle<V> {
|
||||
/// Read the root view pointer off of this window.
|
||||
///
|
||||
/// This will fail if the window is closed or if the root view's type does not match `V`.
|
||||
pub fn root_model<C>(&self, cx: &C) -> Result<Entity<V>>
|
||||
pub fn entity<C>(&self, cx: &C) -> Result<Entity<V>>
|
||||
where
|
||||
C: AppContext,
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user