Remove ReadView and UpdateView traits

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra 2023-04-24 17:36:14 +02:00
parent a6115d9330
commit c165fb9be5
12 changed files with 160 additions and 183 deletions

View file

@ -428,7 +428,7 @@ mod tests {
path::PathBuf,
};
use gpui::{AppContext, TestAppContext, UpdateView, View, ViewContext};
use gpui::{AppContext, BorrowWindowContext, TestAppContext, ViewContext, WindowContext};
use project::{FakeFs, Project};
use settings::Settings;
@ -660,7 +660,7 @@ mod tests {
pub fn workspace<F, T>(&self, read: F) -> T
where
F: FnOnce(&Workspace, &AppContext) -> T,
F: FnOnce(&Workspace, &ViewContext<Workspace>) -> T,
{
self.workspace.read_with(self.cx, read)
}
@ -810,18 +810,15 @@ mod tests {
}
}
impl<'a> UpdateView for DockTestContext<'a> {
type Output<S> = S;
impl BorrowWindowContext for DockTestContext<'_> {
type ReturnValue<T> = T;
fn update_view<T, S>(
&mut self,
handle: &ViewHandle<T>,
update: &mut dyn FnMut(&mut T, &mut ViewContext<T>) -> S,
) -> S
where
T: View,
{
handle.update(self.cx, update)
fn read_with<T, F: FnOnce(&WindowContext) -> T>(&self, window_id: usize, f: F) -> T {
BorrowWindowContext::read_with(self.cx, window_id, f)
}
fn update<T, F: FnOnce(&mut WindowContext) -> T>(&mut self, window_id: usize, f: F) -> T {
BorrowWindowContext::update(self.cx, window_id, f)
}
}
}

View file

@ -981,7 +981,7 @@ impl Pane {
// was started.
let (item_ix, mut project_item_ids) = pane.read_with(&cx, |pane, cx| {
(pane.index_for_item(&*item), item.project_item_model_ids(cx))
});
})?;
let item_ix = if let Some(ix) = item_ix {
ix
} else {
@ -1001,7 +1001,7 @@ impl Pane {
project_item_ids.retain(|id| !other_project_item_ids.contains(id));
}
}
});
})?;
let should_save = project_item_ids
.iter()
.any(|id| saved_project_items_ids.insert(*id));

View file

@ -140,7 +140,10 @@ impl SerializedPaneGroup {
.await
.log_err()?;
if pane.read_with(cx, |pane, _| pane.items_len() != 0) {
if pane
.read_with(cx, |pane, _| pane.items_len() != 0)
.log_err()?
{
Some((Member::Pane(pane.clone()), active.then(|| pane)))
} else {
workspace

View file

@ -1226,7 +1226,7 @@ impl Workspace {
cx.read(|cx| (item.is_singleton(cx), item.project_entry_ids(cx)));
if singleton || !project_entry_ids.is_empty() {
if let Some(ix) =
pane.read_with(&cx, |pane, _| pane.index_for_item(item.as_ref()))
pane.read_with(&cx, |pane, _| pane.index_for_item(item.as_ref()))?
{
if !Pane::save_item(
project.clone(),
@ -2298,7 +2298,7 @@ impl Workspace {
this.read_with(&cx, |this, _| {
this.leader_updates_tx
.unbounded_send((leader_id, envelope.payload))
})?;
})??;
Ok(())
}
@ -2354,7 +2354,7 @@ impl Workspace {
.flat_map(|states_by_pane| states_by_pane.keys())
.cloned()
.collect()
});
})?;
Self::add_views_from_leader(this.clone(), leader_id, panes, vec![view], cx).await?;
}
}
@ -2369,7 +2369,7 @@ impl Workspace {
views: Vec<proto::View>,
cx: &mut AsyncAppContext,
) -> Result<()> {
let project = this.read_with(cx, |this, _| this.project.clone());
let project = this.read_with(cx, |this, _| this.project.clone())?;
let replica_id = project
.read_with(cx, |project, _| {
project
@ -2699,7 +2699,7 @@ impl Workspace {
workspace.dock_pane().clone(),
workspace.last_active_center_pane.clone(),
)
});
})?;
serialized_workspace
.dock_pane
@ -2765,7 +2765,7 @@ impl Workspace {
})?;
// Serialize ourself to make sure our timestamps and any pane / item changes are replicated
workspace.read_with(&cx, |workspace, cx| workspace.serialize_workspace(cx))
workspace.read_with(&cx, |workspace, cx| workspace.serialize_workspace(cx))?
}
anyhow::Ok(())
})