Replace app/app_mut on contexts with AsRef/AsMut impls

Co-Authored-By: Brooks Swinnerton <934497+bswinnerton@users.noreply.github.com>
This commit is contained in:
Nathan Sobo
2021-04-13 20:07:25 -06:00
co-authored by Brooks Swinnerton
parent 7469240a2e
commit 0a2d2aa684
10 changed files with 95 additions and 77 deletions
+2 -2
View File
@@ -51,8 +51,8 @@ fn open_paths(params: &OpenParams, app: &mut MutableAppContext) {
for window_id in app.window_ids().collect::<Vec<_>>() {
if let Some(handle) = app.root_view::<WorkspaceView>(window_id) {
if handle.update(app, |view, ctx| {
if view.contains_paths(&params.paths, ctx.app()) {
view.open_paths(&params.paths, ctx.app_mut());
if view.contains_paths(&params.paths, ctx.as_ref()) {
view.open_paths(&params.paths, ctx.as_mut());
log::info!("open paths on existing workspace");
true
} else {
+4 -5
View File
@@ -110,11 +110,10 @@ impl Pane {
entry_id: (usize, usize),
ctx: &mut ViewContext<Self>,
) -> bool {
if let Some(index) = self
.items
.iter()
.position(|item| item.entry_id(ctx.app()).map_or(false, |id| id == entry_id))
{
if let Some(index) = self.items.iter().position(|item| {
item.entry_id(ctx.as_ref())
.map_or(false, |id| id == entry_id)
}) {
self.activate_item(index, ctx);
true
} else {
+2 -2
View File
@@ -153,8 +153,8 @@ impl Workspace {
.ok_or(anyhow!("worktree {} does not exist", entry.0,))?;
let replica_id = self.replica_id;
let file = worktree.file(entry.1, ctx.app())?;
let history = file.load_history(ctx.app());
let file = worktree.file(entry.1, ctx.as_ref())?;
let history = file.load_history(ctx.as_ref());
let buffer = async move { Ok(Buffer::from_history(replica_id, file, history.await?)) };
let (mut tx, rx) = watch::channel(None);
+5 -5
View File
@@ -214,7 +214,7 @@ impl WorkspaceView {
me.loading_entries.remove(&entry);
match item {
Ok(item) => {
let item_view = item.add_view(ctx.window_id(), settings, ctx.app_mut());
let item_view = item.add_view(ctx.window_id(), settings, ctx.as_mut());
me.add_item(item_view, ctx);
}
Err(error) => {
@@ -243,7 +243,7 @@ impl WorkspaceView {
pub fn save_active_item(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
self.active_pane.update(ctx, |pane, ctx| {
if let Some(item) = pane.active_item() {
let task = item.save(ctx.app_mut());
let task = item.save(ctx.as_mut());
ctx.spawn(task, |_, result, _| {
if let Err(e) = result {
// TODO - present this error to the user
@@ -258,7 +258,7 @@ impl WorkspaceView {
pub fn debug_elements(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
match to_string_pretty(&ctx.debug_elements()) {
Ok(json) => {
ctx.app_mut().copy(&json);
ctx.as_mut().copy(&json);
log::info!(
"copied {:.1} KiB of element debug JSON to the clipboard",
json.len() as f32 / 1024.
@@ -323,7 +323,7 @@ impl WorkspaceView {
let new_pane = self.add_pane(ctx);
self.activate_pane(new_pane.clone(), ctx);
if let Some(item) = pane.read(ctx).active_item() {
if let Some(clone) = item.clone_on_split(ctx.app_mut()) {
if let Some(clone) = item.clone_on_split(ctx.as_mut()) {
self.add_item(clone, ctx);
}
}
@@ -351,7 +351,7 @@ impl WorkspaceView {
fn add_item(&self, item: Box<dyn ItemViewHandle>, ctx: &mut ViewContext<Self>) {
let active_pane = self.active_pane();
item.set_parent_pane(&active_pane, ctx.app_mut());
item.set_parent_pane(&active_pane, ctx.as_mut());
active_pane.update(ctx, |pane, ctx| {
let item_idx = pane.add_item(item, ctx);
pane.activate_item(item_idx, ctx);