use std::path::Path;
use crate::config::NonRustInclusion;
use crate::project::RootItem;
use crate::scan;
use crate::scan::MetadataDispatchContext;
use crate::tui::panes::Panes;
use crate::tui::project_list::ProjectList;
pub struct TreeMutation<'a> {
pub projects: &'a mut ProjectList,
pub panes: &'a mut Panes,
pub non_rust: NonRustInclusion,
}
impl TreeMutation<'_> {
pub fn replace_all(&mut self, projects: ProjectList) {
self.projects.replace_roots_from(projects);
}
pub fn insert_into_hierarchy(
&mut self,
item: RootItem,
dispatch: &MetadataDispatchContext,
) -> bool {
let roots = scan::cargo_metadata_roots_for_item(&item);
let changed = self.projects.insert_into_hierarchy(item);
for root in roots {
scan::spawn_cargo_metadata_refresh(dispatch.clone(), root);
}
changed
}
pub fn replace_leaf_by_path(
&mut self,
path: &Path,
item: RootItem,
dispatch: &MetadataDispatchContext,
) -> Option<RootItem> {
let roots = scan::cargo_metadata_roots_for_item(&item);
let previous = self.projects.replace_leaf_by_path(path, item);
for root in roots {
scan::spawn_cargo_metadata_refresh(dispatch.clone(), root);
}
previous
}
pub fn regroup_members(&mut self, inline_dirs: &[String]) {
self.projects.regroup_members(inline_dirs);
}
pub fn regroup_top_level_worktrees(&mut self) { self.projects.regroup_top_level_worktrees(); }
}
impl Drop for TreeMutation<'_> {
fn drop(&mut self) {
self.panes.clear_for_tree_change();
self.projects
.recompute_visibility(self.non_rust.includes_non_rust());
}
}