Replace the old worktree with the new one

This commit is contained in:
Nathan Sobo
2021-04-15 21:02:30 -06:00
parent 5648c67d54
commit 358fad8242
11 changed files with 105 additions and 1456 deletions
+5 -7
View File
@@ -4,7 +4,7 @@ use crate::{
settings::Settings,
time::ReplicaId,
watch,
worktree_old::{Worktree, WorktreeHandle as _},
worktree::{Worktree, WorktreeHandle as _},
};
use anyhow::anyhow;
use gpui::{AppContext, Entity, Handle, ModelContext, ModelHandle, MutableAppContext, ViewContext};
@@ -117,7 +117,7 @@ impl Workspace {
}
}
let worktree = ctx.add_model(|ctx| Worktree::new(ctx.model_id(), path, ctx));
let worktree = ctx.add_model(|ctx| Worktree::new(path, ctx));
ctx.observe(&worktree, Self::on_worktree_updated);
self.worktrees.insert(worktree);
ctx.notify();
@@ -211,9 +211,7 @@ impl WorkspaceHandle for ModelHandle<Workspace> {
.iter()
.flat_map(|tree| {
let tree_id = tree.id();
tree.read(app)
.files()
.map(move |file| (tree_id, file.entry_id))
tree.read(app).files().map(move |inode| (tree_id, inode))
})
.collect::<Vec<_>>()
}
@@ -241,8 +239,8 @@ mod tests {
// Get the first file entry.
let tree = app.read(|ctx| workspace.read(ctx).worktrees.iter().next().unwrap().clone());
let entry_id = app.read(|ctx| tree.read(ctx).files().next().unwrap().entry_id);
let entry = (tree.id(), entry_id);
let file_inode = app.read(|ctx| tree.read(ctx).files().next().unwrap());
let entry = (tree.id(), file_inode);
// Open the same entry twice before it finishes loading.
let (future_1, future_2) = workspace.update(&mut app, |w, app| {
+1 -14
View File
@@ -5,7 +5,7 @@ use gpui::{
color::rgbu, elements::*, json::to_string_pretty, keymap::Binding, AnyViewHandle, AppContext,
ClipboardItem, Entity, ModelHandle, MutableAppContext, View, ViewContext, ViewHandle,
};
use log::{error, info};
use log::error;
use std::{collections::HashSet, path::PathBuf};
pub fn init(app: &mut MutableAppContext) {
@@ -227,19 +227,6 @@ impl WorkspaceView {
}
}
pub fn open_example_entry(&mut self, ctx: &mut ViewContext<Self>) {
if let Some(tree) = self.workspace.read(ctx).worktrees().iter().next() {
if let Some(file) = tree.read(ctx).files().next() {
info!("open_entry ({}, {})", tree.id(), file.entry_id);
self.open_entry((tree.id(), file.entry_id), ctx);
} else {
error!("No example file found for worktree {}", tree.id());
}
} else {
error!("No worktree found while opening example entry");
}
}
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() {