use std::collections::HashSet;
use super::ExpandKey;
use super::ProjectList;
use crate::config::NonRustInclusion;
use crate::tui::app::FinderState;
#[allow(
dead_code,
reason = "guard ships alongside ProjectList so the type is in place \
while call sites still use the direct accessors"
)]
pub struct SelectionMutation<'a> {
pub(super) project_list: &'a mut ProjectList,
pub(super) non_rust: NonRustInclusion,
}
#[allow(
dead_code,
reason = "guard methods ship alongside the type while call sites \
still use the direct accessors"
)]
impl SelectionMutation<'_> {
pub(super) fn toggle_expand(&mut self, key: ExpandKey) -> bool {
if self.project_list.expanded.contains(&key) {
self.project_list.expanded.remove(&key);
false
} else {
self.project_list.expanded.insert(key);
true
}
}
pub(super) fn expand(&mut self, key: ExpandKey) -> bool {
self.project_list.expanded.insert(key)
}
pub(super) fn collapse(&mut self, key: &ExpandKey) -> bool {
self.project_list.expanded.remove(key)
}
pub(super) const fn expanded_mut(&mut self) -> &mut HashSet<ExpandKey> {
&mut self.project_list.expanded
}
pub(super) const fn finder_mut(&mut self) -> &mut FinderState { &mut self.project_list.finder }
}
impl Drop for SelectionMutation<'_> {
fn drop(&mut self) {
self.project_list
.recompute_visibility(self.non_rust.includes_non_rust());
}
}