Rename model
based variable names to entity
(#24198)
## Context While looking through the client crate, I noticed that some of the old functions and variables were still using gpui::model name that was deprecated during the gpui3 transition. This PR renames those instances of model to entity to be more inline with gpui3. In addition, I also renamed `model` to `entity` in cases found by the below search terms given by @someone13574 - model = cx. - model: Entity - model: &Entity - OpenedModelHandle - model.update - model.upgrade - model = .*\.root (regex) - parent_model - model = cx.new - cx.spawn(move |model Release Notes: - N/A
This commit is contained in:
parent
27d1c689cf
commit
8c7096f7a6
40 changed files with 332 additions and 327 deletions
|
@ -442,7 +442,7 @@ impl AssistantPanel {
|
||||||
|
|
||||||
fn handle_assistant_configuration_event(
|
fn handle_assistant_configuration_event(
|
||||||
&mut self,
|
&mut self,
|
||||||
_model: &Entity<AssistantConfiguration>,
|
_entity: &Entity<AssistantConfiguration>,
|
||||||
event: &AssistantConfigurationEvent,
|
event: &AssistantConfigurationEvent,
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
|
|
|
@ -79,8 +79,8 @@ impl ContextStore {
|
||||||
project.open_buffer(project_path.clone(), cx)
|
project.open_buffer(project_path.clone(), cx)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let buffer_model = open_buffer_task.await?;
|
let buffer_entity = open_buffer_task.await?;
|
||||||
let buffer_id = this.update(&mut cx, |_, cx| buffer_model.read(cx).remote_id())?;
|
let buffer_id = this.update(&mut cx, |_, cx| buffer_entity.read(cx).remote_id())?;
|
||||||
|
|
||||||
let already_included = this.update(&mut cx, |this, _cx| {
|
let already_included = this.update(&mut cx, |this, _cx| {
|
||||||
match this.will_include_buffer(buffer_id, &project_path.path) {
|
match this.will_include_buffer(buffer_id, &project_path.path) {
|
||||||
|
@ -98,10 +98,10 @@ impl ContextStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
let (buffer_info, text_task) = this.update(&mut cx, |_, cx| {
|
let (buffer_info, text_task) = this.update(&mut cx, |_, cx| {
|
||||||
let buffer = buffer_model.read(cx);
|
let buffer = buffer_entity.read(cx);
|
||||||
collect_buffer_info_and_text(
|
collect_buffer_info_and_text(
|
||||||
project_path.path.clone(),
|
project_path.path.clone(),
|
||||||
buffer_model,
|
buffer_entity,
|
||||||
buffer,
|
buffer,
|
||||||
cx.to_async(),
|
cx.to_async(),
|
||||||
)
|
)
|
||||||
|
@ -119,18 +119,18 @@ impl ContextStore {
|
||||||
|
|
||||||
pub fn add_file_from_buffer(
|
pub fn add_file_from_buffer(
|
||||||
&mut self,
|
&mut self,
|
||||||
buffer_model: Entity<Buffer>,
|
buffer_entity: Entity<Buffer>,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) -> Task<Result<()>> {
|
) -> Task<Result<()>> {
|
||||||
cx.spawn(|this, mut cx| async move {
|
cx.spawn(|this, mut cx| async move {
|
||||||
let (buffer_info, text_task) = this.update(&mut cx, |_, cx| {
|
let (buffer_info, text_task) = this.update(&mut cx, |_, cx| {
|
||||||
let buffer = buffer_model.read(cx);
|
let buffer = buffer_entity.read(cx);
|
||||||
let Some(file) = buffer.file() else {
|
let Some(file) = buffer.file() else {
|
||||||
return Err(anyhow!("Buffer has no path."));
|
return Err(anyhow!("Buffer has no path."));
|
||||||
};
|
};
|
||||||
Ok(collect_buffer_info_and_text(
|
Ok(collect_buffer_info_and_text(
|
||||||
file.path().clone(),
|
file.path().clone(),
|
||||||
buffer_model,
|
buffer_entity,
|
||||||
buffer,
|
buffer,
|
||||||
cx.to_async(),
|
cx.to_async(),
|
||||||
))
|
))
|
||||||
|
@ -207,11 +207,11 @@ impl ContextStore {
|
||||||
let mut buffer_infos = Vec::new();
|
let mut buffer_infos = Vec::new();
|
||||||
let mut text_tasks = Vec::new();
|
let mut text_tasks = Vec::new();
|
||||||
this.update(&mut cx, |_, cx| {
|
this.update(&mut cx, |_, cx| {
|
||||||
for (path, buffer_model) in files.into_iter().zip(buffers) {
|
for (path, buffer_entity) in files.into_iter().zip(buffers) {
|
||||||
let buffer_model = buffer_model?;
|
let buffer_entity = buffer_entity?;
|
||||||
let buffer = buffer_model.read(cx);
|
let buffer = buffer_entity.read(cx);
|
||||||
let (buffer_info, text_task) =
|
let (buffer_info, text_task) =
|
||||||
collect_buffer_info_and_text(path, buffer_model, buffer, cx.to_async());
|
collect_buffer_info_and_text(path, buffer_entity, buffer, cx.to_async());
|
||||||
buffer_infos.push(buffer_info);
|
buffer_infos.push(buffer_info);
|
||||||
text_tasks.push(text_task);
|
text_tasks.push(text_task);
|
||||||
}
|
}
|
||||||
|
@ -429,7 +429,7 @@ pub enum FileInclusion {
|
||||||
|
|
||||||
// ContextBuffer without text.
|
// ContextBuffer without text.
|
||||||
struct BufferInfo {
|
struct BufferInfo {
|
||||||
buffer_model: Entity<Buffer>,
|
buffer_entity: Entity<Buffer>,
|
||||||
id: BufferId,
|
id: BufferId,
|
||||||
version: clock::Global,
|
version: clock::Global,
|
||||||
}
|
}
|
||||||
|
@ -437,7 +437,7 @@ struct BufferInfo {
|
||||||
fn make_context_buffer(info: BufferInfo, text: SharedString) -> ContextBuffer {
|
fn make_context_buffer(info: BufferInfo, text: SharedString) -> ContextBuffer {
|
||||||
ContextBuffer {
|
ContextBuffer {
|
||||||
id: info.id,
|
id: info.id,
|
||||||
buffer: info.buffer_model,
|
buffer: info.buffer_entity,
|
||||||
version: info.version,
|
version: info.version,
|
||||||
text,
|
text,
|
||||||
}
|
}
|
||||||
|
@ -445,13 +445,13 @@ fn make_context_buffer(info: BufferInfo, text: SharedString) -> ContextBuffer {
|
||||||
|
|
||||||
fn collect_buffer_info_and_text(
|
fn collect_buffer_info_and_text(
|
||||||
path: Arc<Path>,
|
path: Arc<Path>,
|
||||||
buffer_model: Entity<Buffer>,
|
buffer_entity: Entity<Buffer>,
|
||||||
buffer: &Buffer,
|
buffer: &Buffer,
|
||||||
cx: AsyncApp,
|
cx: AsyncApp,
|
||||||
) -> (BufferInfo, Task<SharedString>) {
|
) -> (BufferInfo, Task<SharedString>) {
|
||||||
let buffer_info = BufferInfo {
|
let buffer_info = BufferInfo {
|
||||||
id: buffer.remote_id(),
|
id: buffer.remote_id(),
|
||||||
buffer_model,
|
buffer_entity,
|
||||||
version: buffer.version(),
|
version: buffer.version(),
|
||||||
};
|
};
|
||||||
// Important to collect version at the same time as content so that staleness logic is correct.
|
// Important to collect version at the same time as content so that staleness logic is correct.
|
||||||
|
|
|
@ -92,8 +92,8 @@ impl ContextStrip {
|
||||||
let active_item = workspace.read(cx).active_item(cx)?;
|
let active_item = workspace.read(cx).active_item(cx)?;
|
||||||
|
|
||||||
let editor = active_item.to_any().downcast::<Editor>().ok()?.read(cx);
|
let editor = active_item.to_any().downcast::<Editor>().ok()?.read(cx);
|
||||||
let active_buffer_model = editor.buffer().read(cx).as_singleton()?;
|
let active_buffer_entity = editor.buffer().read(cx).as_singleton()?;
|
||||||
let active_buffer = active_buffer_model.read(cx);
|
let active_buffer = active_buffer_entity.read(cx);
|
||||||
|
|
||||||
let path = active_buffer.file()?.path();
|
let path = active_buffer.file()?.path();
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ impl ContextStrip {
|
||||||
|
|
||||||
Some(SuggestedContext::File {
|
Some(SuggestedContext::File {
|
||||||
name,
|
name,
|
||||||
buffer: active_buffer_model.downgrade(),
|
buffer: active_buffer_entity.downgrade(),
|
||||||
icon_path,
|
icon_path,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -393,9 +393,9 @@ impl Render for ContextStrip {
|
||||||
.on_action(cx.listener(Self::remove_focused_context))
|
.on_action(cx.listener(Self::remove_focused_context))
|
||||||
.on_action(cx.listener(Self::accept_suggested_context))
|
.on_action(cx.listener(Self::accept_suggested_context))
|
||||||
.on_children_prepainted({
|
.on_children_prepainted({
|
||||||
let model = cx.entity().downgrade();
|
let entity = cx.entity().downgrade();
|
||||||
move |children_bounds, _window, cx| {
|
move |children_bounds, _window, cx| {
|
||||||
model
|
entity
|
||||||
.update(cx, |this, _| {
|
.update(cx, |this, _| {
|
||||||
this.children_bounds = Some(children_bounds);
|
this.children_bounds = Some(children_bounds);
|
||||||
})
|
})
|
||||||
|
|
|
@ -31,11 +31,11 @@ use std::{
|
||||||
use util::{ResultExt, TryFutureExt};
|
use util::{ResultExt, TryFutureExt};
|
||||||
|
|
||||||
pub(crate) fn init(client: &AnyProtoClient) {
|
pub(crate) fn init(client: &AnyProtoClient) {
|
||||||
client.add_model_message_handler(ContextStore::handle_advertise_contexts);
|
client.add_entity_message_handler(ContextStore::handle_advertise_contexts);
|
||||||
client.add_model_request_handler(ContextStore::handle_open_context);
|
client.add_entity_request_handler(ContextStore::handle_open_context);
|
||||||
client.add_model_request_handler(ContextStore::handle_create_context);
|
client.add_entity_request_handler(ContextStore::handle_create_context);
|
||||||
client.add_model_message_handler(ContextStore::handle_update_context);
|
client.add_entity_message_handler(ContextStore::handle_update_context);
|
||||||
client.add_model_request_handler(ContextStore::handle_synchronize_contexts);
|
client.add_entity_request_handler(ContextStore::handle_synchronize_contexts);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -310,7 +310,7 @@ impl ContextStore {
|
||||||
.client
|
.client
|
||||||
.subscribe_to_entity(remote_id)
|
.subscribe_to_entity(remote_id)
|
||||||
.log_err()
|
.log_err()
|
||||||
.map(|subscription| subscription.set_model(&cx.entity(), &mut cx.to_async()));
|
.map(|subscription| subscription.set_entity(&cx.entity(), &mut cx.to_async()));
|
||||||
self.advertise_contexts(cx);
|
self.advertise_contexts(cx);
|
||||||
} else {
|
} else {
|
||||||
self.client_subscription = None;
|
self.client_subscription = None;
|
||||||
|
|
|
@ -15,8 +15,8 @@ use util::ResultExt;
|
||||||
pub const ACKNOWLEDGE_DEBOUNCE_INTERVAL: Duration = Duration::from_millis(250);
|
pub const ACKNOWLEDGE_DEBOUNCE_INTERVAL: Duration = Duration::from_millis(250);
|
||||||
|
|
||||||
pub(crate) fn init(client: &AnyProtoClient) {
|
pub(crate) fn init(client: &AnyProtoClient) {
|
||||||
client.add_model_message_handler(ChannelBuffer::handle_update_channel_buffer);
|
client.add_entity_message_handler(ChannelBuffer::handle_update_channel_buffer);
|
||||||
client.add_model_message_handler(ChannelBuffer::handle_update_channel_buffer_collaborators);
|
client.add_entity_message_handler(ChannelBuffer::handle_update_channel_buffer_collaborators);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ChannelBuffer {
|
pub struct ChannelBuffer {
|
||||||
|
@ -81,7 +81,7 @@ impl ChannelBuffer {
|
||||||
collaborators: Default::default(),
|
collaborators: Default::default(),
|
||||||
acknowledge_task: None,
|
acknowledge_task: None,
|
||||||
channel_id: channel.id,
|
channel_id: channel.id,
|
||||||
subscription: Some(subscription.set_model(&cx.entity(), &mut cx.to_async())),
|
subscription: Some(subscription.set_entity(&cx.entity(), &mut cx.to_async())),
|
||||||
user_store,
|
user_store,
|
||||||
channel_store,
|
channel_store,
|
||||||
};
|
};
|
||||||
|
|
|
@ -95,9 +95,9 @@ pub enum ChannelChatEvent {
|
||||||
|
|
||||||
impl EventEmitter<ChannelChatEvent> for ChannelChat {}
|
impl EventEmitter<ChannelChatEvent> for ChannelChat {}
|
||||||
pub fn init(client: &AnyProtoClient) {
|
pub fn init(client: &AnyProtoClient) {
|
||||||
client.add_model_message_handler(ChannelChat::handle_message_sent);
|
client.add_entity_message_handler(ChannelChat::handle_message_sent);
|
||||||
client.add_model_message_handler(ChannelChat::handle_message_removed);
|
client.add_entity_message_handler(ChannelChat::handle_message_removed);
|
||||||
client.add_model_message_handler(ChannelChat::handle_message_updated);
|
client.add_entity_message_handler(ChannelChat::handle_message_updated);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ChannelChat {
|
impl ChannelChat {
|
||||||
|
@ -132,7 +132,7 @@ impl ChannelChat {
|
||||||
last_acknowledged_id: None,
|
last_acknowledged_id: None,
|
||||||
rng: StdRng::from_entropy(),
|
rng: StdRng::from_entropy(),
|
||||||
first_loaded_message_id: None,
|
first_loaded_message_id: None,
|
||||||
_subscription: subscription.set_model(&cx.entity(), &mut cx.to_async()),
|
_subscription: subscription.set_entity(&cx.entity(), &mut cx.to_async()),
|
||||||
}
|
}
|
||||||
})?;
|
})?;
|
||||||
Self::handle_loaded_messages(
|
Self::handle_loaded_messages(
|
||||||
|
|
|
@ -39,8 +39,8 @@ pub struct ChannelStore {
|
||||||
channel_states: HashMap<ChannelId, ChannelState>,
|
channel_states: HashMap<ChannelId, ChannelState>,
|
||||||
outgoing_invites: HashSet<(ChannelId, UserId)>,
|
outgoing_invites: HashSet<(ChannelId, UserId)>,
|
||||||
update_channels_tx: mpsc::UnboundedSender<proto::UpdateChannels>,
|
update_channels_tx: mpsc::UnboundedSender<proto::UpdateChannels>,
|
||||||
opened_buffers: HashMap<ChannelId, OpenedModelHandle<ChannelBuffer>>,
|
opened_buffers: HashMap<ChannelId, OpenEntityHandle<ChannelBuffer>>,
|
||||||
opened_chats: HashMap<ChannelId, OpenedModelHandle<ChannelChat>>,
|
opened_chats: HashMap<ChannelId, OpenEntityHandle<ChannelChat>>,
|
||||||
client: Arc<Client>,
|
client: Arc<Client>,
|
||||||
did_subscribe: bool,
|
did_subscribe: bool,
|
||||||
user_store: Entity<UserStore>,
|
user_store: Entity<UserStore>,
|
||||||
|
@ -142,7 +142,7 @@ pub enum ChannelEvent {
|
||||||
|
|
||||||
impl EventEmitter<ChannelEvent> for ChannelStore {}
|
impl EventEmitter<ChannelEvent> for ChannelStore {}
|
||||||
|
|
||||||
enum OpenedModelHandle<E> {
|
enum OpenEntityHandle<E> {
|
||||||
Open(WeakEntity<E>),
|
Open(WeakEntity<E>),
|
||||||
Loading(Shared<Task<Result<Entity<E>, Arc<anyhow::Error>>>>),
|
Loading(Shared<Task<Result<Entity<E>, Arc<anyhow::Error>>>>),
|
||||||
}
|
}
|
||||||
|
@ -292,7 +292,7 @@ impl ChannelStore {
|
||||||
|
|
||||||
pub fn has_open_channel_buffer(&self, channel_id: ChannelId, _cx: &App) -> bool {
|
pub fn has_open_channel_buffer(&self, channel_id: ChannelId, _cx: &App) -> bool {
|
||||||
if let Some(buffer) = self.opened_buffers.get(&channel_id) {
|
if let Some(buffer) = self.opened_buffers.get(&channel_id) {
|
||||||
if let OpenedModelHandle::Open(buffer) = buffer {
|
if let OpenEntityHandle::Open(buffer) = buffer {
|
||||||
return buffer.upgrade().is_some();
|
return buffer.upgrade().is_some();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -453,7 +453,7 @@ impl ChannelStore {
|
||||||
fn open_channel_resource<T, F, Fut>(
|
fn open_channel_resource<T, F, Fut>(
|
||||||
&mut self,
|
&mut self,
|
||||||
channel_id: ChannelId,
|
channel_id: ChannelId,
|
||||||
get_map: fn(&mut Self) -> &mut HashMap<ChannelId, OpenedModelHandle<T>>,
|
get_map: fn(&mut Self) -> &mut HashMap<ChannelId, OpenEntityHandle<T>>,
|
||||||
load: F,
|
load: F,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) -> Task<Result<Entity<T>>>
|
) -> Task<Result<Entity<T>>>
|
||||||
|
@ -465,15 +465,15 @@ impl ChannelStore {
|
||||||
let task = loop {
|
let task = loop {
|
||||||
match get_map(self).entry(channel_id) {
|
match get_map(self).entry(channel_id) {
|
||||||
hash_map::Entry::Occupied(e) => match e.get() {
|
hash_map::Entry::Occupied(e) => match e.get() {
|
||||||
OpenedModelHandle::Open(model) => {
|
OpenEntityHandle::Open(entity) => {
|
||||||
if let Some(model) = model.upgrade() {
|
if let Some(entity) = entity.upgrade() {
|
||||||
break Task::ready(Ok(model)).shared();
|
break Task::ready(Ok(entity)).shared();
|
||||||
} else {
|
} else {
|
||||||
get_map(self).remove(&channel_id);
|
get_map(self).remove(&channel_id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OpenedModelHandle::Loading(task) => {
|
OpenEntityHandle::Loading(task) => {
|
||||||
break task.clone();
|
break task.clone();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -490,7 +490,7 @@ impl ChannelStore {
|
||||||
})
|
})
|
||||||
.shared();
|
.shared();
|
||||||
|
|
||||||
e.insert(OpenedModelHandle::Loading(task.clone()));
|
e.insert(OpenEntityHandle::Loading(task.clone()));
|
||||||
cx.spawn({
|
cx.spawn({
|
||||||
let task = task.clone();
|
let task = task.clone();
|
||||||
move |this, mut cx| async move {
|
move |this, mut cx| async move {
|
||||||
|
@ -499,7 +499,7 @@ impl ChannelStore {
|
||||||
Ok(model) => {
|
Ok(model) => {
|
||||||
get_map(this).insert(
|
get_map(this).insert(
|
||||||
channel_id,
|
channel_id,
|
||||||
OpenedModelHandle::Open(model.downgrade()),
|
OpenEntityHandle::Open(model.downgrade()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
|
@ -900,7 +900,7 @@ impl ChannelStore {
|
||||||
self.disconnect_channel_buffers_task.take();
|
self.disconnect_channel_buffers_task.take();
|
||||||
|
|
||||||
for chat in self.opened_chats.values() {
|
for chat in self.opened_chats.values() {
|
||||||
if let OpenedModelHandle::Open(chat) = chat {
|
if let OpenEntityHandle::Open(chat) = chat {
|
||||||
if let Some(chat) = chat.upgrade() {
|
if let Some(chat) = chat.upgrade() {
|
||||||
chat.update(cx, |chat, cx| {
|
chat.update(cx, |chat, cx| {
|
||||||
chat.rejoin(cx);
|
chat.rejoin(cx);
|
||||||
|
@ -911,7 +911,7 @@ impl ChannelStore {
|
||||||
|
|
||||||
let mut buffer_versions = Vec::new();
|
let mut buffer_versions = Vec::new();
|
||||||
for buffer in self.opened_buffers.values() {
|
for buffer in self.opened_buffers.values() {
|
||||||
if let OpenedModelHandle::Open(buffer) = buffer {
|
if let OpenEntityHandle::Open(buffer) = buffer {
|
||||||
if let Some(buffer) = buffer.upgrade() {
|
if let Some(buffer) = buffer.upgrade() {
|
||||||
let channel_buffer = buffer.read(cx);
|
let channel_buffer = buffer.read(cx);
|
||||||
let buffer = channel_buffer.buffer().read(cx);
|
let buffer = channel_buffer.buffer().read(cx);
|
||||||
|
@ -937,7 +937,7 @@ impl ChannelStore {
|
||||||
|
|
||||||
this.update(&mut cx, |this, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
this.opened_buffers.retain(|_, buffer| match buffer {
|
this.opened_buffers.retain(|_, buffer| match buffer {
|
||||||
OpenedModelHandle::Open(channel_buffer) => {
|
OpenEntityHandle::Open(channel_buffer) => {
|
||||||
let Some(channel_buffer) = channel_buffer.upgrade() else {
|
let Some(channel_buffer) = channel_buffer.upgrade() else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
@ -998,7 +998,7 @@ impl ChannelStore {
|
||||||
false
|
false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
OpenedModelHandle::Loading(_) => true,
|
OpenEntityHandle::Loading(_) => true,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
|
@ -1018,7 +1018,7 @@ impl ChannelStore {
|
||||||
if let Some(this) = this.upgrade() {
|
if let Some(this) = this.upgrade() {
|
||||||
this.update(&mut cx, |this, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
for (_, buffer) in this.opened_buffers.drain() {
|
for (_, buffer) in this.opened_buffers.drain() {
|
||||||
if let OpenedModelHandle::Open(buffer) = buffer {
|
if let OpenEntityHandle::Open(buffer) = buffer {
|
||||||
if let Some(buffer) = buffer.upgrade() {
|
if let Some(buffer) = buffer.upgrade() {
|
||||||
buffer.update(cx, |buffer, cx| buffer.disconnect(cx));
|
buffer.update(cx, |buffer, cx| buffer.disconnect(cx));
|
||||||
}
|
}
|
||||||
|
@ -1082,7 +1082,7 @@ impl ChannelStore {
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if let Some(OpenedModelHandle::Open(buffer)) =
|
if let Some(OpenEntityHandle::Open(buffer)) =
|
||||||
self.opened_buffers.remove(&channel_id)
|
self.opened_buffers.remove(&channel_id)
|
||||||
{
|
{
|
||||||
if let Some(buffer) = buffer.upgrade() {
|
if let Some(buffer) = buffer.upgrade() {
|
||||||
|
@ -1098,7 +1098,7 @@ impl ChannelStore {
|
||||||
let channel_changed = index.insert(channel);
|
let channel_changed = index.insert(channel);
|
||||||
|
|
||||||
if channel_changed {
|
if channel_changed {
|
||||||
if let Some(OpenedModelHandle::Open(buffer)) = self.opened_buffers.get(&id) {
|
if let Some(OpenEntityHandle::Open(buffer)) = self.opened_buffers.get(&id) {
|
||||||
if let Some(buffer) = buffer.upgrade() {
|
if let Some(buffer) = buffer.upgrade() {
|
||||||
buffer.update(cx, ChannelBuffer::channel_changed);
|
buffer.update(cx, ChannelBuffer::channel_changed);
|
||||||
}
|
}
|
||||||
|
|
|
@ -379,7 +379,7 @@ pub struct PendingEntitySubscription<T: 'static> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: 'static> PendingEntitySubscription<T> {
|
impl<T: 'static> PendingEntitySubscription<T> {
|
||||||
pub fn set_model(mut self, model: &Entity<T>, cx: &AsyncApp) -> Subscription {
|
pub fn set_entity(mut self, entity: &Entity<T>, cx: &AsyncApp) -> Subscription {
|
||||||
self.consumed = true;
|
self.consumed = true;
|
||||||
let mut handlers = self.client.handler_set.lock();
|
let mut handlers = self.client.handler_set.lock();
|
||||||
let id = (TypeId::of::<T>(), self.remote_id);
|
let id = (TypeId::of::<T>(), self.remote_id);
|
||||||
|
@ -392,7 +392,7 @@ impl<T: 'static> PendingEntitySubscription<T> {
|
||||||
handlers.entities_by_type_and_remote_id.insert(
|
handlers.entities_by_type_and_remote_id.insert(
|
||||||
id,
|
id,
|
||||||
EntityMessageSubscriber::Entity {
|
EntityMessageSubscriber::Entity {
|
||||||
handle: model.downgrade().into(),
|
handle: entity.downgrade().into(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
drop(handlers);
|
drop(handlers);
|
||||||
|
@ -686,8 +686,8 @@ impl Client {
|
||||||
H: 'static + Sync + Fn(Entity<E>, TypedEnvelope<M>, AsyncApp) -> F + Send + Sync,
|
H: 'static + Sync + Fn(Entity<E>, TypedEnvelope<M>, AsyncApp) -> F + Send + Sync,
|
||||||
F: 'static + Future<Output = Result<()>>,
|
F: 'static + Future<Output = Result<()>>,
|
||||||
{
|
{
|
||||||
self.add_message_handler_impl(entity, move |model, message, _, cx| {
|
self.add_message_handler_impl(entity, move |entity, message, _, cx| {
|
||||||
handler(model, message, cx)
|
handler(entity, message, cx)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -709,7 +709,7 @@ impl Client {
|
||||||
let message_type_id = TypeId::of::<M>();
|
let message_type_id = TypeId::of::<M>();
|
||||||
let mut state = self.handler_set.lock();
|
let mut state = self.handler_set.lock();
|
||||||
state
|
state
|
||||||
.models_by_message_type
|
.entities_by_message_type
|
||||||
.insert(message_type_id, entity.into());
|
.insert(message_type_id, entity.into());
|
||||||
|
|
||||||
let prev_handler = state.message_handlers.insert(
|
let prev_handler = state.message_handlers.insert(
|
||||||
|
@ -738,7 +738,7 @@ impl Client {
|
||||||
|
|
||||||
pub fn add_request_handler<M, E, H, F>(
|
pub fn add_request_handler<M, E, H, F>(
|
||||||
self: &Arc<Self>,
|
self: &Arc<Self>,
|
||||||
model: WeakEntity<E>,
|
entity: WeakEntity<E>,
|
||||||
handler: H,
|
handler: H,
|
||||||
) -> Subscription
|
) -> Subscription
|
||||||
where
|
where
|
||||||
|
@ -747,7 +747,7 @@ impl Client {
|
||||||
H: 'static + Sync + Fn(Entity<E>, TypedEnvelope<M>, AsyncApp) -> F + Send + Sync,
|
H: 'static + Sync + Fn(Entity<E>, TypedEnvelope<M>, AsyncApp) -> F + Send + Sync,
|
||||||
F: 'static + Future<Output = Result<M::Response>>,
|
F: 'static + Future<Output = Result<M::Response>>,
|
||||||
{
|
{
|
||||||
self.add_message_handler_impl(model, move |handle, envelope, this, cx| {
|
self.add_message_handler_impl(entity, move |handle, envelope, this, cx| {
|
||||||
Self::respond_to_request(envelope.receipt(), handler(handle, envelope, cx), this)
|
Self::respond_to_request(envelope.receipt(), handler(handle, envelope, cx), this)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1948,9 +1948,9 @@ mod tests {
|
||||||
|
|
||||||
let (done_tx1, done_rx1) = smol::channel::unbounded();
|
let (done_tx1, done_rx1) = smol::channel::unbounded();
|
||||||
let (done_tx2, done_rx2) = smol::channel::unbounded();
|
let (done_tx2, done_rx2) = smol::channel::unbounded();
|
||||||
AnyProtoClient::from(client.clone()).add_model_message_handler(
|
AnyProtoClient::from(client.clone()).add_entity_message_handler(
|
||||||
move |model: Entity<TestModel>, _: TypedEnvelope<proto::JoinProject>, mut cx| {
|
move |entity: Entity<TestEntity>, _: TypedEnvelope<proto::JoinProject>, mut cx| {
|
||||||
match model.update(&mut cx, |model, _| model.id).unwrap() {
|
match entity.update(&mut cx, |entity, _| entity.id).unwrap() {
|
||||||
1 => done_tx1.try_send(()).unwrap(),
|
1 => done_tx1.try_send(()).unwrap(),
|
||||||
2 => done_tx2.try_send(()).unwrap(),
|
2 => done_tx2.try_send(()).unwrap(),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
|
@ -1958,15 +1958,15 @@ mod tests {
|
||||||
async { Ok(()) }
|
async { Ok(()) }
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
let model1 = cx.new(|_| TestModel {
|
let entity1 = cx.new(|_| TestEntity {
|
||||||
id: 1,
|
id: 1,
|
||||||
subscription: None,
|
subscription: None,
|
||||||
});
|
});
|
||||||
let model2 = cx.new(|_| TestModel {
|
let entity2 = cx.new(|_| TestEntity {
|
||||||
id: 2,
|
id: 2,
|
||||||
subscription: None,
|
subscription: None,
|
||||||
});
|
});
|
||||||
let model3 = cx.new(|_| TestModel {
|
let entity3 = cx.new(|_| TestEntity {
|
||||||
id: 3,
|
id: 3,
|
||||||
subscription: None,
|
subscription: None,
|
||||||
});
|
});
|
||||||
|
@ -1974,17 +1974,17 @@ mod tests {
|
||||||
let _subscription1 = client
|
let _subscription1 = client
|
||||||
.subscribe_to_entity(1)
|
.subscribe_to_entity(1)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.set_model(&model1, &mut cx.to_async());
|
.set_entity(&entity1, &mut cx.to_async());
|
||||||
let _subscription2 = client
|
let _subscription2 = client
|
||||||
.subscribe_to_entity(2)
|
.subscribe_to_entity(2)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.set_model(&model2, &mut cx.to_async());
|
.set_entity(&entity2, &mut cx.to_async());
|
||||||
// Ensure dropping a subscription for the same entity type still allows receiving of
|
// Ensure dropping a subscription for the same entity type still allows receiving of
|
||||||
// messages for other entity IDs of the same type.
|
// messages for other entity IDs of the same type.
|
||||||
let subscription3 = client
|
let subscription3 = client
|
||||||
.subscribe_to_entity(3)
|
.subscribe_to_entity(3)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.set_model(&model3, &mut cx.to_async());
|
.set_entity(&entity3, &mut cx.to_async());
|
||||||
drop(subscription3);
|
drop(subscription3);
|
||||||
|
|
||||||
server.send(proto::JoinProject { project_id: 1 });
|
server.send(proto::JoinProject { project_id: 1 });
|
||||||
|
@ -2006,11 +2006,11 @@ mod tests {
|
||||||
});
|
});
|
||||||
let server = FakeServer::for_client(user_id, &client, cx).await;
|
let server = FakeServer::for_client(user_id, &client, cx).await;
|
||||||
|
|
||||||
let model = cx.new(|_| TestModel::default());
|
let entity = cx.new(|_| TestEntity::default());
|
||||||
let (done_tx1, _done_rx1) = smol::channel::unbounded();
|
let (done_tx1, _done_rx1) = smol::channel::unbounded();
|
||||||
let (done_tx2, done_rx2) = smol::channel::unbounded();
|
let (done_tx2, done_rx2) = smol::channel::unbounded();
|
||||||
let subscription1 = client.add_message_handler(
|
let subscription1 = client.add_message_handler(
|
||||||
model.downgrade(),
|
entity.downgrade(),
|
||||||
move |_, _: TypedEnvelope<proto::Ping>, _| {
|
move |_, _: TypedEnvelope<proto::Ping>, _| {
|
||||||
done_tx1.try_send(()).unwrap();
|
done_tx1.try_send(()).unwrap();
|
||||||
async { Ok(()) }
|
async { Ok(()) }
|
||||||
|
@ -2018,7 +2018,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
drop(subscription1);
|
drop(subscription1);
|
||||||
let _subscription2 = client.add_message_handler(
|
let _subscription2 = client.add_message_handler(
|
||||||
model.downgrade(),
|
entity.downgrade(),
|
||||||
move |_, _: TypedEnvelope<proto::Ping>, _| {
|
move |_, _: TypedEnvelope<proto::Ping>, _| {
|
||||||
done_tx2.try_send(()).unwrap();
|
done_tx2.try_send(()).unwrap();
|
||||||
async { Ok(()) }
|
async { Ok(()) }
|
||||||
|
@ -2041,27 +2041,27 @@ mod tests {
|
||||||
});
|
});
|
||||||
let server = FakeServer::for_client(user_id, &client, cx).await;
|
let server = FakeServer::for_client(user_id, &client, cx).await;
|
||||||
|
|
||||||
let model = cx.new(|_| TestModel::default());
|
let entity = cx.new(|_| TestEntity::default());
|
||||||
let (done_tx, done_rx) = smol::channel::unbounded();
|
let (done_tx, done_rx) = smol::channel::unbounded();
|
||||||
let subscription = client.add_message_handler(
|
let subscription = client.add_message_handler(
|
||||||
model.clone().downgrade(),
|
entity.clone().downgrade(),
|
||||||
move |model: Entity<TestModel>, _: TypedEnvelope<proto::Ping>, mut cx| {
|
move |entity: Entity<TestEntity>, _: TypedEnvelope<proto::Ping>, mut cx| {
|
||||||
model
|
entity
|
||||||
.update(&mut cx, |model, _| model.subscription.take())
|
.update(&mut cx, |entity, _| entity.subscription.take())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
done_tx.try_send(()).unwrap();
|
done_tx.try_send(()).unwrap();
|
||||||
async { Ok(()) }
|
async { Ok(()) }
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
model.update(cx, |model, _| {
|
entity.update(cx, |entity, _| {
|
||||||
model.subscription = Some(subscription);
|
entity.subscription = Some(subscription);
|
||||||
});
|
});
|
||||||
server.send(proto::Ping {});
|
server.send(proto::Ping {});
|
||||||
done_rx.recv().await.unwrap();
|
done_rx.recv().await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct TestModel {
|
struct TestEntity {
|
||||||
id: usize,
|
id: usize,
|
||||||
subscription: Option<Subscription>,
|
subscription: Option<Subscription>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -342,7 +342,7 @@ async fn test_multiple_handles_to_channel_buffer(
|
||||||
future::try_join3(channel_buffer_1, channel_buffer_2, channel_buffer_3)
|
future::try_join3(channel_buffer_1, channel_buffer_2, channel_buffer_3)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let channel_buffer_model_id = channel_buffer.entity_id();
|
let channel_buffer_entity_id = channel_buffer.entity_id();
|
||||||
assert_eq!(channel_buffer, channel_buffer_2);
|
assert_eq!(channel_buffer, channel_buffer_2);
|
||||||
assert_eq!(channel_buffer, channel_buffer_3);
|
assert_eq!(channel_buffer, channel_buffer_3);
|
||||||
|
|
||||||
|
@ -366,7 +366,7 @@ async fn test_multiple_handles_to_channel_buffer(
|
||||||
.update(cx_a, |store, cx| store.open_channel_buffer(channel_id, cx))
|
.update(cx_a, |store, cx| store.open_channel_buffer(channel_id, cx))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_ne!(channel_buffer.entity_id(), channel_buffer_model_id);
|
assert_ne!(channel_buffer.entity_id(), channel_buffer_entity_id);
|
||||||
channel_buffer.update(cx_a, |buffer, cx| {
|
channel_buffer.update(cx_a, |buffer, cx| {
|
||||||
buffer.buffer().update(cx, |buffer, _| {
|
buffer.buffer().update(cx, |buffer, _| {
|
||||||
assert_eq!(buffer.text(), "hello");
|
assert_eq!(buffer.text(), "hello");
|
||||||
|
|
|
@ -849,10 +849,10 @@ impl TestClient {
|
||||||
) -> (Entity<Workspace>, &'a mut VisualTestContext) {
|
) -> (Entity<Workspace>, &'a mut VisualTestContext) {
|
||||||
let window = cx.update(|cx| cx.active_window().unwrap().downcast::<Workspace>().unwrap());
|
let window = cx.update(|cx| cx.active_window().unwrap().downcast::<Workspace>().unwrap());
|
||||||
|
|
||||||
let model = window.root(cx).unwrap();
|
let entity = window.root(cx).unwrap();
|
||||||
let cx = VisualTestContext::from_window(*window.deref(), cx).as_mut();
|
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.
|
// it might be nice to try and cleanup these at the end of each test.
|
||||||
(model, cx)
|
(entity, cx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -861,9 +861,9 @@ pub fn open_channel_notes(
|
||||||
cx: &mut VisualTestContext,
|
cx: &mut VisualTestContext,
|
||||||
) -> Task<anyhow::Result<Entity<ChannelView>>> {
|
) -> Task<anyhow::Result<Entity<ChannelView>>> {
|
||||||
let window = cx.update(|_, cx| cx.active_window().unwrap().downcast::<Workspace>().unwrap());
|
let window = cx.update(|_, cx| cx.active_window().unwrap().downcast::<Workspace>().unwrap());
|
||||||
let model = window.root(cx).unwrap();
|
let entity = window.root(cx).unwrap();
|
||||||
|
|
||||||
cx.update(|window, cx| ChannelView::open(channel_id, None, model.clone(), window, cx))
|
cx.update(|window, cx| ChannelView::open(channel_id, None, entity.clone(), window, cx))
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for TestClient {
|
impl Drop for TestClient {
|
||||||
|
|
|
@ -97,14 +97,14 @@ impl ChatPanel {
|
||||||
});
|
});
|
||||||
|
|
||||||
cx.new(|cx| {
|
cx.new(|cx| {
|
||||||
let model = cx.entity().downgrade();
|
let entity = cx.entity().downgrade();
|
||||||
let message_list = ListState::new(
|
let message_list = ListState::new(
|
||||||
0,
|
0,
|
||||||
gpui::ListAlignment::Bottom,
|
gpui::ListAlignment::Bottom,
|
||||||
px(1000.),
|
px(1000.),
|
||||||
move |ix, window, cx| {
|
move |ix, window, cx| {
|
||||||
if let Some(model) = model.upgrade() {
|
if let Some(entity) = entity.upgrade() {
|
||||||
model.update(cx, |this: &mut Self, cx| {
|
entity.update(cx, |this: &mut Self, cx| {
|
||||||
this.render_message(ix, window, cx).into_any_element()
|
this.render_message(ix, window, cx).into_any_element()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -239,14 +239,14 @@ impl CollabPanel {
|
||||||
)
|
)
|
||||||
.detach();
|
.detach();
|
||||||
|
|
||||||
let model = cx.entity().downgrade();
|
let entity = cx.entity().downgrade();
|
||||||
let list_state = ListState::new(
|
let list_state = ListState::new(
|
||||||
0,
|
0,
|
||||||
gpui::ListAlignment::Top,
|
gpui::ListAlignment::Top,
|
||||||
px(1000.),
|
px(1000.),
|
||||||
move |ix, window, cx| {
|
move |ix, window, cx| {
|
||||||
if let Some(model) = model.upgrade() {
|
if let Some(entity) = entity.upgrade() {
|
||||||
model.update(cx, |this, cx| this.render_list_entry(ix, window, cx))
|
entity.update(cx, |this, cx| this.render_list_entry(ix, window, cx))
|
||||||
} else {
|
} else {
|
||||||
div().into_any()
|
div().into_any()
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,13 +110,13 @@ impl NotificationPanel {
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
|
|
||||||
let model = cx.entity().downgrade();
|
let entity = cx.entity().downgrade();
|
||||||
let notification_list =
|
let notification_list =
|
||||||
ListState::new(0, ListAlignment::Top, px(1000.), move |ix, window, cx| {
|
ListState::new(0, ListAlignment::Top, px(1000.), move |ix, window, cx| {
|
||||||
model
|
entity
|
||||||
.upgrade()
|
.upgrade()
|
||||||
.and_then(|model| {
|
.and_then(|entity| {
|
||||||
model.update(cx, |this, cx| this.render_notification(ix, window, cx))
|
entity.update(cx, |this, cx| this.render_notification(ix, window, cx))
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| div().into_any())
|
.unwrap_or_else(|| div().into_any())
|
||||||
});
|
});
|
||||||
|
@ -323,9 +323,9 @@ impl NotificationPanel {
|
||||||
.justify_end()
|
.justify_end()
|
||||||
.child(Button::new("decline", "Decline").on_click({
|
.child(Button::new("decline", "Decline").on_click({
|
||||||
let notification = notification.clone();
|
let notification = notification.clone();
|
||||||
let model = cx.entity().clone();
|
let entity = cx.entity().clone();
|
||||||
move |_, _, cx| {
|
move |_, _, cx| {
|
||||||
model.update(cx, |this, cx| {
|
entity.update(cx, |this, cx| {
|
||||||
this.respond_to_notification(
|
this.respond_to_notification(
|
||||||
notification.clone(),
|
notification.clone(),
|
||||||
false,
|
false,
|
||||||
|
@ -336,9 +336,9 @@ impl NotificationPanel {
|
||||||
}))
|
}))
|
||||||
.child(Button::new("accept", "Accept").on_click({
|
.child(Button::new("accept", "Accept").on_click({
|
||||||
let notification = notification.clone();
|
let notification = notification.clone();
|
||||||
let model = cx.entity().clone();
|
let entity = cx.entity().clone();
|
||||||
move |_, _, cx| {
|
move |_, _, cx| {
|
||||||
model.update(cx, |this, cx| {
|
entity.update(cx, |this, cx| {
|
||||||
this.respond_to_notification(
|
this.respond_to_notification(
|
||||||
notification.clone(),
|
notification.clone(),
|
||||||
true,
|
true,
|
||||||
|
|
|
@ -62,9 +62,9 @@ fn test_edit_events(cx: &mut TestAppContext) {
|
||||||
let editor1 = cx.add_window({
|
let editor1 = cx.add_window({
|
||||||
let events = events.clone();
|
let events = events.clone();
|
||||||
|window, cx| {
|
|window, cx| {
|
||||||
let model = cx.entity().clone();
|
let entity = cx.entity().clone();
|
||||||
cx.subscribe_in(
|
cx.subscribe_in(
|
||||||
&model,
|
&entity,
|
||||||
window,
|
window,
|
||||||
move |_, _, event: &EditorEvent, _, _| match event {
|
move |_, _, event: &EditorEvent, _, _| match event {
|
||||||
EditorEvent::Edited { .. } => events.borrow_mut().push(("editor1", "edited")),
|
EditorEvent::Edited { .. } => events.borrow_mut().push(("editor1", "edited")),
|
||||||
|
@ -10196,15 +10196,15 @@ async fn test_following(cx: &mut gpui::TestAppContext) {
|
||||||
let is_still_following = Rc::new(RefCell::new(true));
|
let is_still_following = Rc::new(RefCell::new(true));
|
||||||
let follower_edit_event_count = Rc::new(RefCell::new(0));
|
let follower_edit_event_count = Rc::new(RefCell::new(0));
|
||||||
let pending_update = Rc::new(RefCell::new(None));
|
let pending_update = Rc::new(RefCell::new(None));
|
||||||
let leader_model = leader.root(cx).unwrap();
|
let leader_entity = leader.root(cx).unwrap();
|
||||||
let follower_model = follower.root(cx).unwrap();
|
let follower_entity = follower.root(cx).unwrap();
|
||||||
_ = follower.update(cx, {
|
_ = follower.update(cx, {
|
||||||
let update = pending_update.clone();
|
let update = pending_update.clone();
|
||||||
let is_still_following = is_still_following.clone();
|
let is_still_following = is_still_following.clone();
|
||||||
let follower_edit_event_count = follower_edit_event_count.clone();
|
let follower_edit_event_count = follower_edit_event_count.clone();
|
||||||
|_, window, cx| {
|
|_, window, cx| {
|
||||||
cx.subscribe_in(
|
cx.subscribe_in(
|
||||||
&leader_model,
|
&leader_entity,
|
||||||
window,
|
window,
|
||||||
move |_, leader, event, window, cx| {
|
move |_, leader, event, window, cx| {
|
||||||
leader.read(cx).add_event_to_update_proto(
|
leader.read(cx).add_event_to_update_proto(
|
||||||
|
@ -10218,7 +10218,7 @@ async fn test_following(cx: &mut gpui::TestAppContext) {
|
||||||
.detach();
|
.detach();
|
||||||
|
|
||||||
cx.subscribe_in(
|
cx.subscribe_in(
|
||||||
&follower_model,
|
&follower_entity,
|
||||||
window,
|
window,
|
||||||
move |_, _, event: &EditorEvent, _window, _cx| {
|
move |_, _, event: &EditorEvent, _window, _cx| {
|
||||||
if matches!(Editor::to_follow_event(event), Some(FollowEvent::Unfollow)) {
|
if matches!(Editor::to_follow_event(event), Some(FollowEvent::Unfollow)) {
|
||||||
|
@ -10384,11 +10384,11 @@ async fn test_following_with_multiple_excerpts(cx: &mut gpui::TestAppContext) {
|
||||||
// Start following the editor when it has no excerpts.
|
// Start following the editor when it has no excerpts.
|
||||||
let mut state_message =
|
let mut state_message =
|
||||||
leader.update_in(cx, |leader, window, cx| leader.to_state_proto(window, cx));
|
leader.update_in(cx, |leader, window, cx| leader.to_state_proto(window, cx));
|
||||||
let workspace_model = workspace.root(cx).unwrap();
|
let workspace_entity = workspace.root(cx).unwrap();
|
||||||
let follower_1 = cx
|
let follower_1 = cx
|
||||||
.update_window(*workspace.deref(), |_, window, cx| {
|
.update_window(*workspace.deref(), |_, window, cx| {
|
||||||
Editor::from_state_proto(
|
Editor::from_state_proto(
|
||||||
workspace_model,
|
workspace_entity,
|
||||||
ViewId {
|
ViewId {
|
||||||
creator: Default::default(),
|
creator: Default::default(),
|
||||||
id: 0,
|
id: 0,
|
||||||
|
@ -10486,11 +10486,11 @@ async fn test_following_with_multiple_excerpts(cx: &mut gpui::TestAppContext) {
|
||||||
// Start following separately after it already has excerpts.
|
// Start following separately after it already has excerpts.
|
||||||
let mut state_message =
|
let mut state_message =
|
||||||
leader.update_in(cx, |leader, window, cx| leader.to_state_proto(window, cx));
|
leader.update_in(cx, |leader, window, cx| leader.to_state_proto(window, cx));
|
||||||
let workspace_model = workspace.root(cx).unwrap();
|
let workspace_entity = workspace.root(cx).unwrap();
|
||||||
let follower_2 = cx
|
let follower_2 = cx
|
||||||
.update_window(*workspace.deref(), |_, window, cx| {
|
.update_window(*workspace.deref(), |_, window, cx| {
|
||||||
Editor::from_state_proto(
|
Editor::from_state_proto(
|
||||||
workspace_model,
|
workspace_entity,
|
||||||
ViewId {
|
ViewId {
|
||||||
creator: Default::default(),
|
creator: Default::default(),
|
||||||
id: 0,
|
id: 0,
|
||||||
|
|
|
@ -321,7 +321,7 @@ impl GitPanel {
|
||||||
current_modifiers: window.modifiers(),
|
current_modifiers: window.modifiers(),
|
||||||
width: Some(px(360.)),
|
width: Some(px(360.)),
|
||||||
scrollbar_state: ScrollbarState::new(scroll_handle.clone())
|
scrollbar_state: ScrollbarState::new(scroll_handle.clone())
|
||||||
.parent_model(&cx.entity()),
|
.parent_entity(&cx.entity()),
|
||||||
repository_selector,
|
repository_selector,
|
||||||
selected_entry: None,
|
selected_entry: None,
|
||||||
show_scrollbar: false,
|
show_scrollbar: false,
|
||||||
|
|
|
@ -821,13 +821,13 @@ impl Element for MarkdownElement {
|
||||||
let mut context = KeyContext::default();
|
let mut context = KeyContext::default();
|
||||||
context.add("Markdown");
|
context.add("Markdown");
|
||||||
window.set_key_context(context);
|
window.set_key_context(context);
|
||||||
let model = self.markdown.clone();
|
let entity = self.markdown.clone();
|
||||||
window.on_action(std::any::TypeId::of::<crate::Copy>(), {
|
window.on_action(std::any::TypeId::of::<crate::Copy>(), {
|
||||||
let text = rendered_markdown.text.clone();
|
let text = rendered_markdown.text.clone();
|
||||||
move |_, phase, window, cx| {
|
move |_, phase, window, cx| {
|
||||||
let text = text.clone();
|
let text = text.clone();
|
||||||
if phase == DispatchPhase::Bubble {
|
if phase == DispatchPhase::Bubble {
|
||||||
model.update(cx, move |this, cx| this.copy(&text, window, cx))
|
entity.update(cx, move |this, cx| this.copy(&text, window, cx))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -796,9 +796,9 @@ impl OutlinePanel {
|
||||||
show_scrollbar: !Self::should_autohide_scrollbar(cx),
|
show_scrollbar: !Self::should_autohide_scrollbar(cx),
|
||||||
hide_scrollbar_task: None,
|
hide_scrollbar_task: None,
|
||||||
vertical_scrollbar_state: ScrollbarState::new(scroll_handle.clone())
|
vertical_scrollbar_state: ScrollbarState::new(scroll_handle.clone())
|
||||||
.parent_model(&cx.entity()),
|
.parent_entity(&cx.entity()),
|
||||||
horizontal_scrollbar_state: ScrollbarState::new(scroll_handle.clone())
|
horizontal_scrollbar_state: ScrollbarState::new(scroll_handle.clone())
|
||||||
.parent_model(&cx.entity()),
|
.parent_entity(&cx.entity()),
|
||||||
max_width_item_index: None,
|
max_width_item_index: None,
|
||||||
scroll_handle,
|
scroll_handle,
|
||||||
focus_handle,
|
focus_handle,
|
||||||
|
|
|
@ -281,16 +281,16 @@ impl<D: PickerDelegate> Picker<D> {
|
||||||
ElementContainer::UniformList(UniformListScrollHandle::new())
|
ElementContainer::UniformList(UniformListScrollHandle::new())
|
||||||
}
|
}
|
||||||
ContainerKind::List => {
|
ContainerKind::List => {
|
||||||
let model = cx.entity().downgrade();
|
let entity = cx.entity().downgrade();
|
||||||
ElementContainer::List(ListState::new(
|
ElementContainer::List(ListState::new(
|
||||||
0,
|
0,
|
||||||
gpui::ListAlignment::Top,
|
gpui::ListAlignment::Top,
|
||||||
px(1000.),
|
px(1000.),
|
||||||
move |ix, window, cx| {
|
move |ix, window, cx| {
|
||||||
model
|
entity
|
||||||
.upgrade()
|
.upgrade()
|
||||||
.map(|model| {
|
.map(|entity| {
|
||||||
model.update(cx, |this, cx| {
|
entity.update(cx, |this, cx| {
|
||||||
this.render_element(window, cx, ix).into_any_element()
|
this.render_element(window, cx, ix).into_any_element()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -894,15 +894,15 @@ impl LocalBufferStore {
|
||||||
|
|
||||||
impl BufferStore {
|
impl BufferStore {
|
||||||
pub fn init(client: &AnyProtoClient) {
|
pub fn init(client: &AnyProtoClient) {
|
||||||
client.add_model_message_handler(Self::handle_buffer_reloaded);
|
client.add_entity_message_handler(Self::handle_buffer_reloaded);
|
||||||
client.add_model_message_handler(Self::handle_buffer_saved);
|
client.add_entity_message_handler(Self::handle_buffer_saved);
|
||||||
client.add_model_message_handler(Self::handle_update_buffer_file);
|
client.add_entity_message_handler(Self::handle_update_buffer_file);
|
||||||
client.add_model_request_handler(Self::handle_save_buffer);
|
client.add_entity_request_handler(Self::handle_save_buffer);
|
||||||
client.add_model_request_handler(Self::handle_blame_buffer);
|
client.add_entity_request_handler(Self::handle_blame_buffer);
|
||||||
client.add_model_request_handler(Self::handle_reload_buffers);
|
client.add_entity_request_handler(Self::handle_reload_buffers);
|
||||||
client.add_model_request_handler(Self::handle_get_permalink_to_line);
|
client.add_entity_request_handler(Self::handle_get_permalink_to_line);
|
||||||
client.add_model_request_handler(Self::handle_get_staged_text);
|
client.add_entity_request_handler(Self::handle_get_staged_text);
|
||||||
client.add_model_message_handler(Self::handle_update_diff_base);
|
client.add_entity_message_handler(Self::handle_update_diff_base);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a buffer store, optionally retaining its buffers.
|
/// Creates a buffer store, optionally retaining its buffers.
|
||||||
|
|
|
@ -35,7 +35,7 @@ impl<E: 'static> DebouncedDelay<E> {
|
||||||
self.cancel_channel = Some(sender);
|
self.cancel_channel = Some(sender);
|
||||||
|
|
||||||
let previous_task = self.task.take();
|
let previous_task = self.task.take();
|
||||||
self.task = Some(cx.spawn(move |model, mut cx| async move {
|
self.task = Some(cx.spawn(move |entity, mut cx| async move {
|
||||||
let mut timer = cx.background_executor().timer(delay).fuse();
|
let mut timer = cx.background_executor().timer(delay).fuse();
|
||||||
if let Some(previous_task) = previous_task {
|
if let Some(previous_task) = previous_task {
|
||||||
previous_task.await;
|
previous_task.await;
|
||||||
|
@ -46,7 +46,7 @@ impl<E: 'static> DebouncedDelay<E> {
|
||||||
_ = timer => {}
|
_ = timer => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(task) = model.update(&mut cx, |project, cx| (func)(project, cx)) {
|
if let Ok(task) = entity.update(&mut cx, |project, cx| (func)(project, cx)) {
|
||||||
task.await;
|
task.await;
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -387,18 +387,18 @@ impl ImageStoreImpl for Entity<LocalImageStore> {
|
||||||
let LoadedBinaryFile { file, content } = load_file.await?;
|
let LoadedBinaryFile { file, content } = load_file.await?;
|
||||||
let image = create_gpui_image(content)?;
|
let image = create_gpui_image(content)?;
|
||||||
|
|
||||||
let model = cx.new(|cx| ImageItem {
|
let entity = cx.new(|cx| ImageItem {
|
||||||
id: cx.entity_id().as_non_zero_u64().into(),
|
id: cx.entity_id().as_non_zero_u64().into(),
|
||||||
file: file.clone(),
|
file: file.clone(),
|
||||||
image,
|
image,
|
||||||
reload_task: None,
|
reload_task: None,
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let image_id = cx.read_entity(&model, |model, _| model.id)?;
|
let image_id = cx.read_entity(&entity, |model, _| model.id)?;
|
||||||
|
|
||||||
this.update(&mut cx, |this, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
image_store.update(cx, |image_store, cx| {
|
image_store.update(cx, |image_store, cx| {
|
||||||
image_store.add_image(model.clone(), cx)
|
image_store.add_image(entity.clone(), cx)
|
||||||
})??;
|
})??;
|
||||||
this.local_image_ids_by_path.insert(
|
this.local_image_ids_by_path.insert(
|
||||||
ProjectPath {
|
ProjectPath {
|
||||||
|
@ -415,7 +415,7 @@ impl ImageStoreImpl for Entity<LocalImageStore> {
|
||||||
anyhow::Ok(())
|
anyhow::Ok(())
|
||||||
})??;
|
})??;
|
||||||
|
|
||||||
Ok(model)
|
Ok(entity)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2854,37 +2854,37 @@ struct CoreSymbol {
|
||||||
|
|
||||||
impl LspStore {
|
impl LspStore {
|
||||||
pub fn init(client: &AnyProtoClient) {
|
pub fn init(client: &AnyProtoClient) {
|
||||||
client.add_model_request_handler(Self::handle_multi_lsp_query);
|
client.add_entity_request_handler(Self::handle_multi_lsp_query);
|
||||||
client.add_model_request_handler(Self::handle_restart_language_servers);
|
client.add_entity_request_handler(Self::handle_restart_language_servers);
|
||||||
client.add_model_request_handler(Self::handle_cancel_language_server_work);
|
client.add_entity_request_handler(Self::handle_cancel_language_server_work);
|
||||||
client.add_model_message_handler(Self::handle_start_language_server);
|
client.add_entity_message_handler(Self::handle_start_language_server);
|
||||||
client.add_model_message_handler(Self::handle_update_language_server);
|
client.add_entity_message_handler(Self::handle_update_language_server);
|
||||||
client.add_model_message_handler(Self::handle_language_server_log);
|
client.add_entity_message_handler(Self::handle_language_server_log);
|
||||||
client.add_model_message_handler(Self::handle_update_diagnostic_summary);
|
client.add_entity_message_handler(Self::handle_update_diagnostic_summary);
|
||||||
client.add_model_request_handler(Self::handle_format_buffers);
|
client.add_entity_request_handler(Self::handle_format_buffers);
|
||||||
client.add_model_request_handler(Self::handle_resolve_completion_documentation);
|
client.add_entity_request_handler(Self::handle_resolve_completion_documentation);
|
||||||
client.add_model_request_handler(Self::handle_apply_code_action);
|
client.add_entity_request_handler(Self::handle_apply_code_action);
|
||||||
client.add_model_request_handler(Self::handle_inlay_hints);
|
client.add_entity_request_handler(Self::handle_inlay_hints);
|
||||||
client.add_model_request_handler(Self::handle_get_project_symbols);
|
client.add_entity_request_handler(Self::handle_get_project_symbols);
|
||||||
client.add_model_request_handler(Self::handle_resolve_inlay_hint);
|
client.add_entity_request_handler(Self::handle_resolve_inlay_hint);
|
||||||
client.add_model_request_handler(Self::handle_open_buffer_for_symbol);
|
client.add_entity_request_handler(Self::handle_open_buffer_for_symbol);
|
||||||
client.add_model_request_handler(Self::handle_refresh_inlay_hints);
|
client.add_entity_request_handler(Self::handle_refresh_inlay_hints);
|
||||||
client.add_model_request_handler(Self::handle_on_type_formatting);
|
client.add_entity_request_handler(Self::handle_on_type_formatting);
|
||||||
client.add_model_request_handler(Self::handle_apply_additional_edits_for_completion);
|
client.add_entity_request_handler(Self::handle_apply_additional_edits_for_completion);
|
||||||
client.add_model_request_handler(Self::handle_register_buffer_with_language_servers);
|
client.add_entity_request_handler(Self::handle_register_buffer_with_language_servers);
|
||||||
client.add_model_request_handler(Self::handle_rename_project_entry);
|
client.add_entity_request_handler(Self::handle_rename_project_entry);
|
||||||
client.add_model_request_handler(Self::handle_lsp_command::<GetCodeActions>);
|
client.add_entity_request_handler(Self::handle_lsp_command::<GetCodeActions>);
|
||||||
client.add_model_request_handler(Self::handle_lsp_command::<GetCompletions>);
|
client.add_entity_request_handler(Self::handle_lsp_command::<GetCompletions>);
|
||||||
client.add_model_request_handler(Self::handle_lsp_command::<GetHover>);
|
client.add_entity_request_handler(Self::handle_lsp_command::<GetHover>);
|
||||||
client.add_model_request_handler(Self::handle_lsp_command::<GetDefinition>);
|
client.add_entity_request_handler(Self::handle_lsp_command::<GetDefinition>);
|
||||||
client.add_model_request_handler(Self::handle_lsp_command::<GetDeclaration>);
|
client.add_entity_request_handler(Self::handle_lsp_command::<GetDeclaration>);
|
||||||
client.add_model_request_handler(Self::handle_lsp_command::<GetTypeDefinition>);
|
client.add_entity_request_handler(Self::handle_lsp_command::<GetTypeDefinition>);
|
||||||
client.add_model_request_handler(Self::handle_lsp_command::<GetDocumentHighlights>);
|
client.add_entity_request_handler(Self::handle_lsp_command::<GetDocumentHighlights>);
|
||||||
client.add_model_request_handler(Self::handle_lsp_command::<GetReferences>);
|
client.add_entity_request_handler(Self::handle_lsp_command::<GetReferences>);
|
||||||
client.add_model_request_handler(Self::handle_lsp_command::<PrepareRename>);
|
client.add_entity_request_handler(Self::handle_lsp_command::<PrepareRename>);
|
||||||
client.add_model_request_handler(Self::handle_lsp_command::<PerformRename>);
|
client.add_entity_request_handler(Self::handle_lsp_command::<PerformRename>);
|
||||||
client.add_model_request_handler(Self::handle_lsp_command::<lsp_ext_command::ExpandMacro>);
|
client.add_entity_request_handler(Self::handle_lsp_command::<lsp_ext_command::ExpandMacro>);
|
||||||
client.add_model_request_handler(Self::handle_lsp_command::<LinkedEditingRange>);
|
client.add_entity_request_handler(Self::handle_lsp_command::<LinkedEditingRange>);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_remote(&self) -> Option<&RemoteLspStore> {
|
pub fn as_remote(&self) -> Option<&RemoteLspStore> {
|
||||||
|
|
|
@ -592,25 +592,25 @@ impl Project {
|
||||||
Self::init_settings(cx);
|
Self::init_settings(cx);
|
||||||
|
|
||||||
let client: AnyProtoClient = client.clone().into();
|
let client: AnyProtoClient = client.clone().into();
|
||||||
client.add_model_message_handler(Self::handle_add_collaborator);
|
client.add_entity_message_handler(Self::handle_add_collaborator);
|
||||||
client.add_model_message_handler(Self::handle_update_project_collaborator);
|
client.add_entity_message_handler(Self::handle_update_project_collaborator);
|
||||||
client.add_model_message_handler(Self::handle_remove_collaborator);
|
client.add_entity_message_handler(Self::handle_remove_collaborator);
|
||||||
client.add_model_message_handler(Self::handle_update_project);
|
client.add_entity_message_handler(Self::handle_update_project);
|
||||||
client.add_model_message_handler(Self::handle_unshare_project);
|
client.add_entity_message_handler(Self::handle_unshare_project);
|
||||||
client.add_model_request_handler(Self::handle_update_buffer);
|
client.add_entity_request_handler(Self::handle_update_buffer);
|
||||||
client.add_model_message_handler(Self::handle_update_worktree);
|
client.add_entity_message_handler(Self::handle_update_worktree);
|
||||||
client.add_model_request_handler(Self::handle_synchronize_buffers);
|
client.add_entity_request_handler(Self::handle_synchronize_buffers);
|
||||||
|
|
||||||
client.add_model_request_handler(Self::handle_search_candidate_buffers);
|
client.add_entity_request_handler(Self::handle_search_candidate_buffers);
|
||||||
client.add_model_request_handler(Self::handle_open_buffer_by_id);
|
client.add_entity_request_handler(Self::handle_open_buffer_by_id);
|
||||||
client.add_model_request_handler(Self::handle_open_buffer_by_path);
|
client.add_entity_request_handler(Self::handle_open_buffer_by_path);
|
||||||
client.add_model_request_handler(Self::handle_open_new_buffer);
|
client.add_entity_request_handler(Self::handle_open_new_buffer);
|
||||||
client.add_model_message_handler(Self::handle_create_buffer_for_peer);
|
client.add_entity_message_handler(Self::handle_create_buffer_for_peer);
|
||||||
|
|
||||||
client.add_model_request_handler(Self::handle_stage);
|
client.add_entity_request_handler(Self::handle_stage);
|
||||||
client.add_model_request_handler(Self::handle_unstage);
|
client.add_entity_request_handler(Self::handle_unstage);
|
||||||
client.add_model_request_handler(Self::handle_commit);
|
client.add_entity_request_handler(Self::handle_commit);
|
||||||
client.add_model_request_handler(Self::handle_open_commit_message_buffer);
|
client.add_entity_request_handler(Self::handle_open_commit_message_buffer);
|
||||||
|
|
||||||
WorktreeStore::init(&client);
|
WorktreeStore::init(&client);
|
||||||
BufferStore::init(&client);
|
BufferStore::init(&client);
|
||||||
|
@ -893,13 +893,13 @@ impl Project {
|
||||||
ssh.subscribe_to_entity(SSH_PROJECT_ID, &this.lsp_store);
|
ssh.subscribe_to_entity(SSH_PROJECT_ID, &this.lsp_store);
|
||||||
ssh.subscribe_to_entity(SSH_PROJECT_ID, &this.settings_observer);
|
ssh.subscribe_to_entity(SSH_PROJECT_ID, &this.settings_observer);
|
||||||
|
|
||||||
ssh_proto.add_model_message_handler(Self::handle_create_buffer_for_peer);
|
ssh_proto.add_entity_message_handler(Self::handle_create_buffer_for_peer);
|
||||||
ssh_proto.add_model_message_handler(Self::handle_update_worktree);
|
ssh_proto.add_entity_message_handler(Self::handle_update_worktree);
|
||||||
ssh_proto.add_model_message_handler(Self::handle_update_project);
|
ssh_proto.add_entity_message_handler(Self::handle_update_project);
|
||||||
ssh_proto.add_model_message_handler(Self::handle_toast);
|
ssh_proto.add_entity_message_handler(Self::handle_toast);
|
||||||
ssh_proto.add_model_request_handler(Self::handle_language_server_prompt_request);
|
ssh_proto.add_entity_request_handler(Self::handle_language_server_prompt_request);
|
||||||
ssh_proto.add_model_message_handler(Self::handle_hide_toast);
|
ssh_proto.add_entity_message_handler(Self::handle_hide_toast);
|
||||||
ssh_proto.add_model_request_handler(Self::handle_update_buffer_from_ssh);
|
ssh_proto.add_entity_request_handler(Self::handle_update_buffer_from_ssh);
|
||||||
BufferStore::init(&ssh_proto);
|
BufferStore::init(&ssh_proto);
|
||||||
LspStore::init(&ssh_proto);
|
LspStore::init(&ssh_proto);
|
||||||
SettingsObserver::init(&ssh_proto);
|
SettingsObserver::init(&ssh_proto);
|
||||||
|
@ -1110,17 +1110,19 @@ impl Project {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|s| match s {
|
.map(|s| match s {
|
||||||
EntitySubscription::BufferStore(subscription) => {
|
EntitySubscription::BufferStore(subscription) => {
|
||||||
subscription.set_model(&buffer_store, &mut cx)
|
subscription.set_entity(&buffer_store, &mut cx)
|
||||||
}
|
}
|
||||||
EntitySubscription::WorktreeStore(subscription) => {
|
EntitySubscription::WorktreeStore(subscription) => {
|
||||||
subscription.set_model(&worktree_store, &mut cx)
|
subscription.set_entity(&worktree_store, &mut cx)
|
||||||
}
|
}
|
||||||
EntitySubscription::SettingsObserver(subscription) => {
|
EntitySubscription::SettingsObserver(subscription) => {
|
||||||
subscription.set_model(&settings_observer, &mut cx)
|
subscription.set_entity(&settings_observer, &mut cx)
|
||||||
|
}
|
||||||
|
EntitySubscription::Project(subscription) => {
|
||||||
|
subscription.set_entity(&this, &mut cx)
|
||||||
}
|
}
|
||||||
EntitySubscription::Project(subscription) => subscription.set_model(&this, &mut cx),
|
|
||||||
EntitySubscription::LspStore(subscription) => {
|
EntitySubscription::LspStore(subscription) => {
|
||||||
subscription.set_model(&lsp_store, &mut cx)
|
subscription.set_entity(&lsp_store, &mut cx)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
@ -1631,19 +1633,19 @@ impl Project {
|
||||||
self.client_subscriptions.extend([
|
self.client_subscriptions.extend([
|
||||||
self.client
|
self.client
|
||||||
.subscribe_to_entity(project_id)?
|
.subscribe_to_entity(project_id)?
|
||||||
.set_model(&cx.entity(), &mut cx.to_async()),
|
.set_entity(&cx.entity(), &mut cx.to_async()),
|
||||||
self.client
|
self.client
|
||||||
.subscribe_to_entity(project_id)?
|
.subscribe_to_entity(project_id)?
|
||||||
.set_model(&self.worktree_store, &mut cx.to_async()),
|
.set_entity(&self.worktree_store, &mut cx.to_async()),
|
||||||
self.client
|
self.client
|
||||||
.subscribe_to_entity(project_id)?
|
.subscribe_to_entity(project_id)?
|
||||||
.set_model(&self.buffer_store, &mut cx.to_async()),
|
.set_entity(&self.buffer_store, &mut cx.to_async()),
|
||||||
self.client
|
self.client
|
||||||
.subscribe_to_entity(project_id)?
|
.subscribe_to_entity(project_id)?
|
||||||
.set_model(&self.lsp_store, &mut cx.to_async()),
|
.set_entity(&self.lsp_store, &mut cx.to_async()),
|
||||||
self.client
|
self.client
|
||||||
.subscribe_to_entity(project_id)?
|
.subscribe_to_entity(project_id)?
|
||||||
.set_model(&self.settings_observer, &mut cx.to_async()),
|
.set_entity(&self.settings_observer, &mut cx.to_async()),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
self.buffer_store.update(cx, |buffer_store, cx| {
|
self.buffer_store.update(cx, |buffer_store, cx| {
|
||||||
|
|
|
@ -240,7 +240,7 @@ pub struct SettingsObserver {
|
||||||
/// upstream.
|
/// upstream.
|
||||||
impl SettingsObserver {
|
impl SettingsObserver {
|
||||||
pub fn init(client: &AnyProtoClient) {
|
pub fn init(client: &AnyProtoClient) {
|
||||||
client.add_model_message_handler(Self::handle_update_worktree_settings);
|
client.add_entity_message_handler(Self::handle_update_worktree_settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_local(
|
pub fn new_local(
|
||||||
|
|
|
@ -51,7 +51,7 @@ impl EventEmitter<crate::Event> for TaskStore {}
|
||||||
impl TaskStore {
|
impl TaskStore {
|
||||||
pub fn init(client: Option<&AnyProtoClient>) {
|
pub fn init(client: Option<&AnyProtoClient>) {
|
||||||
if let Some(client) = client {
|
if let Some(client) = client {
|
||||||
client.add_model_request_handler(Self::handle_task_context_for_location);
|
client.add_entity_request_handler(Self::handle_task_context_for_location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,9 +26,9 @@ enum ToolchainStoreInner {
|
||||||
impl EventEmitter<ToolchainStoreEvent> for ToolchainStore {}
|
impl EventEmitter<ToolchainStoreEvent> for ToolchainStore {}
|
||||||
impl ToolchainStore {
|
impl ToolchainStore {
|
||||||
pub fn init(client: &AnyProtoClient) {
|
pub fn init(client: &AnyProtoClient) {
|
||||||
client.add_model_request_handler(Self::handle_activate_toolchain);
|
client.add_entity_request_handler(Self::handle_activate_toolchain);
|
||||||
client.add_model_request_handler(Self::handle_list_toolchains);
|
client.add_entity_request_handler(Self::handle_list_toolchains);
|
||||||
client.add_model_request_handler(Self::handle_active_toolchain);
|
client.add_entity_request_handler(Self::handle_active_toolchain);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn local(
|
pub fn local(
|
||||||
|
@ -37,16 +37,16 @@ impl ToolchainStore {
|
||||||
project_environment: Entity<ProjectEnvironment>,
|
project_environment: Entity<ProjectEnvironment>,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let model = cx.new(|_| LocalToolchainStore {
|
let entity = cx.new(|_| LocalToolchainStore {
|
||||||
languages,
|
languages,
|
||||||
worktree_store,
|
worktree_store,
|
||||||
project_environment,
|
project_environment,
|
||||||
active_toolchains: Default::default(),
|
active_toolchains: Default::default(),
|
||||||
});
|
});
|
||||||
let subscription = cx.subscribe(&model, |_, _, e: &ToolchainStoreEvent, cx| {
|
let subscription = cx.subscribe(&entity, |_, _, e: &ToolchainStoreEvent, cx| {
|
||||||
cx.emit(e.clone())
|
cx.emit(e.clone())
|
||||||
});
|
});
|
||||||
Self(ToolchainStoreInner::Local(model, subscription))
|
Self(ToolchainStoreInner::Local(entity, subscription))
|
||||||
}
|
}
|
||||||
pub(super) fn remote(project_id: u64, client: AnyProtoClient, cx: &mut App) -> Self {
|
pub(super) fn remote(project_id: u64, client: AnyProtoClient, cx: &mut App) -> Self {
|
||||||
Self(ToolchainStoreInner::Remote(
|
Self(ToolchainStoreInner::Remote(
|
||||||
|
|
|
@ -72,13 +72,13 @@ impl EventEmitter<WorktreeStoreEvent> for WorktreeStore {}
|
||||||
|
|
||||||
impl WorktreeStore {
|
impl WorktreeStore {
|
||||||
pub fn init(client: &AnyProtoClient) {
|
pub fn init(client: &AnyProtoClient) {
|
||||||
client.add_model_request_handler(Self::handle_create_project_entry);
|
client.add_entity_request_handler(Self::handle_create_project_entry);
|
||||||
client.add_model_request_handler(Self::handle_copy_project_entry);
|
client.add_entity_request_handler(Self::handle_copy_project_entry);
|
||||||
client.add_model_request_handler(Self::handle_delete_project_entry);
|
client.add_entity_request_handler(Self::handle_delete_project_entry);
|
||||||
client.add_model_request_handler(Self::handle_expand_project_entry);
|
client.add_entity_request_handler(Self::handle_expand_project_entry);
|
||||||
client.add_model_request_handler(Self::handle_expand_all_for_project_entry);
|
client.add_entity_request_handler(Self::handle_expand_all_for_project_entry);
|
||||||
client.add_model_request_handler(Self::handle_git_branches);
|
client.add_entity_request_handler(Self::handle_git_branches);
|
||||||
client.add_model_request_handler(Self::handle_update_branch);
|
client.add_entity_request_handler(Self::handle_update_branch);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn local(retain_worktrees: bool, fs: Arc<dyn Fs>) -> Self {
|
pub fn local(retain_worktrees: bool, fs: Arc<dyn Fs>) -> Self {
|
||||||
|
|
|
@ -445,9 +445,9 @@ impl ProjectPanel {
|
||||||
show_scrollbar: !Self::should_autohide_scrollbar(cx),
|
show_scrollbar: !Self::should_autohide_scrollbar(cx),
|
||||||
hide_scrollbar_task: None,
|
hide_scrollbar_task: None,
|
||||||
vertical_scrollbar_state: ScrollbarState::new(scroll_handle.clone())
|
vertical_scrollbar_state: ScrollbarState::new(scroll_handle.clone())
|
||||||
.parent_model(&cx.entity()),
|
.parent_entity(&cx.entity()),
|
||||||
horizontal_scrollbar_state: ScrollbarState::new(scroll_handle.clone())
|
horizontal_scrollbar_state: ScrollbarState::new(scroll_handle.clone())
|
||||||
.parent_model(&cx.entity()),
|
.parent_entity(&cx.entity()),
|
||||||
max_width_item_index: None,
|
max_width_item_index: None,
|
||||||
diagnostics: Default::default(),
|
diagnostics: Default::default(),
|
||||||
scroll_handle,
|
scroll_handle,
|
||||||
|
|
|
@ -1263,7 +1263,7 @@ impl RemoteServerProjects {
|
||||||
state = new_state.clone();
|
state = new_state.clone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let scroll_state = state.scrollbar.parent_model(&cx.entity());
|
let scroll_state = state.scrollbar.parent_entity(&cx.entity());
|
||||||
let connect_button = div()
|
let connect_button = div()
|
||||||
.id("ssh-connect-new-server-container")
|
.id("ssh-connect-new-server-container")
|
||||||
.track_focus(&state.add_new_server.focus_handle)
|
.track_focus(&state.add_new_server.focus_handle)
|
||||||
|
|
|
@ -185,21 +185,21 @@ impl HeadlessProject {
|
||||||
client.add_request_handler(cx.weak_entity(), Self::handle_shutdown_remote_server);
|
client.add_request_handler(cx.weak_entity(), Self::handle_shutdown_remote_server);
|
||||||
client.add_request_handler(cx.weak_entity(), Self::handle_ping);
|
client.add_request_handler(cx.weak_entity(), Self::handle_ping);
|
||||||
|
|
||||||
client.add_model_request_handler(Self::handle_add_worktree);
|
client.add_entity_request_handler(Self::handle_add_worktree);
|
||||||
client.add_request_handler(cx.weak_entity(), 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_entity_request_handler(Self::handle_open_buffer_by_path);
|
||||||
client.add_model_request_handler(Self::handle_open_new_buffer);
|
client.add_entity_request_handler(Self::handle_open_new_buffer);
|
||||||
client.add_model_request_handler(Self::handle_find_search_candidates);
|
client.add_entity_request_handler(Self::handle_find_search_candidates);
|
||||||
client.add_model_request_handler(Self::handle_open_server_settings);
|
client.add_entity_request_handler(Self::handle_open_server_settings);
|
||||||
|
|
||||||
client.add_model_request_handler(BufferStore::handle_update_buffer);
|
client.add_entity_request_handler(BufferStore::handle_update_buffer);
|
||||||
client.add_model_message_handler(BufferStore::handle_close_buffer);
|
client.add_entity_message_handler(BufferStore::handle_close_buffer);
|
||||||
|
|
||||||
client.add_model_request_handler(Self::handle_stage);
|
client.add_entity_request_handler(Self::handle_stage);
|
||||||
client.add_model_request_handler(Self::handle_unstage);
|
client.add_entity_request_handler(Self::handle_unstage);
|
||||||
client.add_model_request_handler(Self::handle_commit);
|
client.add_entity_request_handler(Self::handle_commit);
|
||||||
client.add_model_request_handler(Self::handle_open_commit_message_buffer);
|
client.add_entity_request_handler(Self::handle_open_commit_message_buffer);
|
||||||
|
|
||||||
client.add_request_handler(
|
client.add_request_handler(
|
||||||
extensions.clone().downgrade(),
|
extensions.clone().downgrade(),
|
||||||
|
|
|
@ -127,7 +127,7 @@ impl Cell {
|
||||||
} => {
|
} => {
|
||||||
let source = source.join("");
|
let source = source.join("");
|
||||||
|
|
||||||
let model = cx.new(|cx| {
|
let entity = cx.new(|cx| {
|
||||||
let markdown_parsing_task = {
|
let markdown_parsing_task = {
|
||||||
let languages = languages.clone();
|
let languages = languages.clone();
|
||||||
let source = source.clone();
|
let source = source.clone();
|
||||||
|
@ -159,7 +159,7 @@ impl Cell {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Cell::Markdown(model)
|
Cell::Markdown(entity)
|
||||||
}
|
}
|
||||||
nbformat::v4::Cell::Code {
|
nbformat::v4::Cell::Code {
|
||||||
id,
|
id,
|
||||||
|
|
|
@ -53,7 +53,7 @@ pub struct ProtoMessageHandlerSet {
|
||||||
pub entity_types_by_message_type: HashMap<TypeId, TypeId>,
|
pub entity_types_by_message_type: HashMap<TypeId, TypeId>,
|
||||||
pub entities_by_type_and_remote_id: HashMap<(TypeId, u64), EntityMessageSubscriber>,
|
pub entities_by_type_and_remote_id: HashMap<(TypeId, u64), EntityMessageSubscriber>,
|
||||||
pub entity_id_extractors: HashMap<TypeId, fn(&dyn AnyTypedEnvelope) -> u64>,
|
pub entity_id_extractors: HashMap<TypeId, fn(&dyn AnyTypedEnvelope) -> u64>,
|
||||||
pub models_by_message_type: HashMap<TypeId, AnyWeakEntity>,
|
pub entities_by_message_type: HashMap<TypeId, AnyWeakEntity>,
|
||||||
pub message_handlers: HashMap<TypeId, ProtoMessageHandler>,
|
pub message_handlers: HashMap<TypeId, ProtoMessageHandler>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ pub type ProtoMessageHandler = Arc<
|
||||||
impl ProtoMessageHandlerSet {
|
impl ProtoMessageHandlerSet {
|
||||||
pub fn clear(&mut self) {
|
pub fn clear(&mut self) {
|
||||||
self.message_handlers.clear();
|
self.message_handlers.clear();
|
||||||
self.models_by_message_type.clear();
|
self.entities_by_message_type.clear();
|
||||||
self.entities_by_type_and_remote_id.clear();
|
self.entities_by_type_and_remote_id.clear();
|
||||||
self.entity_id_extractors.clear();
|
self.entity_id_extractors.clear();
|
||||||
}
|
}
|
||||||
|
@ -79,10 +79,11 @@ impl ProtoMessageHandlerSet {
|
||||||
fn add_message_handler(
|
fn add_message_handler(
|
||||||
&mut self,
|
&mut self,
|
||||||
message_type_id: TypeId,
|
message_type_id: TypeId,
|
||||||
model: gpui::AnyWeakEntity,
|
entity: gpui::AnyWeakEntity,
|
||||||
handler: ProtoMessageHandler,
|
handler: ProtoMessageHandler,
|
||||||
) {
|
) {
|
||||||
self.models_by_message_type.insert(message_type_id, model);
|
self.entities_by_message_type
|
||||||
|
.insert(message_type_id, entity);
|
||||||
let prev_handler = self.message_handlers.insert(message_type_id, handler);
|
let prev_handler = self.message_handlers.insert(message_type_id, handler);
|
||||||
if prev_handler.is_some() {
|
if prev_handler.is_some() {
|
||||||
panic!("registered handler for the same message twice");
|
panic!("registered handler for the same message twice");
|
||||||
|
@ -92,7 +93,7 @@ impl ProtoMessageHandlerSet {
|
||||||
fn add_entity_message_handler(
|
fn add_entity_message_handler(
|
||||||
&mut self,
|
&mut self,
|
||||||
message_type_id: TypeId,
|
message_type_id: TypeId,
|
||||||
model_type_id: TypeId,
|
entity_type_id: TypeId,
|
||||||
entity_id_extractor: fn(&dyn AnyTypedEnvelope) -> u64,
|
entity_id_extractor: fn(&dyn AnyTypedEnvelope) -> u64,
|
||||||
handler: ProtoMessageHandler,
|
handler: ProtoMessageHandler,
|
||||||
) {
|
) {
|
||||||
|
@ -100,7 +101,7 @@ impl ProtoMessageHandlerSet {
|
||||||
.entry(message_type_id)
|
.entry(message_type_id)
|
||||||
.or_insert(entity_id_extractor);
|
.or_insert(entity_id_extractor);
|
||||||
self.entity_types_by_message_type
|
self.entity_types_by_message_type
|
||||||
.insert(message_type_id, model_type_id);
|
.insert(message_type_id, entity_type_id);
|
||||||
let prev_handler = self.message_handlers.insert(message_type_id, handler);
|
let prev_handler = self.message_handlers.insert(message_type_id, handler);
|
||||||
if prev_handler.is_some() {
|
if prev_handler.is_some() {
|
||||||
panic!("registered handler for the same message twice");
|
panic!("registered handler for the same message twice");
|
||||||
|
@ -116,7 +117,7 @@ impl ProtoMessageHandlerSet {
|
||||||
let payload_type_id = message.payload_type_id();
|
let payload_type_id = message.payload_type_id();
|
||||||
let mut this = this.lock();
|
let mut this = this.lock();
|
||||||
let handler = this.message_handlers.get(&payload_type_id)?.clone();
|
let handler = this.message_handlers.get(&payload_type_id)?.clone();
|
||||||
let entity = if let Some(entity) = this.models_by_message_type.get(&payload_type_id) {
|
let entity = if let Some(entity) = this.entities_by_message_type.get(&payload_type_id) {
|
||||||
entity.upgrade()?
|
entity.upgrade()?
|
||||||
} else {
|
} else {
|
||||||
let extract_entity_id = *this.entity_id_extractors.get(&payload_type_id)?;
|
let extract_entity_id = *this.entity_id_extractors.get(&payload_type_id)?;
|
||||||
|
@ -207,7 +208,7 @@ impl AnyProtoClient {
|
||||||
self.0.send(envelope, T::NAME)
|
self.0.send(envelope, T::NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_request_handler<M, E, H, F>(&self, model: gpui::WeakEntity<E>, handler: H)
|
pub fn add_request_handler<M, E, H, F>(&self, entity: gpui::WeakEntity<E>, handler: H)
|
||||||
where
|
where
|
||||||
M: RequestMessage,
|
M: RequestMessage,
|
||||||
E: 'static,
|
E: 'static,
|
||||||
|
@ -216,12 +217,12 @@ impl AnyProtoClient {
|
||||||
{
|
{
|
||||||
self.0.message_handler_set().lock().add_message_handler(
|
self.0.message_handler_set().lock().add_message_handler(
|
||||||
TypeId::of::<M>(),
|
TypeId::of::<M>(),
|
||||||
model.into(),
|
entity.into(),
|
||||||
Arc::new(move |model, envelope, client, cx| {
|
Arc::new(move |entity, envelope, client, cx| {
|
||||||
let model = model.downcast::<E>().unwrap();
|
let entity = entity.downcast::<E>().unwrap();
|
||||||
let envelope = envelope.into_any().downcast::<TypedEnvelope<M>>().unwrap();
|
let envelope = envelope.into_any().downcast::<TypedEnvelope<M>>().unwrap();
|
||||||
let request_id = envelope.message_id();
|
let request_id = envelope.message_id();
|
||||||
handler(model, *envelope, cx)
|
handler(entity, *envelope, cx)
|
||||||
.then(move |result| async move {
|
.then(move |result| async move {
|
||||||
match result {
|
match result {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
|
@ -239,7 +240,7 @@ impl AnyProtoClient {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_model_request_handler<M, E, H, F>(&self, handler: H)
|
pub fn add_entity_request_handler<M, E, H, F>(&self, handler: H)
|
||||||
where
|
where
|
||||||
M: EnvelopedMessage + RequestMessage + EntityMessage,
|
M: EnvelopedMessage + RequestMessage + EntityMessage,
|
||||||
E: 'static,
|
E: 'static,
|
||||||
|
@ -247,7 +248,7 @@ impl AnyProtoClient {
|
||||||
F: 'static + Future<Output = anyhow::Result<M::Response>>,
|
F: 'static + Future<Output = anyhow::Result<M::Response>>,
|
||||||
{
|
{
|
||||||
let message_type_id = TypeId::of::<M>();
|
let message_type_id = TypeId::of::<M>();
|
||||||
let model_type_id = TypeId::of::<E>();
|
let entity_type_id = TypeId::of::<E>();
|
||||||
let entity_id_extractor = |envelope: &dyn AnyTypedEnvelope| {
|
let entity_id_extractor = |envelope: &dyn AnyTypedEnvelope| {
|
||||||
envelope
|
envelope
|
||||||
.as_any()
|
.as_any()
|
||||||
|
@ -261,13 +262,13 @@ impl AnyProtoClient {
|
||||||
.lock()
|
.lock()
|
||||||
.add_entity_message_handler(
|
.add_entity_message_handler(
|
||||||
message_type_id,
|
message_type_id,
|
||||||
model_type_id,
|
entity_type_id,
|
||||||
entity_id_extractor,
|
entity_id_extractor,
|
||||||
Arc::new(move |model, envelope, client, cx| {
|
Arc::new(move |entity, envelope, client, cx| {
|
||||||
let model = model.downcast::<E>().unwrap();
|
let entity = entity.downcast::<E>().unwrap();
|
||||||
let envelope = envelope.into_any().downcast::<TypedEnvelope<M>>().unwrap();
|
let envelope = envelope.into_any().downcast::<TypedEnvelope<M>>().unwrap();
|
||||||
let request_id = envelope.message_id();
|
let request_id = envelope.message_id();
|
||||||
handler(model, *envelope, cx)
|
handler(entity, *envelope, cx)
|
||||||
.then(move |result| async move {
|
.then(move |result| async move {
|
||||||
match result {
|
match result {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
|
@ -285,7 +286,7 @@ impl AnyProtoClient {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_model_message_handler<M, E, H, F>(&self, handler: H)
|
pub fn add_entity_message_handler<M, E, H, F>(&self, handler: H)
|
||||||
where
|
where
|
||||||
M: EnvelopedMessage + EntityMessage,
|
M: EnvelopedMessage + EntityMessage,
|
||||||
E: 'static,
|
E: 'static,
|
||||||
|
@ -293,7 +294,7 @@ impl AnyProtoClient {
|
||||||
F: 'static + Future<Output = anyhow::Result<()>>,
|
F: 'static + Future<Output = anyhow::Result<()>>,
|
||||||
{
|
{
|
||||||
let message_type_id = TypeId::of::<M>();
|
let message_type_id = TypeId::of::<M>();
|
||||||
let model_type_id = TypeId::of::<E>();
|
let entity_type_id = TypeId::of::<E>();
|
||||||
let entity_id_extractor = |envelope: &dyn AnyTypedEnvelope| {
|
let entity_id_extractor = |envelope: &dyn AnyTypedEnvelope| {
|
||||||
envelope
|
envelope
|
||||||
.as_any()
|
.as_any()
|
||||||
|
@ -307,12 +308,12 @@ impl AnyProtoClient {
|
||||||
.lock()
|
.lock()
|
||||||
.add_entity_message_handler(
|
.add_entity_message_handler(
|
||||||
message_type_id,
|
message_type_id,
|
||||||
model_type_id,
|
entity_type_id,
|
||||||
entity_id_extractor,
|
entity_id_extractor,
|
||||||
Arc::new(move |model, envelope, _, cx| {
|
Arc::new(move |entity, envelope, _, cx| {
|
||||||
let model = model.downcast::<E>().unwrap();
|
let entity = entity.downcast::<E>().unwrap();
|
||||||
let envelope = envelope.into_any().downcast::<TypedEnvelope<M>>().unwrap();
|
let envelope = envelope.into_any().downcast::<TypedEnvelope<M>>().unwrap();
|
||||||
handler(model, *envelope, cx).boxed_local()
|
handler(entity, *envelope, cx).boxed_local()
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,7 +154,7 @@ enum InputPanel {
|
||||||
pub struct ProjectSearchView {
|
pub struct ProjectSearchView {
|
||||||
workspace: WeakEntity<Workspace>,
|
workspace: WeakEntity<Workspace>,
|
||||||
focus_handle: FocusHandle,
|
focus_handle: FocusHandle,
|
||||||
model: Entity<ProjectSearch>,
|
entity: Entity<ProjectSearch>,
|
||||||
query_editor: Entity<Editor>,
|
query_editor: Entity<Editor>,
|
||||||
replacement_editor: Entity<Editor>,
|
replacement_editor: Entity<Editor>,
|
||||||
results_editor: Entity<Editor>,
|
results_editor: Entity<Editor>,
|
||||||
|
@ -337,7 +337,7 @@ impl Render for ProjectSearchView {
|
||||||
.track_focus(&self.focus_handle(cx))
|
.track_focus(&self.focus_handle(cx))
|
||||||
.child(self.results_editor.clone())
|
.child(self.results_editor.clone())
|
||||||
} else {
|
} else {
|
||||||
let model = self.model.read(cx);
|
let model = self.entity.read(cx);
|
||||||
let has_no_results = model.no_results.unwrap_or(false);
|
let has_no_results = model.no_results.unwrap_or(false);
|
||||||
let is_search_underway = model.pending_search.is_some();
|
let is_search_underway = model.pending_search.is_some();
|
||||||
|
|
||||||
|
@ -436,7 +436,7 @@ impl Item for ProjectSearchView {
|
||||||
|
|
||||||
fn tab_content_text(&self, _: &Window, cx: &App) -> Option<SharedString> {
|
fn tab_content_text(&self, _: &Window, cx: &App) -> Option<SharedString> {
|
||||||
let last_query: Option<SharedString> = self
|
let last_query: Option<SharedString> = self
|
||||||
.model
|
.entity
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.last_search_query_text
|
.last_search_query_text
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
@ -520,7 +520,7 @@ impl Item for ProjectSearchView {
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
let model = self.model.update(cx, |model, cx| model.clone(cx));
|
let model = self.entity.update(cx, |model, cx| model.clone(cx));
|
||||||
Some(cx.new(|cx| Self::new(self.workspace.clone(), model, window, cx, None)))
|
Some(cx.new(|cx| Self::new(self.workspace.clone(), model, window, cx, None)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -585,14 +585,14 @@ impl Item for ProjectSearchView {
|
||||||
|
|
||||||
impl ProjectSearchView {
|
impl ProjectSearchView {
|
||||||
pub fn get_matches(&self, cx: &App) -> Vec<Range<Anchor>> {
|
pub fn get_matches(&self, cx: &App) -> Vec<Range<Anchor>> {
|
||||||
self.model.read(cx).match_ranges.clone()
|
self.entity.read(cx).match_ranges.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_filters(&mut self, cx: &mut Context<Self>) {
|
fn toggle_filters(&mut self, cx: &mut Context<Self>) {
|
||||||
self.filters_enabled = !self.filters_enabled;
|
self.filters_enabled = !self.filters_enabled;
|
||||||
ActiveSettings::update_global(cx, |settings, cx| {
|
ActiveSettings::update_global(cx, |settings, cx| {
|
||||||
settings.0.insert(
|
settings.0.insert(
|
||||||
self.model.read(cx).project.downgrade(),
|
self.entity.read(cx).project.downgrade(),
|
||||||
self.current_settings(),
|
self.current_settings(),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -609,7 +609,7 @@ impl ProjectSearchView {
|
||||||
self.search_options.toggle(option);
|
self.search_options.toggle(option);
|
||||||
ActiveSettings::update_global(cx, |settings, cx| {
|
ActiveSettings::update_global(cx, |settings, cx| {
|
||||||
settings.0.insert(
|
settings.0.insert(
|
||||||
self.model.read(cx).project.downgrade(),
|
self.entity.read(cx).project.downgrade(),
|
||||||
self.current_settings(),
|
self.current_settings(),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -620,19 +620,19 @@ impl ProjectSearchView {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn replace_next(&mut self, _: &ReplaceNext, window: &mut Window, cx: &mut Context<Self>) {
|
fn replace_next(&mut self, _: &ReplaceNext, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
if self.model.read(cx).match_ranges.is_empty() {
|
if self.entity.read(cx).match_ranges.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let Some(active_index) = self.active_match_index else {
|
let Some(active_index) = self.active_match_index else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let query = self.model.read(cx).active_query.clone();
|
let query = self.entity.read(cx).active_query.clone();
|
||||||
if let Some(query) = query {
|
if let Some(query) = query {
|
||||||
let query = query.with_replacement(self.replacement(cx));
|
let query = query.with_replacement(self.replacement(cx));
|
||||||
|
|
||||||
// TODO: Do we need the clone here?
|
// TODO: Do we need the clone here?
|
||||||
let mat = self.model.read(cx).match_ranges[active_index].clone();
|
let mat = self.entity.read(cx).match_ranges[active_index].clone();
|
||||||
self.results_editor.update(cx, |editor, cx| {
|
self.results_editor.update(cx, |editor, cx| {
|
||||||
editor.replace(&mat, &query, window, cx);
|
editor.replace(&mat, &query, window, cx);
|
||||||
});
|
});
|
||||||
|
@ -647,13 +647,13 @@ impl ProjectSearchView {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let Some(query) = self.model.read(cx).active_query.as_ref() else {
|
let Some(query) = self.entity.read(cx).active_query.as_ref() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let query = query.clone().with_replacement(self.replacement(cx));
|
let query = query.clone().with_replacement(self.replacement(cx));
|
||||||
|
|
||||||
let match_ranges = self
|
let match_ranges = self
|
||||||
.model
|
.entity
|
||||||
.update(cx, |model, _| mem::take(&mut model.match_ranges));
|
.update(cx, |model, _| mem::take(&mut model.match_ranges));
|
||||||
if match_ranges.is_empty() {
|
if match_ranges.is_empty() {
|
||||||
return;
|
return;
|
||||||
|
@ -663,14 +663,14 @@ impl ProjectSearchView {
|
||||||
editor.replace_all(&mut match_ranges.iter(), &query, window, cx);
|
editor.replace_all(&mut match_ranges.iter(), &query, window, cx);
|
||||||
});
|
});
|
||||||
|
|
||||||
self.model.update(cx, |model, _cx| {
|
self.entity.update(cx, |model, _cx| {
|
||||||
model.match_ranges = match_ranges;
|
model.match_ranges = match_ranges;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(
|
pub fn new(
|
||||||
workspace: WeakEntity<Workspace>,
|
workspace: WeakEntity<Workspace>,
|
||||||
model: Entity<ProjectSearch>,
|
entity: Entity<ProjectSearch>,
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
settings: Option<ProjectSearchSettings>,
|
settings: Option<ProjectSearchSettings>,
|
||||||
|
@ -691,17 +691,17 @@ impl ProjectSearchView {
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
let model = model.read(cx);
|
let entity = entity.read(cx);
|
||||||
project = model.project.clone();
|
project = entity.project.clone();
|
||||||
excerpts = model.excerpts.clone();
|
excerpts = entity.excerpts.clone();
|
||||||
if let Some(active_query) = model.active_query.as_ref() {
|
if let Some(active_query) = entity.active_query.as_ref() {
|
||||||
query_text = active_query.as_str().to_string();
|
query_text = active_query.as_str().to_string();
|
||||||
replacement_text = active_query.replacement().map(ToOwned::to_owned);
|
replacement_text = active_query.replacement().map(ToOwned::to_owned);
|
||||||
options = SearchOptions::from_query(active_query);
|
options = SearchOptions::from_query(active_query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
subscriptions.push(cx.observe_in(&model, window, |this, _, window, cx| {
|
subscriptions.push(cx.observe_in(&entity, window, |this, _, window, cx| {
|
||||||
this.model_changed(window, cx)
|
this.entity_changed(window, cx)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let query_editor = cx.new(|cx| {
|
let query_editor = cx.new(|cx| {
|
||||||
|
@ -796,8 +796,8 @@ impl ProjectSearchView {
|
||||||
workspace,
|
workspace,
|
||||||
focus_handle,
|
focus_handle,
|
||||||
replacement_editor,
|
replacement_editor,
|
||||||
search_id: model.read(cx).search_id,
|
search_id: entity.read(cx).search_id,
|
||||||
model,
|
entity,
|
||||||
query_editor,
|
query_editor,
|
||||||
results_editor,
|
results_editor,
|
||||||
search_options: options,
|
search_options: options,
|
||||||
|
@ -810,7 +810,7 @@ impl ProjectSearchView {
|
||||||
included_opened_only: false,
|
included_opened_only: false,
|
||||||
_subscriptions: subscriptions,
|
_subscriptions: subscriptions,
|
||||||
};
|
};
|
||||||
this.model_changed(window, cx);
|
this.entity_changed(window, cx);
|
||||||
this
|
this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -826,8 +826,8 @@ impl ProjectSearchView {
|
||||||
|
|
||||||
let weak_workspace = cx.entity().downgrade();
|
let weak_workspace = cx.entity().downgrade();
|
||||||
|
|
||||||
let model = cx.new(|cx| ProjectSearch::new(workspace.project().clone(), cx));
|
let entity = cx.new(|cx| ProjectSearch::new(workspace.project().clone(), cx));
|
||||||
let search = cx.new(|cx| ProjectSearchView::new(weak_workspace, model, window, cx, None));
|
let search = cx.new(|cx| ProjectSearchView::new(weak_workspace, entity, window, cx, None));
|
||||||
workspace.add_item_to_active_pane(Box::new(search.clone()), None, true, window, cx);
|
workspace.add_item_to_active_pane(Box::new(search.clone()), None, true, window, cx);
|
||||||
search.update(cx, |search, cx| {
|
search.update(cx, |search, cx| {
|
||||||
search
|
search
|
||||||
|
@ -868,7 +868,7 @@ impl ProjectSearchView {
|
||||||
let new_query = search_view.update(cx, |search_view, cx| {
|
let new_query = search_view.update(cx, |search_view, cx| {
|
||||||
let new_query = search_view.build_search_query(cx);
|
let new_query = search_view.build_search_query(cx);
|
||||||
if new_query.is_some() {
|
if new_query.is_some() {
|
||||||
if let Some(old_query) = search_view.model.read(cx).active_query.clone() {
|
if let Some(old_query) = search_view.entity.read(cx).active_query.clone() {
|
||||||
search_view.query_editor.update(cx, |editor, cx| {
|
search_view.query_editor.update(cx, |editor, cx| {
|
||||||
editor.set_text(old_query.as_str(), window, cx);
|
editor.set_text(old_query.as_str(), window, cx);
|
||||||
});
|
});
|
||||||
|
@ -878,18 +878,16 @@ impl ProjectSearchView {
|
||||||
new_query
|
new_query
|
||||||
});
|
});
|
||||||
if let Some(new_query) = new_query {
|
if let Some(new_query) = new_query {
|
||||||
let model = cx.new(|cx| {
|
let entity = cx.new(|cx| {
|
||||||
let mut model = ProjectSearch::new(workspace.project().clone(), cx);
|
let mut entity = ProjectSearch::new(workspace.project().clone(), cx);
|
||||||
model.search(new_query, cx);
|
entity.search(new_query, cx);
|
||||||
model
|
entity
|
||||||
});
|
});
|
||||||
let weak_workspace = cx.entity().downgrade();
|
let weak_workspace = cx.entity().downgrade();
|
||||||
workspace.add_item_to_active_pane(
|
workspace.add_item_to_active_pane(
|
||||||
Box::new(
|
Box::new(cx.new(|cx| {
|
||||||
cx.new(|cx| {
|
ProjectSearchView::new(weak_workspace, entity, window, cx, None)
|
||||||
ProjectSearchView::new(weak_workspace, model, window, cx, None)
|
})),
|
||||||
}),
|
|
||||||
),
|
|
||||||
None,
|
None,
|
||||||
true,
|
true,
|
||||||
window,
|
window,
|
||||||
|
@ -969,7 +967,7 @@ impl ProjectSearchView {
|
||||||
|
|
||||||
fn search(&mut self, cx: &mut Context<Self>) {
|
fn search(&mut self, cx: &mut Context<Self>) {
|
||||||
if let Some(query) = self.build_search_query(cx) {
|
if let Some(query) = self.build_search_query(cx) {
|
||||||
self.model.update(cx, |model, cx| model.search(query, cx));
|
self.entity.update(cx, |model, cx| model.search(query, cx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1111,7 +1109,7 @@ impl ProjectSearchView {
|
||||||
|
|
||||||
fn select_match(&mut self, direction: Direction, window: &mut Window, cx: &mut Context<Self>) {
|
fn select_match(&mut self, direction: Direction, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
if let Some(index) = self.active_match_index {
|
if let Some(index) = self.active_match_index {
|
||||||
let match_ranges = self.model.read(cx).match_ranges.clone();
|
let match_ranges = self.entity.read(cx).match_ranges.clone();
|
||||||
|
|
||||||
if !EditorSettings::get_global(cx).search_wrap
|
if !EditorSettings::get_global(cx).search_wrap
|
||||||
&& ((direction == Direction::Next && index + 1 >= match_ranges.len())
|
&& ((direction == Direction::Next && index + 1 >= match_ranges.len())
|
||||||
|
@ -1182,14 +1180,14 @@ impl ProjectSearchView {
|
||||||
window.focus(&results_handle);
|
window.focus(&results_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn model_changed(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
fn entity_changed(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
let match_ranges = self.model.read(cx).match_ranges.clone();
|
let match_ranges = self.entity.read(cx).match_ranges.clone();
|
||||||
if match_ranges.is_empty() {
|
if match_ranges.is_empty() {
|
||||||
self.active_match_index = None;
|
self.active_match_index = None;
|
||||||
} else {
|
} else {
|
||||||
self.active_match_index = Some(0);
|
self.active_match_index = Some(0);
|
||||||
self.update_match_index(cx);
|
self.update_match_index(cx);
|
||||||
let prev_search_id = mem::replace(&mut self.search_id, self.model.read(cx).search_id);
|
let prev_search_id = mem::replace(&mut self.search_id, self.entity.read(cx).search_id);
|
||||||
let is_new_search = self.search_id != prev_search_id;
|
let is_new_search = self.search_id != prev_search_id;
|
||||||
self.results_editor.update(cx, |editor, cx| {
|
self.results_editor.update(cx, |editor, cx| {
|
||||||
if is_new_search {
|
if is_new_search {
|
||||||
|
@ -1219,7 +1217,7 @@ impl ProjectSearchView {
|
||||||
fn update_match_index(&mut self, cx: &mut Context<Self>) {
|
fn update_match_index(&mut self, cx: &mut Context<Self>) {
|
||||||
let results_editor = self.results_editor.read(cx);
|
let results_editor = self.results_editor.read(cx);
|
||||||
let new_index = active_match_index(
|
let new_index = active_match_index(
|
||||||
&self.model.read(cx).match_ranges,
|
&self.entity.read(cx).match_ranges,
|
||||||
&results_editor.selections.newest_anchor().head(),
|
&results_editor.selections.newest_anchor().head(),
|
||||||
&results_editor.buffer().read(cx).snapshot(cx),
|
&results_editor.buffer().read(cx).snapshot(cx),
|
||||||
);
|
);
|
||||||
|
@ -1324,7 +1322,7 @@ impl ProjectSearchView {
|
||||||
|
|
||||||
fn move_focus_to_results(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
fn move_focus_to_results(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
if !self.results_editor.focus_handle(cx).is_focused(window)
|
if !self.results_editor.focus_handle(cx).is_focused(window)
|
||||||
&& !self.model.read(cx).match_ranges.is_empty()
|
&& !self.entity.read(cx).match_ranges.is_empty()
|
||||||
{
|
{
|
||||||
cx.stop_propagation();
|
cx.stop_propagation();
|
||||||
self.focus_results_editor(window, cx)
|
self.focus_results_editor(window, cx)
|
||||||
|
@ -1454,7 +1452,7 @@ impl ProjectSearchBar {
|
||||||
if let Some(search_view) = self.active_project_search.as_ref() {
|
if let Some(search_view) = self.active_project_search.as_ref() {
|
||||||
search_view.update(cx, |search_view, cx| {
|
search_view.update(cx, |search_view, cx| {
|
||||||
search_view.toggle_search_option(option, cx);
|
search_view.toggle_search_option(option, cx);
|
||||||
if search_view.model.read(cx).active_query.is_some() {
|
if search_view.entity.read(cx).active_query.is_some() {
|
||||||
search_view.search(cx);
|
search_view.search(cx);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1505,7 +1503,7 @@ impl ProjectSearchBar {
|
||||||
if let Some(search_view) = self.active_project_search.as_ref() {
|
if let Some(search_view) = self.active_project_search.as_ref() {
|
||||||
search_view.update(cx, |search_view, cx| {
|
search_view.update(cx, |search_view, cx| {
|
||||||
search_view.toggle_opened_only(window, cx);
|
search_view.toggle_opened_only(window, cx);
|
||||||
if search_view.model.read(cx).active_query.is_some() {
|
if search_view.entity.read(cx).active_query.is_some() {
|
||||||
search_view.search(cx);
|
search_view.search(cx);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1562,7 +1560,7 @@ impl ProjectSearchBar {
|
||||||
),
|
),
|
||||||
] {
|
] {
|
||||||
if editor.focus_handle(cx).is_focused(window) {
|
if editor.focus_handle(cx).is_focused(window) {
|
||||||
let new_query = search_view.model.update(cx, |model, cx| {
|
let new_query = search_view.entity.update(cx, |model, cx| {
|
||||||
let project = model.project.clone();
|
let project = model.project.clone();
|
||||||
|
|
||||||
if let Some(new_query) = project.update(cx, |project, _| {
|
if let Some(new_query) = project.update(cx, |project, _| {
|
||||||
|
@ -1606,12 +1604,12 @@ impl ProjectSearchBar {
|
||||||
if editor.focus_handle(cx).is_focused(window) {
|
if editor.focus_handle(cx).is_focused(window) {
|
||||||
if editor.read(cx).text(cx).is_empty() {
|
if editor.read(cx).text(cx).is_empty() {
|
||||||
if let Some(new_query) = search_view
|
if let Some(new_query) = search_view
|
||||||
.model
|
.entity
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.project
|
.project
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.search_history(kind)
|
.search_history(kind)
|
||||||
.current(search_view.model.read(cx).cursor(kind))
|
.current(search_view.entity.read(cx).cursor(kind))
|
||||||
.map(str::to_string)
|
.map(str::to_string)
|
||||||
{
|
{
|
||||||
search_view.set_search_editor(kind, &new_query, window, cx);
|
search_view.set_search_editor(kind, &new_query, window, cx);
|
||||||
|
@ -1619,7 +1617,7 @@ impl ProjectSearchBar {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(new_query) = search_view.model.update(cx, |model, cx| {
|
if let Some(new_query) = search_view.entity.update(cx, |model, cx| {
|
||||||
let project = model.project.clone();
|
let project = model.project.clone();
|
||||||
project.update(cx, |project, _| {
|
project.update(cx, |project, _| {
|
||||||
project
|
project
|
||||||
|
@ -1806,13 +1804,13 @@ impl Render for ProjectSearchBar {
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
let limit_reached = search.model.read(cx).limit_reached;
|
let limit_reached = search.entity.read(cx).limit_reached;
|
||||||
|
|
||||||
let match_text = search
|
let match_text = search
|
||||||
.active_match_index
|
.active_match_index
|
||||||
.and_then(|index| {
|
.and_then(|index| {
|
||||||
let index = index + 1;
|
let index = index + 1;
|
||||||
let match_quantity = search.model.read(cx).match_ranges.len();
|
let match_quantity = search.entity.read(cx).match_ranges.len();
|
||||||
if match_quantity > 0 {
|
if match_quantity > 0 {
|
||||||
debug_assert!(match_quantity >= index);
|
debug_assert!(match_quantity >= index);
|
||||||
if limit_reached {
|
if limit_reached {
|
||||||
|
|
|
@ -47,14 +47,14 @@ pub struct IndentGuides {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn indent_guides<V: Render>(
|
pub fn indent_guides<V: Render>(
|
||||||
model: Entity<V>,
|
entity: Entity<V>,
|
||||||
indent_size: Pixels,
|
indent_size: Pixels,
|
||||||
colors: IndentGuideColors,
|
colors: IndentGuideColors,
|
||||||
compute_indents_fn: impl Fn(&mut V, Range<usize>, &mut Window, &mut Context<V>) -> SmallVec<[usize; 64]>
|
compute_indents_fn: impl Fn(&mut V, Range<usize>, &mut Window, &mut Context<V>) -> SmallVec<[usize; 64]>
|
||||||
+ 'static,
|
+ 'static,
|
||||||
) -> IndentGuides {
|
) -> IndentGuides {
|
||||||
let compute_indents_fn = Box::new(move |range, window: &mut Window, cx: &mut App| {
|
let compute_indents_fn = Box::new(move |range, window: &mut Window, cx: &mut App| {
|
||||||
model.update(cx, |this, cx| compute_indents_fn(this, range, window, cx))
|
entity.update(cx, |this, cx| compute_indents_fn(this, range, window, cx))
|
||||||
});
|
});
|
||||||
IndentGuides {
|
IndentGuides {
|
||||||
colors,
|
colors,
|
||||||
|
@ -78,7 +78,7 @@ impl IndentGuides {
|
||||||
/// Sets a custom callback that will be called when the indent guides need to be rendered.
|
/// Sets a custom callback that will be called when the indent guides need to be rendered.
|
||||||
pub fn with_render_fn<V: Render>(
|
pub fn with_render_fn<V: Render>(
|
||||||
mut self,
|
mut self,
|
||||||
model: Entity<V>,
|
entity: Entity<V>,
|
||||||
render_fn: impl Fn(
|
render_fn: impl Fn(
|
||||||
&mut V,
|
&mut V,
|
||||||
RenderIndentGuideParams,
|
RenderIndentGuideParams,
|
||||||
|
@ -88,7 +88,7 @@ impl IndentGuides {
|
||||||
+ 'static,
|
+ 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let render_fn = move |params, window: &mut Window, cx: &mut App| {
|
let render_fn = move |params, window: &mut Window, cx: &mut App| {
|
||||||
model.update(cx, |this, cx| render_fn(this, params, window, cx))
|
entity.update(cx, |this, cx| render_fn(this, params, window, cx))
|
||||||
};
|
};
|
||||||
self.render_fn = Some(Box::new(render_fn));
|
self.render_fn = Some(Box::new(render_fn));
|
||||||
self
|
self
|
||||||
|
|
|
@ -114,7 +114,7 @@ impl ScrollbarState {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set a parent model which should be notified whenever this Scrollbar gets a scroll event.
|
/// Set a parent model which should be notified whenever this Scrollbar gets a scroll event.
|
||||||
pub fn parent_model<V: 'static>(mut self, v: &Entity<V>) -> Self {
|
pub fn parent_entity<V: 'static>(mut self, v: &Entity<V>) -> Self {
|
||||||
self.parent_id = Some(v.entity_id());
|
self.parent_id = Some(v.entity_id());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,14 +95,14 @@ impl VimTestContext {
|
||||||
Self { cx }
|
Self { cx }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_entity<F, T, R>(&mut self, model: Entity<T>, update: F) -> R
|
pub fn update_entity<F, T, R>(&mut self, entity: Entity<T>, update: F) -> R
|
||||||
where
|
where
|
||||||
T: 'static,
|
T: 'static,
|
||||||
F: FnOnce(&mut T, &mut Window, &mut Context<T>) -> R + 'static,
|
F: FnOnce(&mut T, &mut Window, &mut Context<T>) -> R + 'static,
|
||||||
{
|
{
|
||||||
let window = self.window;
|
let window = self.window;
|
||||||
self.update_window(window, move |_, window, cx| {
|
self.update_window(window, move |_, window, cx| {
|
||||||
model.update(cx, |t, cx| update(t, window, cx))
|
entity.update(cx, |t, cx| update(t, window, cx))
|
||||||
})
|
})
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,7 @@ impl VimTestContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mode(&mut self) -> Mode {
|
pub fn mode(&mut self) -> Mode {
|
||||||
self.update_editor(|editor, _, cx| editor.addon::<VimAddon>().unwrap().model.read(cx).mode)
|
self.update_editor(|editor, _, cx| editor.addon::<VimAddon>().unwrap().entity.read(cx).mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn active_operator(&mut self) -> Option<Operator> {
|
pub fn active_operator(&mut self) -> Option<Operator> {
|
||||||
|
@ -139,7 +139,7 @@ impl VimTestContext {
|
||||||
editor
|
editor
|
||||||
.addon::<VimAddon>()
|
.addon::<VimAddon>()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.model
|
.entity
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.operator_stack
|
.operator_stack
|
||||||
.last()
|
.last()
|
||||||
|
@ -153,7 +153,7 @@ impl VimTestContext {
|
||||||
self.update_editor(|editor, _window, _cx| editor.addon::<VimAddon>().cloned().unwrap());
|
self.update_editor(|editor, _window, _cx| editor.addon::<VimAddon>().cloned().unwrap());
|
||||||
|
|
||||||
self.update(|window, cx| {
|
self.update(|window, cx| {
|
||||||
vim.model.update(cx, |vim, cx| {
|
vim.entity.update(cx, |vim, cx| {
|
||||||
vim.switch_mode(mode, true, window, cx);
|
vim.switch_mode(mode, true, window, cx);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -173,7 +173,7 @@ pub fn init(cx: &mut App) {
|
||||||
.and_then(|item| item.act_as::<Editor>(cx))
|
.and_then(|item| item.act_as::<Editor>(cx))
|
||||||
.and_then(|editor| editor.read(cx).addon::<VimAddon>().cloned());
|
.and_then(|editor| editor.read(cx).addon::<VimAddon>().cloned());
|
||||||
let Some(vim) = vim else { return };
|
let Some(vim) = vim else { return };
|
||||||
vim.model.update(cx, |_, cx| {
|
vim.entity.update(cx, |_, cx| {
|
||||||
cx.defer_in(window, |vim, window, cx| vim.search_submit(window, cx))
|
cx.defer_in(window, |vim, window, cx| vim.search_submit(window, cx))
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
@ -183,12 +183,12 @@ pub fn init(cx: &mut App) {
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(crate) struct VimAddon {
|
pub(crate) struct VimAddon {
|
||||||
pub(crate) model: Entity<Vim>,
|
pub(crate) entity: Entity<Vim>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl editor::Addon for VimAddon {
|
impl editor::Addon for VimAddon {
|
||||||
fn extend_key_context(&self, key_context: &mut KeyContext, cx: &App) {
|
fn extend_key_context(&self, key_context: &mut KeyContext, cx: &App) {
|
||||||
self.model.read(cx).extend_key_context(key_context, cx)
|
self.entity.read(cx).extend_key_context(key_context, cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_any(&self) -> &dyn std::any::Any {
|
fn to_any(&self) -> &dyn std::any::Any {
|
||||||
|
@ -298,7 +298,7 @@ impl Vim {
|
||||||
if toggle {
|
if toggle {
|
||||||
let is_relative = editor
|
let is_relative = editor
|
||||||
.addon::<VimAddon>()
|
.addon::<VimAddon>()
|
||||||
.map(|vim| vim.model.read(cx).mode != Mode::Insert);
|
.map(|vim| vim.entity.read(cx).mode != Mode::Insert);
|
||||||
editor.set_relative_line_number(is_relative, cx)
|
editor.set_relative_line_number(is_relative, cx)
|
||||||
} else {
|
} else {
|
||||||
editor.set_relative_line_number(None, cx)
|
editor.set_relative_line_number(None, cx)
|
||||||
|
@ -324,7 +324,9 @@ impl Vim {
|
||||||
fn activate(editor: &mut Editor, window: &mut Window, cx: &mut Context<Editor>) {
|
fn activate(editor: &mut Editor, window: &mut Window, cx: &mut Context<Editor>) {
|
||||||
let vim = Vim::new(window, cx);
|
let vim = Vim::new(window, cx);
|
||||||
|
|
||||||
editor.register_addon(VimAddon { model: vim.clone() });
|
editor.register_addon(VimAddon {
|
||||||
|
entity: vim.clone(),
|
||||||
|
});
|
||||||
|
|
||||||
vim.update(cx, |_, cx| {
|
vim.update(cx, |_, cx| {
|
||||||
Vim::action(editor, cx, |vim, action: &SwitchMode, window, cx| {
|
Vim::action(editor, cx, |vim, action: &SwitchMode, window, cx| {
|
||||||
|
|
|
@ -1504,8 +1504,8 @@ pub mod test {
|
||||||
_window: &mut Window,
|
_window: &mut Window,
|
||||||
cx: &mut App,
|
cx: &mut App,
|
||||||
) -> Task<anyhow::Result<Entity<Self>>> {
|
) -> Task<anyhow::Result<Entity<Self>>> {
|
||||||
let model = cx.new(|cx| Self::new_deserialized(workspace_id, cx));
|
let entity = cx.new(|cx| Self::new_deserialized(workspace_id, cx));
|
||||||
Task::ready(Ok(model))
|
Task::ready(Ok(entity))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cleanup(
|
fn cleanup(
|
||||||
|
|
|
@ -2540,8 +2540,10 @@ impl Pane {
|
||||||
let navigate_backward = IconButton::new("navigate_backward", IconName::ArrowLeft)
|
let navigate_backward = IconButton::new("navigate_backward", IconName::ArrowLeft)
|
||||||
.icon_size(IconSize::Small)
|
.icon_size(IconSize::Small)
|
||||||
.on_click({
|
.on_click({
|
||||||
let model = cx.entity().clone();
|
let entity = cx.entity().clone();
|
||||||
move |_, window, cx| model.update(cx, |pane, cx| pane.navigate_backward(window, cx))
|
move |_, window, cx| {
|
||||||
|
entity.update(cx, |pane, cx| pane.navigate_backward(window, cx))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.disabled(!self.can_navigate_backward())
|
.disabled(!self.can_navigate_backward())
|
||||||
.tooltip({
|
.tooltip({
|
||||||
|
@ -2554,8 +2556,8 @@ impl Pane {
|
||||||
let navigate_forward = IconButton::new("navigate_forward", IconName::ArrowRight)
|
let navigate_forward = IconButton::new("navigate_forward", IconName::ArrowRight)
|
||||||
.icon_size(IconSize::Small)
|
.icon_size(IconSize::Small)
|
||||||
.on_click({
|
.on_click({
|
||||||
let model = cx.entity().clone();
|
let entity = cx.entity().clone();
|
||||||
move |_, window, cx| model.update(cx, |pane, cx| pane.navigate_forward(window, cx))
|
move |_, window, cx| entity.update(cx, |pane, cx| pane.navigate_forward(window, cx))
|
||||||
})
|
})
|
||||||
.disabled(!self.can_navigate_forward())
|
.disabled(!self.can_navigate_forward())
|
||||||
.tooltip({
|
.tooltip({
|
||||||
|
|
|
@ -230,9 +230,9 @@ impl Zeta {
|
||||||
cx: &mut App,
|
cx: &mut App,
|
||||||
) -> Entity<Self> {
|
) -> Entity<Self> {
|
||||||
let this = Self::global(cx).unwrap_or_else(|| {
|
let this = Self::global(cx).unwrap_or_else(|| {
|
||||||
let model = cx.new(|cx| Self::new(client, user_store, cx));
|
let entity = cx.new(|cx| Self::new(client, user_store, cx));
|
||||||
cx.set_global(ZetaGlobal(model.clone()));
|
cx.set_global(ZetaGlobal(entity.clone()));
|
||||||
model
|
entity
|
||||||
});
|
});
|
||||||
|
|
||||||
this.update(cx, move |this, cx| {
|
this.update(cx, move |this, cx| {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue