Implement TUI search and mutation workflows
This commit is contained in:
@@ -84,6 +84,7 @@ impl TreeCommitter for NoGitTreeCommitter {
|
||||
pub struct MutationOutcome {
|
||||
action: MutationAction,
|
||||
entries: Vec<EntryPath>,
|
||||
selection: Option<MutationSelection>,
|
||||
}
|
||||
|
||||
impl MutationOutcome {
|
||||
@@ -93,6 +94,35 @@ impl MutationOutcome {
|
||||
pub fn entries(&self) -> &[EntryPath] {
|
||||
&self.entries
|
||||
}
|
||||
pub fn selection(&self) -> Option<&MutationSelection> {
|
||||
self.selection.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub enum MutationSelection {
|
||||
Entry(EntryPath),
|
||||
Directory(DirectoryPath),
|
||||
}
|
||||
|
||||
impl MutationSelection {
|
||||
pub fn path(&self) -> &std::path::Path {
|
||||
match self {
|
||||
Self::Entry(path) => path.as_path(),
|
||||
Self::Directory(path) => path.as_path(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_directory(&self) -> bool {
|
||||
matches!(self, Self::Directory(_))
|
||||
}
|
||||
|
||||
pub fn display_path(&self) -> String {
|
||||
match self {
|
||||
Self::Entry(path) => path.to_string(),
|
||||
Self::Directory(path) => path.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TreeMutator<'a> {
|
||||
@@ -172,6 +202,7 @@ impl<'a> TreeMutator<'a> {
|
||||
Ok(MutationOutcome {
|
||||
action: MutationAction::Remove,
|
||||
entries: entries.into_iter().map(|entry| entry.source).collect(),
|
||||
selection: None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -507,9 +538,14 @@ impl<'a> TreeMutator<'a> {
|
||||
if moving {
|
||||
self.repository.cleanup_empty_directories(&source_root)?;
|
||||
}
|
||||
let selection = destination_entry.map_or_else(
|
||||
|| MutationSelection::Directory(destination_root),
|
||||
MutationSelection::Entry,
|
||||
);
|
||||
Ok(MutationOutcome {
|
||||
action,
|
||||
entries: entries.into_iter().map(|entry| entry.destination).collect(),
|
||||
selection: Some(selection),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user