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

@ -473,7 +473,7 @@ impl Render for ActivityIndicator {
let Some(content) = self.content_to_render(cx) else {
return result;
};
let this = cx.model().downgrade();
let this = cx.entity().downgrade();
let truncate_content = content.message.len() > MAX_MESSAGE_LEN;
result.gap_2().child(
PopoverMenu::new("activity-indicator-popover")

View file

@ -155,7 +155,7 @@ impl AssistantPanel {
let project_paths = if let Some(tab) = dropped_item.downcast_ref::<DraggedTab>()
{
if tab.pane == cx.model() {
if tab.pane == cx.entity() {
return None;
}
let item = tab.pane.read(cx).item_for_index(tab.ix);
@ -231,7 +231,7 @@ impl AssistantPanel {
pane.active_item()
.map_or(false, |item| item.downcast::<ContextHistory>().is_some()),
);
let _pane = cx.model().clone();
let _pane = cx.entity().clone();
let right_children = h_flex()
.gap(DynamicSpacing::Base02.rems(cx))
.child(
@ -617,7 +617,7 @@ impl AssistantPanel {
InlineAssistant::update_global(cx, |assistant, cx| {
assistant.assist(
&active_editor,
Some(cx.model().downgrade()),
Some(cx.entity().downgrade()),
include_context.then_some(&assistant_panel),
initial_prompt,
window,
@ -629,7 +629,7 @@ impl AssistantPanel {
TerminalInlineAssistant::update_global(cx, |assistant, cx| {
assistant.assist(
&active_terminal,
Some(cx.model().downgrade()),
Some(cx.entity().downgrade()),
Some(&assistant_panel),
initial_prompt,
window,

View file

@ -77,7 +77,7 @@ pub fn init(
let Some(window) = window else {
return;
};
let workspace = cx.model().clone();
let workspace = cx.entity().clone();
InlineAssistant::update_global(cx, |inline_assistant, cx| {
inline_assistant.register_workspace(&workspace, window, cx)
});
@ -211,7 +211,7 @@ impl InlineAssistant {
} else {
editor.add_code_action_provider(
Rc::new(AssistantCodeActionProvider {
editor: cx.model().downgrade(),
editor: cx.entity().downgrade(),
workspace: workspace.downgrade(),
}),
window,
@ -1345,7 +1345,7 @@ impl EditorInlineAssists {
})
}),
editor.update(cx, |editor, cx| {
let editor_handle = cx.model().downgrade();
let editor_handle = cx.entity().downgrade();
editor.register_action(move |_: &editor::actions::Newline, window, cx| {
InlineAssistant::update_global(cx, |this, cx| {
if let Some(editor) = editor_handle.upgrade() {
@ -1355,7 +1355,7 @@ impl EditorInlineAssists {
})
}),
editor.update(cx, |editor, cx| {
let editor_handle = cx.model().downgrade();
let editor_handle = cx.entity().downgrade();
editor.register_action(move |_: &editor::actions::Cancel, window, cx| {
InlineAssistant::update_global(cx, |this, cx| {
if let Some(editor) = editor_handle.upgrade() {

View file

@ -242,7 +242,7 @@ impl TerminalInlineAssistant {
let (latest_output, working_directory) = assist
.terminal
.update(cx, |terminal, cx| {
let terminal = terminal.model().read(cx);
let terminal = terminal.entity().read(cx);
let latest_output = terminal.last_n_non_empty_lines(DEFAULT_CONTEXT_LINES);
let working_directory = terminal
.working_directory()

View file

@ -56,7 +56,7 @@ impl ActiveThread {
messages: Vec::new(),
rendered_messages_by_id: HashMap::default(),
list_state: ListState::new(0, ListAlignment::Bottom, px(1024.), {
let this = cx.model().downgrade();
let this = cx.entity().downgrade();
move |ix, _: &mut Window, cx: &mut App| {
this.update(cx, |this, cx| this.render_message(ix, cx))
.unwrap()

View file

@ -158,7 +158,7 @@ impl AssistantPanel {
let project = workspace.project().clone();
let language_registry = project.read(cx).languages().clone();
let workspace = workspace.weak_handle();
let weak_self = cx.model().downgrade();
let weak_self = cx.entity().downgrade();
let message_editor = cx.new(|cx| {
MessageEditor::new(
@ -811,7 +811,7 @@ impl AssistantPanel {
.child(v_flex().mx_auto().w_4_5().gap_2().children(
recent_threads.into_iter().map(|thread| {
// TODO: keyboard navigation
PastThread::new(thread, cx.model().downgrade(), false)
PastThread::new(thread, cx.entity().downgrade(), false)
}),
))
.child(

View file

@ -78,7 +78,7 @@ impl ContextPicker {
}
fn build_menu(&mut self, window: &mut Window, cx: &mut Context<Self>) -> Entity<ContextMenu> {
let context_picker = cx.model().clone();
let context_picker = cx.entity().clone();
let menu = ContextMenu::build(window, cx, move |menu, _window, cx| {
let recent = self.recent_entries(cx);
@ -144,7 +144,7 @@ impl ContextPicker {
}
fn select_kind(&mut self, kind: ContextKind, window: &mut Window, cx: &mut Context<Self>) {
let context_picker = cx.model().downgrade();
let context_picker = cx.entity().downgrade();
match kind {
ContextKind::File => {

View file

@ -393,7 +393,7 @@ impl Render for ContextStrip {
.on_action(cx.listener(Self::remove_focused_context))
.on_action(cx.listener(Self::accept_suggested_context))
.on_children_prepainted({
let model = cx.model().downgrade();
let model = cx.entity().downgrade();
move |children_bounds, _window, cx| {
model
.update(cx, |this, _| {

View file

@ -58,7 +58,7 @@ pub fn init(
let Some(window) = window else {
return;
};
let workspace = cx.model().clone();
let workspace = cx.entity().clone();
InlineAssistant::update_global(cx, |inline_assistant, cx| {
inline_assistant.register_workspace(&workspace, window, cx)
});
@ -196,7 +196,7 @@ impl InlineAssistant {
editor.add_code_action_provider(
Rc::new(AssistantCodeActionProvider {
editor: cx.model().downgrade(),
editor: cx.entity().downgrade(),
workspace: workspace.downgrade(),
thread_store,
}),
@ -249,7 +249,7 @@ impl InlineAssistant {
InlineAssistant::update_global(cx, |assistant, cx| {
assistant.assist(
&active_editor,
cx.model().downgrade(),
cx.entity().downgrade(),
thread_store,
window,
cx,
@ -260,7 +260,7 @@ impl InlineAssistant {
TerminalInlineAssistant::update_global(cx, |assistant, cx| {
assistant.assist(
&active_terminal,
cx.model().downgrade(),
cx.entity().downgrade(),
thread_store,
window,
cx,
@ -1472,7 +1472,7 @@ impl EditorInlineAssists {
})
}),
editor.update(cx, |editor, cx| {
let editor_handle = cx.model().downgrade();
let editor_handle = cx.entity().downgrade();
editor.register_action(move |_: &editor::actions::Newline, window, cx| {
InlineAssistant::update_global(cx, |this, cx| {
if let Some(editor) = editor_handle.upgrade() {
@ -1482,7 +1482,7 @@ impl EditorInlineAssists {
})
}),
editor.update(cx, |editor, cx| {
let editor_handle = cx.model().downgrade();
let editor_handle = cx.entity().downgrade();
editor.register_action(move |_: &editor::actions::Cancel, window, cx| {
InlineAssistant::update_global(cx, |this, cx| {
if let Some(editor) = editor_handle.upgrade() {

View file

@ -222,7 +222,7 @@ impl TerminalInlineAssistant {
let (latest_output, working_directory) = assist
.terminal
.update(cx, |terminal, cx| {
let terminal = terminal.model().read(cx);
let terminal = terminal.entity().read(cx);
let latest_output = terminal.last_n_non_empty_lines(DEFAULT_CONTEXT_LINES);
let working_directory = terminal
.working_directory()

View file

@ -154,7 +154,7 @@ impl Render for ThreadHistory {
} else {
history.child(
uniform_list(
cx.model().clone(),
cx.entity().clone(),
"thread-history",
threads.len(),
move |history, range, _window, _cx| {

View file

@ -213,7 +213,7 @@ impl ContextEditor {
) -> Self {
let completion_provider = SlashCommandCompletionProvider::new(
context.read(cx).slash_commands().clone(),
Some(cx.model().downgrade()),
Some(cx.entity().downgrade()),
Some(workspace.clone()),
);
@ -551,7 +551,7 @@ impl ContextEditor {
window: &mut Window,
cx: &mut Context<Self>,
) {
let context_editor = cx.model().downgrade();
let context_editor = cx.entity().downgrade();
match event {
ContextEvent::MessagesEdited => {
@ -605,7 +605,7 @@ impl ContextEditor {
.map(|tool_use| {
let placeholder = FoldPlaceholder {
render: render_fold_icon_button(
cx.model().downgrade(),
cx.entity().downgrade(),
IconName::PocketKnife,
tool_use.name.clone().into(),
),
@ -789,7 +789,7 @@ impl ContextEditor {
let placeholder = FoldPlaceholder {
render: render_fold_icon_button(
cx.model().downgrade(),
cx.entity().downgrade(),
IconName::PocketKnife,
format!("Tool Result: {tool_use_id}").into(),
),
@ -937,7 +937,7 @@ impl ContextEditor {
window: &mut Window,
cx: &mut Context<ContextEditor>,
) {
let this = cx.model().downgrade();
let this = cx.entity().downgrade();
let mut editors_to_close = Vec::new();
self.editor.update(cx, |editor, cx| {
@ -1081,7 +1081,7 @@ impl ContextEditor {
start..end,
FoldPlaceholder {
render: render_fold_icon_button(
cx.model().downgrade(),
cx.entity().downgrade(),
section.icon,
section.label.clone(),
),
@ -1843,7 +1843,7 @@ impl ContextEditor {
editor.insert("\n", window, cx);
let fold_placeholder =
quote_selection_fold_placeholder(crease_title, cx.model().downgrade());
quote_selection_fold_placeholder(crease_title, cx.entity().downgrade());
let crease = Crease::inline(
anchor_before..anchor_after,
fold_placeholder,
@ -2027,7 +2027,7 @@ impl ContextEditor {
let buffer = editor.buffer().read(cx).snapshot(cx);
let mut buffer_rows_to_fold = BTreeSet::new();
let weak_editor = cx.model().downgrade();
let weak_editor = cx.entity().downgrade();
editor.insert_creases(
metadata.creases.into_iter().map(|metadata| {
let start = buffer.anchor_after(
@ -2509,7 +2509,7 @@ impl ContextEditor {
fn render_inject_context_menu(&self, cx: &mut Context<Self>) -> impl IntoElement {
slash_command_picker::SlashCommandSelector::new(
self.slash_commands.clone(),
cx.model().downgrade(),
cx.entity().downgrade(),
Button::new("trigger", "Add Context")
.icon(IconName::Plus)
.icon_size(IconSize::Small)
@ -3699,7 +3699,7 @@ pub fn make_lsp_adapter_delegate(
Ok(Some(LocalLspAdapterDelegate::new(
project.languages().clone(),
project.environment(),
cx.weak_model(),
cx.weak_entity(),
&worktree,
http_client,
project.fs().clone(),

View file

@ -318,7 +318,7 @@ impl ContextStore {
.client
.subscribe_to_entity(remote_id)
.log_err()
.map(|subscription| subscription.set_model(&cx.model(), &mut cx.to_async()));
.map(|subscription| subscription.set_model(&cx.entity(), &mut cx.to_async()));
self.advertise_contexts(cx);
} else {
self.client_subscription = None;

View file

@ -85,7 +85,7 @@ impl SlashCommand for TerminalSlashCommand {
let lines = active_terminal
.read(cx)
.model()
.entity()
.read(cx)
.last_n_non_empty_lines(line_count);

View file

@ -152,7 +152,7 @@ impl ToolbarItemView for Breadcrumbs {
return ToolbarItemLocation::Hidden;
};
let this = cx.model().downgrade();
let this = cx.entity().downgrade();
self.subscription = Some(item.subscribe_to_item_events(
window,
cx,

View file

@ -105,8 +105,8 @@ impl ActiveCall {
incoming_call: watch::channel(),
_join_debouncer: OneAtATime { cancel: None },
_subscriptions: vec![
client.add_request_handler(cx.weak_model(), Self::handle_incoming_call),
client.add_message_handler(cx.weak_model(), Self::handle_call_canceled),
client.add_request_handler(cx.weak_entity(), Self::handle_incoming_call),
client.add_message_handler(cx.weak_entity(), Self::handle_call_canceled),
],
client,
user_store,

View file

@ -148,7 +148,7 @@ impl Room {
pending_participants: Default::default(),
pending_call_count: 0,
client_subscriptions: vec![
client.add_message_handler(cx.weak_model(), Self::handle_room_updated)
client.add_message_handler(cx.weak_entity(), Self::handle_room_updated)
],
_subscriptions: vec![
cx.on_release(Self::released),

View file

@ -98,8 +98,8 @@ impl ActiveCall {
incoming_call: watch::channel(),
_join_debouncer: OneAtATime { cancel: None },
_subscriptions: vec![
client.add_request_handler(cx.weak_model(), Self::handle_incoming_call),
client.add_message_handler(cx.weak_model(), Self::handle_call_canceled),
client.add_request_handler(cx.weak_entity(), Self::handle_incoming_call),
client.add_message_handler(cx.weak_entity(), Self::handle_call_canceled),
],
client,
user_store,

View file

@ -204,7 +204,7 @@ impl Room {
pending_participants: Default::default(),
pending_call_count: 0,
client_subscriptions: vec![
client.add_message_handler(cx.weak_model(), Self::handle_room_updated)
client.add_message_handler(cx.weak_entity(), Self::handle_room_updated)
],
_subscriptions: vec![
cx.on_release(Self::released),

View file

@ -81,7 +81,7 @@ impl ChannelBuffer {
collaborators: Default::default(),
acknowledge_task: None,
channel_id: channel.id,
subscription: Some(subscription.set_model(&cx.model(), &mut cx.to_async())),
subscription: Some(subscription.set_model(&cx.entity(), &mut cx.to_async())),
user_store,
channel_store,
};

View file

@ -132,7 +132,7 @@ impl ChannelChat {
last_acknowledged_id: None,
rng: StdRng::from_entropy(),
first_loaded_message_id: None,
_subscription: subscription.set_model(&cx.model(), &mut cx.to_async()),
_subscription: subscription.set_model(&cx.entity(), &mut cx.to_async()),
}
})?;
Self::handle_loaded_messages(

View file

@ -158,8 +158,8 @@ impl ChannelStore {
pub fn new(client: Arc<Client>, user_store: Entity<UserStore>, cx: &mut Context<Self>) -> Self {
let rpc_subscriptions = [
client.add_message_handler(cx.weak_model(), Self::handle_update_channels),
client.add_message_handler(cx.weak_model(), Self::handle_update_user_channels),
client.add_message_handler(cx.weak_entity(), Self::handle_update_channels),
client.add_message_handler(cx.weak_entity(), Self::handle_update_user_channels),
];
let mut connection_status = client.status();
@ -306,7 +306,7 @@ impl ChannelStore {
) -> Task<Result<Entity<ChannelBuffer>>> {
let client = self.client.clone();
let user_store = self.user_store.clone();
let channel_store = cx.model();
let channel_store = cx.entity();
self.open_channel_resource(
channel_id,
|this| &mut this.opened_buffers,
@ -436,7 +436,7 @@ impl ChannelStore {
) -> Task<Result<Entity<ChannelChat>>> {
let client = self.client.clone();
let user_store = self.user_store.clone();
let this = cx.model();
let this = cx.entity();
self.open_channel_resource(
channel_id,
|this| &mut this.opened_chats,

View file

@ -146,10 +146,10 @@ impl UserStore {
let (mut current_user_tx, current_user_rx) = watch::channel();
let (update_contacts_tx, mut update_contacts_rx) = mpsc::unbounded();
let rpc_subscriptions = vec![
client.add_message_handler(cx.weak_model(), Self::handle_update_plan),
client.add_message_handler(cx.weak_model(), Self::handle_update_contacts),
client.add_message_handler(cx.weak_model(), Self::handle_update_invite_info),
client.add_message_handler(cx.weak_model(), Self::handle_show_contacts),
client.add_message_handler(cx.weak_entity(), Self::handle_update_plan),
client.add_message_handler(cx.weak_entity(), Self::handle_update_contacts),
client.add_message_handler(cx.weak_entity(), Self::handle_update_invite_info),
client.add_message_handler(cx.weak_entity(), Self::handle_show_contacts),
];
Self {
users: Default::default(),
@ -262,7 +262,7 @@ impl UserStore {
Ok(())
}),
pending_contact_requests: Default::default(),
weak_self: cx.weak_model(),
weak_self: cx.weak_entity(),
}
}

View file

@ -91,7 +91,7 @@ async fn test_host_disconnect(
)
});
let cx_b = &mut VisualTestContext::from_window(*workspace_b, cx_b);
let workspace_b_view = workspace_b.root_model(cx_b).unwrap();
let workspace_b_view = workspace_b.root(cx_b).unwrap();
let editor_b = workspace_b
.update(cx_b, |workspace, window, cx| {

View file

@ -21,14 +21,14 @@ async fn test_notifications(
let notification_events_b = Arc::new(Mutex::new(Vec::new()));
client_a.notification_store().update(cx_a, |_, cx| {
let events = notification_events_a.clone();
cx.subscribe(&cx.model(), move |_, _, event, _| {
cx.subscribe(&cx.entity(), move |_, _, event, _| {
events.lock().push(event.clone());
})
.detach()
});
client_b.notification_store().update(cx_b, |_, cx| {
let events = notification_events_b.clone();
cx.subscribe(&cx.model(), move |_, _, event, _| {
cx.subscribe(&cx.entity(), move |_, _, event, _| {
events.lock().push(event.clone());
})
.detach()

View file

@ -849,7 +849,7 @@ impl TestClient {
) -> (Entity<Workspace>, &'a mut VisualTestContext) {
let window = cx.update(|cx| cx.active_window().unwrap().downcast::<Workspace>().unwrap());
let model = window.root_model(cx).unwrap();
let model = window.root(cx).unwrap();
let cx = VisualTestContext::from_window(*window.deref(), cx).as_mut();
// it might be nice to try and cleanup these at the end of each test.
(model, cx)
@ -861,7 +861,7 @@ pub fn open_channel_notes(
cx: &mut VisualTestContext,
) -> Task<anyhow::Result<Entity<ChannelView>>> {
let window = cx.update(|_, cx| cx.active_window().unwrap().downcast::<Workspace>().unwrap());
let model = window.root_model(cx).unwrap();
let model = window.root(cx).unwrap();
cx.update(|window, cx| ChannelView::open(channel_id, None, model.clone(), window, cx))
}

View file

@ -204,7 +204,7 @@ impl ChannelView {
cx: &mut Context<Self>,
) -> Self {
let buffer = channel_buffer.read(cx).buffer();
let this = cx.model().downgrade();
let this = cx.entity().downgrade();
let editor = cx.new(|cx| {
let mut editor = Editor::for_buffer(buffer, None, window, cx);
editor.set_collaboration_hub(Box::new(ChannelBufferCollaborationHub(

View file

@ -97,7 +97,7 @@ impl ChatPanel {
});
cx.new(|cx| {
let model = cx.model().downgrade();
let model = cx.entity().downgrade();
let message_list = ListState::new(
0,
gpui::ListAlignment::Bottom,
@ -680,7 +680,7 @@ impl ChatPanel {
})
})
.when_some(message_id, |el, message_id| {
let this = cx.model().clone();
let this = cx.entity().clone();
el.child(
self.render_popover_button(

View file

@ -101,7 +101,7 @@ impl MessageEditor {
window: &mut Window,
cx: &mut Context<Self>,
) -> Self {
let this = cx.model().downgrade();
let this = cx.entity().downgrade();
editor.update(cx, |editor, cx| {
editor.set_soft_wrap_mode(SoftWrap::EditorWidth, cx);
editor.set_use_autoclose(false);

View file

@ -73,7 +73,7 @@ pub fn init(cx: &mut App) {
.and_then(|room| room.read(cx).channel_id());
if let Some(channel_id) = channel_id {
let workspace = cx.model().clone();
let workspace = cx.entity().clone();
window.defer(cx, move |window, cx| {
ChannelView::open(channel_id, None, workspace, window, cx)
.detach_and_log_err(cx)
@ -239,7 +239,7 @@ impl CollabPanel {
)
.detach();
let model = cx.model().downgrade();
let model = cx.entity().downgrade();
let list_state = ListState::new(
0,
gpui::ListAlignment::Top,
@ -1040,7 +1040,7 @@ impl CollabPanel {
window: &mut Window,
cx: &mut Context<Self>,
) {
let this = cx.model().clone();
let this = cx.entity().clone();
if !(role == proto::ChannelRole::Guest
|| role == proto::ChannelRole::Talker
|| role == proto::ChannelRole::Member)
@ -1170,7 +1170,7 @@ impl CollabPanel {
.channel_for_id(clipboard.channel_id)
.map(|channel| channel.name.clone())
});
let this = cx.model().clone();
let this = cx.entity().clone();
let context_menu = ContextMenu::build(window, cx, |mut context_menu, window, cx| {
if self.has_subchannels(ix) {
@ -1337,7 +1337,7 @@ impl CollabPanel {
window: &mut Window,
cx: &mut Context<Self>,
) {
let this = cx.model().clone();
let this = cx.entity().clone();
let in_room = ActiveCall::global(cx).read(cx).room().is_some();
let context_menu = ContextMenu::build(window, cx, |mut context_menu, _, _| {

View file

@ -40,7 +40,7 @@ impl ChannelModal {
cx: &mut Context<Self>,
) -> Self {
cx.observe(&channel_store, |_, _, cx| cx.notify()).detach();
let channel_modal = cx.model().downgrade();
let channel_modal = cx.entity().downgrade();
let picker = cx.new(|cx| {
Picker::uniform_list(
ChannelModalDelegate {
@ -581,7 +581,7 @@ impl ChannelModalDelegate {
return;
};
let user_id = membership.user.id;
let picker = cx.model().clone();
let picker = cx.entity().clone();
let context_menu = ContextMenu::build(window, cx, |mut menu, _window, _cx| {
let role = membership.role;

View file

@ -16,7 +16,7 @@ pub struct ContactFinder {
impl ContactFinder {
pub fn new(user_store: Entity<UserStore>, window: &mut Window, cx: &mut Context<Self>) -> Self {
let delegate = ContactFinderDelegate {
parent: cx.model().downgrade(),
parent: cx.entity().downgrade(),
user_store,
potential_contacts: Arc::from([]),
selected_index: 0,

View file

@ -110,7 +110,7 @@ impl NotificationPanel {
})
.detach();
let model = cx.model().downgrade();
let model = cx.entity().downgrade();
let notification_list =
ListState::new(0, ListAlignment::Top, px(1000.), move |ix, window, cx| {
model
@ -323,7 +323,7 @@ impl NotificationPanel {
.justify_end()
.child(Button::new("decline", "Decline").on_click({
let notification = notification.clone();
let model = cx.model().clone();
let model = cx.entity().clone();
move |_, _, cx| {
model.update(cx, |this, cx| {
this.respond_to_notification(
@ -336,7 +336,7 @@ impl NotificationPanel {
}))
.child(Button::new("accept", "Accept").on_click({
let notification = notification.clone();
let model = cx.model().clone();
let model = cx.entity().clone();
move |_, _, cx| {
model.update(cx, |this, cx| {
this.respond_to_notification(
@ -570,7 +570,7 @@ impl NotificationPanel {
workspace.dismiss_notification(&id, cx);
workspace.show_notification(id, cx, |cx| {
let workspace = cx.model().downgrade();
let workspace = cx.entity().downgrade();
cx.new(|_| NotificationToast {
notification_id,
actor,

View file

@ -107,7 +107,7 @@ impl CommandPalette {
.collect();
let delegate =
CommandPaletteDelegate::new(cx.model().downgrade(), commands, previous_focus_handle);
CommandPaletteDelegate::new(cx.entity().downgrade(), commands, previous_focus_handle);
let picker = cx.new(|cx| {
let picker = Picker::uniform_list(delegate, window, cx);

View file

@ -283,7 +283,7 @@ impl ProjectDiagnosticsEditor {
if let Some(existing) = workspace.item_of_type::<ProjectDiagnosticsEditor>(cx) {
workspace.activate_item(&existing, true, true, window, cx);
} else {
let workspace_handle = cx.model().downgrade();
let workspace_handle = cx.entity().downgrade();
let include_warnings = match cx.try_global::<IncludeWarnings>() {
Some(include_warnings) => include_warnings.0,

View file

@ -495,7 +495,7 @@ impl CompletionsMenu {
let last_rendered_range = self.last_rendered_range.clone();
let style = style.clone();
let list = uniform_list(
cx.model().clone(),
cx.entity().clone(),
"completions",
self.entries.borrow().len(),
move |_editor, range, _window, cx| {
@ -1090,7 +1090,7 @@ impl CodeActionsMenu {
let actions = self.actions.clone();
let selected_item = self.selected_item;
let list = uniform_list(
cx.model().clone(),
cx.entity().clone(),
"code_actions_menu",
self.actions.len(),
move |_this, range, _, cx| {

View file

@ -1159,7 +1159,7 @@ impl Editor {
) -> Self {
let style = window.text_style();
let font_size = style.font_size.to_pixels(window.rem_size());
let editor = cx.model().downgrade();
let editor = cx.entity().downgrade();
let fold_placeholder = FoldPlaceholder {
constrain_width: true,
render: Arc::new(move |fold_id, fold_range, _, cx| {
@ -15339,7 +15339,7 @@ impl Render for Editor {
};
EditorElement::new(
&cx.model(),
&cx.entity(),
EditorStyle {
background,
local_player: cx.theme().players().local(),

View file

@ -62,7 +62,7 @@ fn test_edit_events(cx: &mut TestAppContext) {
let editor1 = cx.add_window({
let events = events.clone();
|window, cx| {
let model = cx.model().clone();
let model = cx.entity().clone();
cx.subscribe_in(
&model,
window,
@ -83,7 +83,7 @@ fn test_edit_events(cx: &mut TestAppContext) {
let events = events.clone();
|window, cx| {
cx.subscribe_in(
&cx.model().clone(),
&cx.entity().clone(),
window,
move |_, _, event: &EditorEvent, _, _| match event {
EditorEvent::Edited { .. } => events.borrow_mut().push(("editor2", "edited")),
@ -689,7 +689,7 @@ async fn test_navigation_history(cx: &mut TestAppContext) {
cx.new(|cx| {
let buffer = MultiBuffer::build_simple(&sample_text(300, 5, 'a'), cx);
let mut editor = build_editor(buffer.clone(), window, cx);
let handle = cx.model();
let handle = cx.entity();
editor.set_nav_history(Some(pane.read(cx).nav_history_for_item(&handle)));
fn pop_history(editor: &mut Editor, cx: &mut App) -> Option<NavigationEntry> {
@ -10180,8 +10180,8 @@ async fn test_following(cx: &mut gpui::TestAppContext) {
let is_still_following = Rc::new(RefCell::new(true));
let follower_edit_event_count = Rc::new(RefCell::new(0));
let pending_update = Rc::new(RefCell::new(None));
let leader_model = leader.root_model(cx).unwrap();
let follower_model = follower.root_model(cx).unwrap();
let leader_model = leader.root(cx).unwrap();
let follower_model = follower.root(cx).unwrap();
_ = follower.update(cx, {
let update = pending_update.clone();
let is_still_following = is_still_following.clone();
@ -10368,7 +10368,7 @@ async fn test_following_with_multiple_excerpts(cx: &mut gpui::TestAppContext) {
// Start following the editor when it has no excerpts.
let mut state_message =
leader.update_in(cx, |leader, window, cx| leader.to_state_proto(window, cx));
let workspace_model = workspace.root_model(cx).unwrap();
let workspace_model = workspace.root(cx).unwrap();
let follower_1 = cx
.update_window(*workspace.deref(), |_, window, cx| {
Editor::from_state_proto(
@ -10470,7 +10470,7 @@ async fn test_following_with_multiple_excerpts(cx: &mut gpui::TestAppContext) {
// Start following separately after it already has excerpts.
let mut state_message =
leader.update_in(cx, |leader, window, cx| leader.to_state_proto(window, cx));
let workspace_model = workspace.root_model(cx).unwrap();
let workspace_model = workspace.root(cx).unwrap();
let follower_2 = cx
.update_window(*workspace.deref(), |_, window, cx| {
Editor::from_state_proto(
@ -14497,7 +14497,7 @@ fn test_crease_insertion_and_rendering(cx: &mut TestAppContext) {
let _div = snapshot.render_crease_toggle(
MultiBufferRow(1),
false,
cx.model().clone(),
cx.entity().clone(),
window,
cx,
);
@ -14718,7 +14718,7 @@ async fn test_goto_definition_with_find_all_references_fallback(cx: &mut gpui::T
"Initially, only one, test, editor should be open in the workspace"
);
assert_eq!(
test_editor_cx.model(),
test_editor_cx.entity(),
editors.last().expect("Asserted len is 1").clone()
);
});
@ -14754,7 +14754,7 @@ async fn test_goto_definition_with_find_all_references_fallback(cx: &mut gpui::T
);
let references_fallback_text = editors
.into_iter()
.find(|new_editor| *new_editor != test_editor_cx.model())
.find(|new_editor| *new_editor != test_editor_cx.entity())
.expect("Should have one non-test editor now")
.read(test_editor_cx)
.text(test_editor_cx);

View file

@ -6246,7 +6246,7 @@ impl Element for EditorElement {
let height = self.style.text.line_height_in_pixels(rem_size);
if auto_width {
let editor_handle = cx.model().clone();
let editor_handle = cx.entity().clone();
let style = self.style.clone();
window.request_measured_layout(
Style::default(),
@ -6287,7 +6287,7 @@ impl Element for EditorElement {
}
}
EditorMode::AutoHeight { max_lines } => {
let editor_handle = cx.model().clone();
let editor_handle = cx.entity().clone();
let max_line_number_width =
self.max_line_number_width(&editor.snapshot(window, cx), window, cx);
window.request_measured_layout(

View file

@ -77,7 +77,7 @@ impl ProjectDiffEditor {
if let Some(existing) = workspace.item_of_type::<Self>(cx) {
workspace.activate_item(&existing, true, true, window, cx);
} else {
let workspace_handle = cx.model().downgrade();
let workspace_handle = cx.entity().downgrade();
let project_diff =
cx.new(|cx| Self::new(workspace.project().clone(), workspace_handle, window, cx));
workspace.add_item_to_active_pane(Box::new(project_diff), None, true, window, cx);

View file

@ -596,7 +596,7 @@ impl Editor {
style: BlockStyle::Sticky,
priority: 0,
render: Arc::new({
let editor = cx.model().clone();
let editor = cx.entity().clone();
let hunk = hunk.clone();
let has_multiple_hunks = self.has_multiple_hunks(cx);
@ -870,7 +870,7 @@ impl Editor {
let deleted_hunk_color = deleted_hunk_color(cx);
let (editor_height, editor_with_deleted_text) =
editor_with_deleted_text(diff_base_buffer, deleted_hunk_color, hunk, window, cx);
let editor = cx.model().clone();
let editor = cx.entity().clone();
let hunk = hunk.clone();
let height = editor_height.max(deleted_text_height);
BlockProperties {
@ -1214,7 +1214,7 @@ fn editor_with_deleted_text(
window: &mut Window,
cx: &mut Context<Editor>,
) -> (u32, Model<Editor>) {
let parent_editor = cx.model().downgrade();
let parent_editor = cx.entity().downgrade();
let editor = cx.new(|cx| {
let multi_buffer = cx.new(|_| MultiBuffer::without_headers(language::Capability::ReadOnly));
multi_buffer.update(cx, |multi_buffer, cx| {

View file

@ -317,7 +317,7 @@ impl ScrollManager {
self.show_scrollbar(window, cx);
self.autoscroll_request.take();
if let Some(workspace_id) = workspace_id {
let item_id = cx.model().entity_id().as_u64() as ItemId;
let item_id = cx.entity().entity_id().as_u64() as ItemId;
cx.foreground_executor()
.spawn(async move {

View file

@ -133,7 +133,7 @@ impl EditorLspTestContext {
let window = cx.add_window(|window, cx| Workspace::test_new(project.clone(), window, cx));
let workspace = window.root_model(cx).unwrap();
let workspace = window.root(cx).unwrap();
let mut cx = VisualTestContext::from_window(*window.deref(), cx);
project

View file

@ -67,7 +67,7 @@ impl EditorTestContext {
window.focus(&editor.focus_handle(cx));
editor
});
let editor_view = editor.root_model(cx).unwrap();
let editor_view = editor.root(cx).unwrap();
cx.run_until_parked();
Self {
@ -89,7 +89,7 @@ impl EditorTestContext {
}
pub async fn for_editor(editor: WindowHandle<Editor>, cx: &mut gpui::TestAppContext) -> Self {
let editor_view = editor.root_model(cx).unwrap();
let editor_view = editor.root(cx).unwrap();
Self {
cx: VisualTestContext::from_window(*editor.deref(), cx),
window: editor.into(),
@ -126,7 +126,7 @@ impl EditorTestContext {
editor
});
let editor_view = editor.root_model(cx).unwrap();
let editor_view = editor.root(cx).unwrap();
Self {
cx: VisualTestContext::from_window(*editor.deref(), cx),
window: editor.into(),

View file

@ -74,7 +74,7 @@ pub fn init(cx: &mut App) {
cx,
);
let workspace_handle = cx.model().downgrade();
let workspace_handle = cx.entity().downgrade();
window
.spawn(cx, |mut cx| async move {
let extension_path =
@ -533,7 +533,7 @@ impl ExtensionsPage {
extension: &ExtensionMetadata,
cx: &mut Context<Self>,
) -> ExtensionCard {
let this = cx.model().clone();
let this = cx.entity().clone();
let status = Self::extension_status(&extension.id, cx);
let has_dev_extension = Self::dev_extension_exists(&extension.id, cx);
@ -715,7 +715,7 @@ impl ExtensionsPage {
workspace.toggle_modal(window, cx, |window, cx| {
let delegate = ExtensionVersionSelectorDelegate::new(
fs,
cx.model().downgrade(),
cx.entity().downgrade(),
extension_versions,
);
@ -1160,7 +1160,7 @@ impl Render for ExtensionsPage {
return this.py_4().child(self.render_empty_state(cx));
}
let extensions_page = cx.model().clone();
let extensions_page = cx.entity().clone();
let scroll_handle = self.list.clone();
this.child(
uniform_list(extensions_page, "entries", count, Self::render_extensions)

View file

@ -132,7 +132,7 @@ impl ModalView for FeedbackModal {
impl FeedbackModal {
pub fn register(workspace: &mut Workspace, _: &mut Window, cx: &mut Context<Workspace>) {
let _handle = cx.model().downgrade();
let _handle = cx.entity().downgrade();
workspace.register_action(move |workspace, _: &GiveFeedback, window, cx| {
workspace
.with_local_workspace(window, cx, |workspace, window, cx| {

View file

@ -147,10 +147,10 @@ impl FileFinder {
workspace
.update_in(&mut cx, |workspace, window, cx| {
let project = workspace.project().clone();
let weak_workspace = cx.model().downgrade();
let weak_workspace = cx.entity().downgrade();
workspace.toggle_modal(window, cx, |window, cx| {
let delegate = FileFinderDelegate::new(
cx.model().downgrade(),
cx.entity().downgrade(),
weak_workspace,
project,
currently_opened_path,

View file

@ -156,7 +156,7 @@ impl GitPanel {
let git_state = project.read(cx).git_state().cloned();
let active_repository = project.read(cx).active_repository(cx);
let (err_sender, mut err_receiver) = mpsc::channel(1);
let workspace = cx.model().downgrade();
let workspace = cx.entity().downgrade();
let git_panel = cx.new(|cx| {
let focus_handle = cx.focus_handle();
@ -193,7 +193,7 @@ impl GitPanel {
current_modifiers: window.modifiers(),
width: Some(px(360.)),
scrollbar_state: ScrollbarState::new(scroll_handle.clone())
.parent_model(&cx.model()),
.parent_model(&cx.entity()),
selected_entry: None,
show_scrollbar: false,
hide_scrollbar_task: None,
@ -703,7 +703,7 @@ impl GitPanel {
}
fn schedule_update(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let handle = cx.model().downgrade();
let handle = cx.entity().downgrade();
self.update_visible_entries_task = cx.spawn_in(window, |_, mut cx| async move {
cx.background_executor().timer(UPDATE_DEBOUNCE).await;
if let Some(this) = handle.upgrade() {
@ -1114,7 +1114,7 @@ impl GitPanel {
.size_full()
.overflow_hidden()
.child(
uniform_list(cx.model().clone(), "entries", entry_count, {
uniform_list(cx.entity().clone(), "entries", entry_count, {
move |git_panel, range, _window, cx| {
let mut items = Vec::with_capacity(range.end - range.start);
git_panel.for_each_visible_entry(range, cx, |ix, details, cx| {
@ -1167,7 +1167,7 @@ impl GitPanel {
let checkbox_id =
ElementId::Name(format!("checkbox_{}", entry_details.display_name).into());
let is_tree_view = false;
let handle = cx.model().downgrade();
let handle = cx.entity().downgrade();
let end_slot = h_flex()
.invisible()

View file

@ -27,7 +27,7 @@ impl RepositorySelector {
let filtered_repositories = all_repositories.clone();
let delegate = RepositorySelectorDelegate {
project: project.downgrade(),
repository_selector: cx.model().downgrade(),
repository_selector: cx.entity().downgrade(),
repository_entries: all_repositories,
filtered_repositories,
selected_index: 0,

View file

@ -42,7 +42,7 @@ enum GoToLineRowHighlights {}
impl GoToLine {
fn register(editor: &mut Editor, _window: Option<&mut Window>, cx: &mut Context<Editor>) {
let handle = cx.model().downgrade();
let handle = cx.entity().downgrade();
editor
.register_action(move |_: &editor::actions::ToggleGoToLine, window, cx| {
let Some(editor_handle) = handle.upgrade() else {
@ -94,7 +94,7 @@ impl GoToLine {
let line_editor = cx.new(|cx| {
let mut editor = Editor::single_line(window, cx);
let editor_handle = cx.model().downgrade();
let editor_handle = cx.entity().downgrade();
editor
.register_action::<Tab>({
move |_, window, cx| {

View file

@ -572,7 +572,7 @@ impl Render for TextInput {
.p(px(4.))
.bg(white())
.child(TextElement {
input: cx.model().clone(),
input: cx.entity().clone(),
}),
)
}
@ -697,7 +697,7 @@ fn main() {
},
)
.unwrap();
let view = window.root_model(cx).unwrap();
let view = window.root(cx).unwrap();
cx.observe_keystrokes(move |ev, _, cx| {
view.update(cx, |view, cx| {
view.recent_keystrokes.push(ev.keystroke.clone());

View file

@ -9,7 +9,7 @@ impl Render for UniformListExample {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
div().size_full().bg(rgb(0xffffff)).child(
uniform_list(
cx.model().clone(),
cx.entity().clone(),
"entries",
50,
|_this, range, _window, _cx| {

View file

@ -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"))?;

View file

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

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

View file

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

View file

@ -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,
{

View file

@ -121,7 +121,7 @@ impl Render for InlineCompletionButton {
}),
);
}
let this = cx.model().clone();
let this = cx.entity().clone();
div().child(
PopoverMenu::new("copilot")
@ -173,7 +173,7 @@ impl Render for InlineCompletionButton {
let icon = status.to_icon();
let tooltip_text = status.to_tooltip();
let has_menu = status.has_menu();
let this = cx.model().clone();
let this = cx.entity().clone();
let fs = self.fs.clone();
return div().child(
@ -268,7 +268,7 @@ impl Render for InlineCompletionButton {
);
}
let this = cx.model().clone();
let this = cx.entity().clone();
let button = IconButton::new("zeta", IconName::ZedPredict).when(
!self.popover_menu_handle.is_deployed(),
|button| {
@ -399,7 +399,7 @@ impl InlineCompletionButton {
None,
move |window, cx| {
if let Some(workspace) = window.window_handle().downcast::<Workspace>() {
if let Ok(workspace) = workspace.root_model(cx) {
if let Ok(workspace) = workspace.root(cx) {
let workspace = workspace.downgrade();
window
.spawn(cx, |cx| {

View file

@ -972,7 +972,7 @@ impl Buffer {
}
pub fn branch(&mut self, cx: &mut Context<Self>) -> Entity<Self> {
let this = cx.model();
let this = cx.entity();
cx.new(|cx| {
let mut branch = Self {
branch_state: Some(BufferBranchState {

View file

@ -2805,7 +2805,7 @@ fn test_random_collaboration(cx: &mut App, mut rng: StdRng) {
);
buffer.set_group_interval(Duration::from_millis(rng.gen_range(0..=200)));
let network = network.clone();
cx.subscribe(&cx.model(), move |buffer, _, event, _| {
cx.subscribe(&cx.entity(), move |buffer, _, event, _| {
if let BufferEvent::Operation {
operation,
is_local: true,
@ -2936,7 +2936,7 @@ fn test_random_collaboration(cx: &mut App, mut rng: StdRng) {
);
new_buffer.set_group_interval(Duration::from_millis(rng.gen_range(0..=200)));
let network = network.clone();
cx.subscribe(&cx.model(), move |buffer, _, event, _| {
cx.subscribe(&cx.entity(), move |buffer, _, event, _| {
if let BufferEvent::Operation {
operation,
is_local: true,

View file

@ -33,7 +33,7 @@ impl LanguageModelSelector {
let all_models = Self::all_models(cx);
let delegate = LanguageModelPickerDelegate {
language_model_selector: cx.model().downgrade(),
language_model_selector: cx.entity().downgrade(),
on_model_changed: on_model_changed.clone(),
all_models: all_models.clone(),
filtered_models: all_models,

View file

@ -124,7 +124,7 @@ impl RefreshLlmTokenListener {
fn new(client: Arc<Client>, cx: &mut Context<Self>) -> Self {
Self {
_llm_token_subscription: client
.add_message_handler(cx.weak_model(), Self::handle_refresh_llm_token),
.add_message_handler(cx.weak_entity(), Self::handle_refresh_llm_token),
}
}

View file

@ -67,7 +67,7 @@ impl LanguageSelector {
cx: &mut Context<Self>,
) -> Self {
let delegate = LanguageSelectorDelegate::new(
cx.model().downgrade(),
cx.entity().downgrade(),
buffer,
project,
language_registry,

View file

@ -242,7 +242,7 @@ impl LogStore {
if let copilot::Event::CopilotLanguageServerStarted = inline_completion_event {
if let Some(server) = copilot.read(cx).language_server() {
let server_id = server.server_id();
let weak_this = cx.weak_model();
let weak_this = cx.weak_entity();
this.copilot_log_subscription =
Some(server.on_notification::<copilot::request::LogMessage, _>(
move |params, mut cx| {
@ -926,7 +926,7 @@ impl LspLogView {
.expect("log buffer should be a singleton")
.update(cx, |_, cx| {
cx.spawn({
let buffer = cx.model();
let buffer = cx.entity();
|_, mut cx| async move {
let language = language.await.ok();
buffer.update(&mut cx, |buffer, cx| {
@ -1222,7 +1222,7 @@ impl Render for LspLogToolbarItemView {
)
})
.collect();
let log_toolbar_view = cx.model().clone();
let log_toolbar_view = cx.entity().clone();
let lsp_menu = PopoverMenu::new("LspLogView")
.anchor(Corner::TopLeft)
.trigger(Button::new(

View file

@ -303,7 +303,7 @@ impl Render for SyntaxTreeView {
{
let layer = layer.clone();
rendered = rendered.child(uniform_list(
cx.model().clone(),
cx.entity().clone(),
"SyntaxTreeView",
layer.node().descendant_count(),
move |this, range, _, cx| {
@ -451,7 +451,7 @@ impl SyntaxTreeToolbarItemView {
let active_layer = buffer_state.active_layer.clone()?;
let active_buffer = buffer_state.buffer.read(cx).snapshot();
let view = cx.model().clone();
let view = cx.entity().clone();
Some(
PopoverMenu::new("Syntax Tree")
.trigger(Self::render_header(&active_layer))

View file

@ -219,7 +219,7 @@ impl Markdown {
impl Render for Markdown {
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
MarkdownElement::new(
cx.model().clone(),
cx.entity().clone(),
self.style.clone(),
self.language_registry.clone(),
self.fallback_code_block_language.clone(),

View file

@ -144,7 +144,7 @@ impl MarkdownPreviewView {
cx: &mut Context<Workspace>,
) -> Entity<Self> {
cx.new(|cx| {
let view = cx.model().downgrade();
let view = cx.entity().downgrade();
let list_state = ListState::new(
0,

View file

@ -103,9 +103,9 @@ impl NotificationStore {
channel_messages: Default::default(),
_watch_connection_status: watch_connection_status,
_subscriptions: vec![
client.add_message_handler(cx.weak_model(), Self::handle_new_notification),
client.add_message_handler(cx.weak_model(), Self::handle_delete_notification),
client.add_message_handler(cx.weak_model(), Self::handle_update_notification),
client.add_message_handler(cx.weak_entity(), Self::handle_new_notification),
client.add_message_handler(cx.weak_entity(), Self::handle_delete_notification),
client.add_message_handler(cx.weak_entity(), Self::handle_update_notification),
],
user_store,
client,

View file

@ -88,7 +88,7 @@ impl Render for OutlineView {
impl OutlineView {
fn register(editor: &mut Editor, _: Option<&mut Window>, cx: &mut Context<Editor>) {
if editor.mode() == EditorMode::Full {
let handle = cx.model().downgrade();
let handle = cx.entity().downgrade();
editor
.register_action(move |action, window, cx| {
if let Some(editor) = handle.upgrade() {
@ -105,7 +105,7 @@ impl OutlineView {
window: &mut Window,
cx: &mut Context<Self>,
) -> OutlineView {
let delegate = OutlineViewDelegate::new(cx.model().downgrade(), outline, editor, cx);
let delegate = OutlineViewDelegate::new(cx.entity().downgrade(), outline, editor, cx);
let picker = cx.new(|cx| {
Picker::uniform_list(delegate, window, cx).max_height(Some(vh(0.75, window)))
});

View file

@ -709,7 +709,7 @@ impl OutlinePanel {
cx: &mut Context<Workspace>,
) -> Entity<Self> {
let project = workspace.project().clone();
let workspace_handle = cx.model().downgrade();
let workspace_handle = cx.entity().downgrade();
let outline_panel = cx.new(|cx| {
let filter_editor = cx.new(|cx| {
let mut editor = Editor::single_line(window, cx);
@ -796,9 +796,9 @@ impl OutlinePanel {
show_scrollbar: !Self::should_autohide_scrollbar(cx),
hide_scrollbar_task: None,
vertical_scrollbar_state: ScrollbarState::new(scroll_handle.clone())
.parent_model(&cx.model()),
.parent_model(&cx.entity()),
horizontal_scrollbar_state: ScrollbarState::new(scroll_handle.clone())
.parent_model(&cx.model()),
.parent_model(&cx.entity()),
max_width_item_index: None,
scroll_handle,
focus_handle,
@ -4467,7 +4467,7 @@ impl OutlinePanel {
let multi_buffer_snapshot = self
.active_editor()
.map(|editor| editor.read(cx).buffer().read(cx).snapshot(cx));
uniform_list(cx.model().clone(), "entries", items_len, {
uniform_list(cx.entity().clone(), "entries", items_len, {
move |outline_panel, range, window, cx| {
let entries = outline_panel.cached_entries.get(range);
entries
@ -4534,7 +4534,7 @@ impl OutlinePanel {
.when(show_indent_guides, |list| {
list.with_decoration(
ui::indent_guides(
cx.model().clone(),
cx.entity().clone(),
px(indent_size),
IndentGuideColors::panel(cx),
|outline_panel, range, _, _| {
@ -4547,7 +4547,7 @@ impl OutlinePanel {
},
)
.with_render_fn(
cx.model().clone(),
cx.entity().clone(),
move |outline_panel, params, _, _| {
const LEFT_OFFSET: f32 = 14.;

View file

@ -281,7 +281,7 @@ impl<D: PickerDelegate> Picker<D> {
ElementContainer::UniformList(UniformListScrollHandle::new())
}
ContainerKind::List => {
let model = cx.model().downgrade();
let model = cx.entity().downgrade();
ElementContainer::List(ListState::new(
0,
gpui::ListAlignment::Top,
@ -643,7 +643,7 @@ impl<D: PickerDelegate> Picker<D> {
};
match &self.element_container {
ElementContainer::UniformList(scroll_handle) => uniform_list(
cx.model().clone(),
cx.entity().clone(),
"candidates",
self.delegate.match_count(),
move |picker, visible_range, window, cx| {

View file

@ -687,7 +687,7 @@ impl LocalBufferStore {
buffer_id,
);
events.push(BufferStoreEvent::BufferChangedFilePath {
buffer: cx.model(),
buffer: cx.entity(),
old_file: buffer.file().cloned(),
});
}
@ -875,7 +875,7 @@ impl LocalBufferStore {
if !push_to_history {
buffer.forget_transaction(transaction.id);
}
project_transaction.0.insert(cx.model(), transaction);
project_transaction.0.insert(cx.entity(), transaction);
}
})?;
}
@ -1302,7 +1302,7 @@ impl BufferStore {
unstaged_changes: None,
};
let handle = cx.model().downgrade();
let handle = cx.entity().downgrade();
buffer.update(cx, move |_, cx| {
cx.on_release(move |buffer, cx| {
handle

View file

@ -39,7 +39,7 @@ impl Manager {
project: &Entity<Project>,
cx: &mut Context<Self>,
) {
let manager = cx.weak_model();
let manager = cx.weak_entity();
project.update(cx, |_, cx| {
let manager = manager.clone();
cx.on_release(move |project, cx| {

View file

@ -122,7 +122,7 @@ impl GitState {
let mut new_repositories = Vec::new();
let mut new_active_index = None;
let this = cx.weak_model();
let this = cx.weak_entity();
worktree_store.update(cx, |worktree_store, cx| {
for worktree in worktree_store.worktrees() {

View file

@ -203,7 +203,7 @@ pub struct ImageStore {
impl ImageStore {
pub fn local(worktree_store: Entity<WorktreeStore>, cx: &mut Context<Self>) -> Self {
let this = cx.weak_model();
let this = cx.weak_entity();
Self {
state: Box::new(cx.new(|cx| {
let subscription = cx.subscribe(

View file

@ -417,7 +417,7 @@ impl LocalLspStore {
let delegate = LocalLspAdapterDelegate::new(
self.languages.clone(),
&self.environment,
cx.weak_model(),
cx.weak_entity(),
&worktree,
self.http_client.clone(),
self.fs.clone(),
@ -5153,7 +5153,7 @@ impl LspStore {
let delegate = LocalLspAdapterDelegate::new(
local.languages.clone(),
&local.environment,
cx.weak_model(),
cx.weak_entity(),
&worktree,
local.http_client.clone(),
local.fs.clone(),
@ -8159,7 +8159,7 @@ impl LanguageServerWatchedPathsBuilder {
language_server_id: LanguageServerId,
cx: &mut Context<LspStore>,
) -> LanguageServerWatchedPaths {
let project = cx.weak_model();
let project = cx.weak_entity();
const LSP_ABS_PATH_OBSERVE: Duration = Duration::from_millis(100);
let abs_paths = self

View file

@ -869,7 +869,7 @@ impl Project {
};
let ssh = ssh.read(cx);
ssh.subscribe_to_entity(SSH_PROJECT_ID, &cx.model());
ssh.subscribe_to_entity(SSH_PROJECT_ID, &cx.entity());
ssh.subscribe_to_entity(SSH_PROJECT_ID, &this.buffer_store);
ssh.subscribe_to_entity(SSH_PROJECT_ID, &this.worktree_store);
ssh.subscribe_to_entity(SSH_PROJECT_ID, &this.lsp_store);
@ -1585,7 +1585,7 @@ impl Project {
self.client_subscriptions.extend([
self.client
.subscribe_to_entity(project_id)?
.set_model(&cx.model(), &mut cx.to_async()),
.set_model(&cx.entity(), &mut cx.to_async()),
self.client
.subscribe_to_entity(project_id)?
.set_model(&self.worktree_store, &mut cx.to_async()),
@ -2427,7 +2427,7 @@ impl Project {
delay
} else {
if first_insertion {
let this = cx.weak_model();
let this = cx.weak_entity();
cx.defer(move |cx| {
if let Some(this) = this.upgrade() {
this.update(cx, |this, cx| {

View file

@ -401,9 +401,9 @@ impl ProjectPanel {
show_scrollbar: !Self::should_autohide_scrollbar(cx),
hide_scrollbar_task: None,
vertical_scrollbar_state: ScrollbarState::new(scroll_handle.clone())
.parent_model(&cx.model()),
.parent_model(&cx.entity()),
horizontal_scrollbar_state: ScrollbarState::new(scroll_handle.clone())
.parent_model(&cx.model()),
.parent_model(&cx.entity()),
max_width_item_index: None,
diagnostics: Default::default(),
scroll_handle,
@ -4227,7 +4227,7 @@ impl Render for ProjectPanel {
)
.track_focus(&self.focus_handle(cx))
.child(
uniform_list(cx.model().clone(), "entries", item_count, {
uniform_list(cx.entity().clone(), "entries", item_count, {
|this, range, window, cx| {
let mut items = Vec::with_capacity(range.end - range.start);
this.for_each_visible_entry(
@ -4244,7 +4244,7 @@ impl Render for ProjectPanel {
.when(show_indent_guides, |list| {
list.with_decoration(
ui::indent_guides(
cx.model().clone(),
cx.entity().clone(),
px(indent_size),
IndentGuideColors::panel(cx),
|this, range, window, cx| {
@ -4287,7 +4287,7 @@ impl Render for ProjectPanel {
},
))
.with_render_fn(
cx.model().clone(),
cx.entity().clone(),
move |this, params, _, cx| {
const LEFT_OFFSET: f32 = 14.;
const PADDING_Y: f32 = 4.;

View file

@ -21,7 +21,7 @@ pub fn init(cx: &mut App) {
workspace.register_action(
|workspace, _: &workspace::ToggleProjectSymbols, window, cx| {
let project = workspace.project().clone();
let handle = cx.model().downgrade();
let handle = cx.entity().downgrade();
workspace.toggle_modal(window, cx, move |window, cx| {
let delegate = ProjectSymbolsDelegate::new(handle, project);
Picker::uniform_list(delegate, window, cx).width(rems(34.))

View file

@ -64,7 +64,7 @@ impl DisconnectedOverlay {
) {
return;
}
let handle = cx.model().downgrade();
let handle = cx.entity().downgrade();
let ssh_connection_options = project.read(cx).ssh_connection_options(cx);
let host = if let Some(ssh_connection_options) = ssh_connection_options {

View file

@ -109,7 +109,7 @@ impl RecentProjects {
window: &mut Window,
cx: &mut Context<Workspace>,
) {
let weak = cx.model().downgrade();
let weak = cx.entity().downgrade();
workspace.toggle_modal(window, cx, |window, cx| {
let delegate = RecentProjectsDelegate::new(weak, create_new_window, true);

View file

@ -145,7 +145,7 @@ impl ProjectPicker {
let Ok(Some(paths)) = rx.await else {
workspace
.update_in(&mut cx, |workspace, window, cx| {
let weak = cx.model().downgrade();
let weak = cx.entity().downgrade();
workspace.toggle_modal(window, cx, |window, cx| {
RemoteServerProjects::new(window, cx, weak)
});
@ -326,14 +326,14 @@ impl RemoteServerProjects {
_: &mut Context<Workspace>,
) {
workspace.register_action(|workspace, _: &OpenRemote, window, cx| {
let handle = cx.model().downgrade();
let handle = cx.entity().downgrade();
workspace.toggle_modal(window, cx, |window, cx| Self::new(window, cx, handle))
});
}
pub fn open(workspace: Entity<Workspace>, window: &mut Window, cx: &mut App) {
workspace.update(cx, |workspace, cx| {
let handle = cx.model().downgrade();
let handle = cx.entity().downgrade();
workspace.toggle_modal(window, cx, |window, cx| Self::new(window, cx, handle))
})
}
@ -523,7 +523,7 @@ impl RemoteServerProjects {
let Some(Some(session)) = session else {
workspace
.update_in(&mut cx, |workspace, window, cx| {
let weak = cx.model().downgrade();
let weak = cx.entity().downgrade();
workspace.toggle_modal(window, cx, |window, cx| {
RemoteServerProjects::new(window, cx, weak)
});
@ -535,7 +535,7 @@ impl RemoteServerProjects {
workspace
.update_in(&mut cx, |workspace, window, cx| {
let app_state = workspace.app_state().clone();
let weak = cx.model().downgrade();
let weak = cx.entity().downgrade();
let project = project::Project::ssh(
session,
app_state.client.clone(),
@ -1152,7 +1152,7 @@ impl RemoteServerProjects {
let connection_string = connection_string.clone();
move |_, _: &menu::Confirm, window, cx| {
remove_ssh_server(
cx.model().clone(),
cx.entity().clone(),
server_index,
connection_string.clone(),
window,
@ -1172,7 +1172,7 @@ impl RemoteServerProjects {
.child(Label::new("Remove Server").color(Color::Error))
.on_click(cx.listener(move |_, _, window, cx| {
remove_ssh_server(
cx.model().clone(),
cx.entity().clone(),
server_index,
connection_string.clone(),
window,
@ -1280,7 +1280,7 @@ impl RemoteServerProjects {
state = new_state.clone();
}
}
let scroll_state = state.scrollbar.parent_model(&cx.model());
let scroll_state = state.scrollbar.parent_model(&cx.entity());
let connect_button = div()
.id("ssh-connect-new-server-container")
.track_focus(&state.add_new_server.focus_handle)

View file

@ -166,19 +166,19 @@ impl HeadlessProject {
session.subscribe_to_entity(SSH_PROJECT_ID, &worktree_store);
session.subscribe_to_entity(SSH_PROJECT_ID, &buffer_store);
session.subscribe_to_entity(SSH_PROJECT_ID, &cx.model());
session.subscribe_to_entity(SSH_PROJECT_ID, &cx.entity());
session.subscribe_to_entity(SSH_PROJECT_ID, &lsp_store);
session.subscribe_to_entity(SSH_PROJECT_ID, &task_store);
session.subscribe_to_entity(SSH_PROJECT_ID, &toolchain_store);
session.subscribe_to_entity(SSH_PROJECT_ID, &settings_observer);
client.add_request_handler(cx.weak_model(), Self::handle_list_remote_directory);
client.add_request_handler(cx.weak_model(), Self::handle_get_path_metadata);
client.add_request_handler(cx.weak_model(), Self::handle_shutdown_remote_server);
client.add_request_handler(cx.weak_model(), Self::handle_ping);
client.add_request_handler(cx.weak_entity(), Self::handle_list_remote_directory);
client.add_request_handler(cx.weak_entity(), Self::handle_get_path_metadata);
client.add_request_handler(cx.weak_entity(), Self::handle_shutdown_remote_server);
client.add_request_handler(cx.weak_entity(), Self::handle_ping);
client.add_model_request_handler(Self::handle_add_worktree);
client.add_request_handler(cx.weak_model(), Self::handle_remove_worktree);
client.add_request_handler(cx.weak_entity(), Self::handle_remove_worktree);
client.add_model_request_handler(Self::handle_open_buffer_by_path);
client.add_model_request_handler(Self::handle_open_new_buffer);

View file

@ -113,10 +113,10 @@ impl NotebookEditor {
);
}
let notebook_handle = cx.model().downgrade();
let notebook_handle = cx.entity().downgrade();
let cell_count = cell_order.len();
let this = cx.model();
let this = cx.entity();
let cell_list = ListState::new(
cell_count,
gpui::ListAlignment::Top,

View file

@ -92,7 +92,7 @@ pub fn init(cx: &mut App) {
let project_path = buffer.and_then(|buffer| buffer.read(cx).project_path(cx));
let editor_handle = cx.model().downgrade();
let editor_handle = cx.entity().downgrade();
if let Some(language) = language {
if language.name() == "Python".into() {

View file

@ -245,7 +245,7 @@ impl Session {
repl_session_id = cx.entity_id().to_string(),
);
let session_view = cx.model().clone();
let session_view = cx.entity().clone();
let kernel = match self.kernel_specification.clone() {
KernelSpecification::Jupyter(kernel_specification)
@ -417,7 +417,7 @@ impl Session {
};
let parent_message_id = message.header.msg_id.clone();
let session_view = cx.model().downgrade();
let session_view = cx.entity().downgrade();
let weak_editor = self.editor.clone();
let on_close: CloseBlockFn = Arc::new(

View file

@ -516,7 +516,7 @@ impl ToolbarItemView for BufferSearchBar {
if let Some(searchable_item_handle) =
item.and_then(|item| item.to_searchable_item_handle(cx))
{
let this = cx.model().downgrade();
let this = cx.entity().downgrade();
self.active_searchable_item_subscription =
Some(searchable_item_handle.subscribe_to_search_events(

View file

@ -820,7 +820,7 @@ impl ProjectSearchView {
return;
};
let weak_workspace = cx.model().downgrade();
let weak_workspace = cx.entity().downgrade();
let model = cx.new(|cx| ProjectSearch::new(workspace.project().clone(), cx));
let search = cx.new(|cx| ProjectSearchView::new(weak_workspace, model, window, cx, None));
@ -879,7 +879,7 @@ impl ProjectSearchView {
model.search(new_query, cx);
model
});
let weak_workspace = cx.model().downgrade();
let weak_workspace = cx.entity().downgrade();
workspace.add_item_to_active_pane(
Box::new(
cx.new(|cx| {
@ -937,7 +937,7 @@ impl ProjectSearchView {
let settings = settings.cloned();
let weak_workspace = cx.model().downgrade();
let weak_workspace = cx.entity().downgrade();
let project_search = cx.new(|cx| ProjectSearch::new(workspace.project().clone(), cx));
let project_search_view = cx.new(|cx| {

View file

@ -115,7 +115,7 @@ impl ProjectIndexDebugView {
.collect::<Vec<_>>();
this.update(&mut cx, |this, cx| {
let view = cx.model().downgrade();
let view = cx.entity().downgrade();
this.selected_path = Some(PathState {
path: file_path,
list_state: ListState::new(
@ -224,7 +224,7 @@ impl Render for ProjectIndexDebugView {
.into_any_element()
} else {
let mut list = uniform_list(
cx.model().clone(),
cx.entity().clone(),
"ProjectIndexDebugView",
self.rows.len(),
move |this, range, _, cx| {

View file

@ -58,7 +58,7 @@ impl ScopeSelector {
cx: &mut Context<Self>,
) -> Self {
let delegate =
ScopeSelectorDelegate::new(workspace, cx.model().downgrade(), language_registry);
ScopeSelectorDelegate::new(workspace, cx.entity().downgrade(), language_registry);
let picker = cx.new(|cx| Picker::uniform_list(delegate, window, cx));

View file

@ -39,7 +39,7 @@ impl Render for IndentGuidesStory {
.child(
v_flex().size_full().child(
uniform_list(
cx.model().clone(),
cx.entity().clone(),
"some-list",
self.depths.len(),
|this, range, cx| {
@ -60,7 +60,7 @@ impl Render for IndentGuidesStory {
)
.with_sizing_behavior(gpui::ListSizingBehavior::Infer)
.with_decoration(ui::indent_guides(
cx.model().clone(),
cx.entity().clone(),
px(16.),
ui::IndentGuideColors {
default: Color::Info.color(cx),

View file

@ -94,7 +94,7 @@ impl TabSwitcher {
let delegate = TabSwitcherDelegate::new(
project,
action,
cx.model().downgrade(),
cx.entity().downgrade(),
weak_pane,
window,
cx,

View file

@ -903,7 +903,7 @@ pub fn new_terminal_pane(
cx: &mut Context<TerminalPanel>,
) -> Entity<Pane> {
let is_local = project.read(cx).is_local();
let terminal_panel = cx.model().clone();
let terminal_panel = cx.entity().clone();
let pane = cx.new(|cx| {
let mut pane = Pane::new(
workspace.clone(),
@ -923,7 +923,7 @@ pub fn new_terminal_pane(
let split_closure_terminal_panel = terminal_panel.downgrade();
pane.set_can_split(Some(Arc::new(move |pane, dragged_item, _window, cx| {
if let Some(tab) = dragged_item.downcast_ref::<DraggedTab>() {
let is_current_pane = tab.pane == cx.model();
let is_current_pane = tab.pane == cx.entity();
let Some(can_drag_away) = split_closure_terminal_panel
.update(cx, |terminal_panel, _| {
let current_panes = terminal_panel.center.panes();
@ -963,7 +963,7 @@ pub fn new_terminal_pane(
return ControlFlow::Break(());
};
if let Some(tab) = dropped_item.downcast_ref::<DraggedTab>() {
let this_pane = cx.model().clone();
let this_pane = cx.entity().clone();
let item = if tab.pane == this_pane {
pane.item_for_index(tab.ix)
} else {

View file

@ -218,7 +218,7 @@ impl TerminalView {
}
}
pub fn model(&self) -> &Entity<Terminal> {
pub fn entity(&self) -> &Entity<Terminal> {
&self.terminal
}
@ -1125,7 +1125,7 @@ impl TerminalView {
impl Render for TerminalView {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let terminal_handle = self.terminal.clone();
let terminal_view_handle = cx.model().clone();
let terminal_view_handle = cx.entity().clone();
let focused = self.focus_handle.is_focused(window);
@ -1771,7 +1771,7 @@ mod tests {
let project = Project::test(params.fs.clone(), [], cx).await;
let workspace = cx
.add_window(|window, cx| Workspace::test_new(project.clone(), window, cx))
.root_model(cx)
.root(cx)
.unwrap();
(project, workspace)

View file

@ -33,7 +33,7 @@ pub fn toggle(
let fs = workspace.app_state().fs.clone();
workspace.toggle_modal(window, cx, |window, cx| {
let delegate = ThemeSelectorDelegate::new(
cx.model().downgrade(),
cx.entity().downgrade(),
fs,
toggle.themes_filter.as_ref(),
cx,

View file

@ -96,7 +96,7 @@ impl ToolchainSelector {
window: &mut Window,
cx: &mut Context<Self>,
) -> Self {
let toolchain_selector = cx.model().downgrade();
let toolchain_selector = cx.entity().downgrade();
let picker = cx.new(|cx| {
let delegate = ToolchainSelectorDelegate::new(
active_toolchain,

View file

@ -539,7 +539,7 @@ impl Render for ContextMenu {
disabled,
}) => {
let handler = handler.clone();
let menu = cx.model().downgrade();
let menu = cx.entity().downgrade();
let icon_color = if *disabled {
Color::Muted
} else {
@ -637,7 +637,7 @@ impl Render for ContextMenu {
selectable,
} => {
let handler = handler.clone();
let menu = cx.model().downgrade();
let menu = cx.entity().downgrade();
let selectable = *selectable;
ListItem::new(ix)
.inset(true)

View file

@ -35,7 +35,7 @@ impl BranchList {
window: &mut Window,
cx: &mut Context<Workspace>,
) {
let this = cx.model().clone();
let this = cx.entity().clone();
cx.spawn_in(window, |_, mut cx| async move {
// Modal branch picker has a longer trailoff than a popover one.
let delegate = BranchListDelegate::new(this.clone(), 70, &cx).await?;

View file

@ -20,7 +20,7 @@ impl ModeIndicator {
})
.detach();
let handle = cx.model().clone();
let handle = cx.entity().clone();
let window_handle = window.window_handle();
cx.observe_new::<Vim>(move |_, window, cx| {
let Some(window) = window else {
@ -29,7 +29,7 @@ impl ModeIndicator {
if window.window_handle() != window_handle {
return;
}
let vim = cx.model().clone();
let vim = cx.entity().clone();
handle.update(cx, |_, cx| {
cx.subscribe(&vim, |mode_indicator, vim, event, cx| match event {
VimEvent::Focused => {

View file

@ -130,7 +130,7 @@ impl Replayer {
text,
utf16_range_to_replace,
} => {
let Some(Some(workspace)) = window.root_model::<Workspace>() else {
let Some(Some(workspace)) = window.root::<Workspace>() else {
return;
};
let Some(editor) = workspace

Some files were not shown because too many files have changed in this diff Show more