Remove more references to 'model' in GPUI APIs (#23693)

Release Notes:

- N/A
This commit is contained in:
Mikayla Maki 2025-01-26 20:00:27 -08:00 committed by GitHub
parent a6b1514246
commit 9cae96f82f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
115 changed files with 309 additions and 311 deletions

View file

@ -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)
})