diff --git a/src/main.rs b/src/main.rs index 25858e0..15f71fe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,14 +20,16 @@ use std::{any::TypeId, env, fs, path::PathBuf, process}; use config::{AppTheme, Config, CONFIG_VERSION}; mod config; +mod localize; + mod menu; mod mouse_area; -mod localize; - mod mime_icon; +mod operation; + use tab::{Location, Tab}; mod tab; diff --git a/src/operation.rs b/src/operation.rs new file mode 100644 index 0000000..1842ef9 --- /dev/null +++ b/src/operation.rs @@ -0,0 +1,57 @@ +use std::path::PathBuf; + +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum Operation { + /// Move a path to the trash + Delete { path: PathBuf }, + /// Rename a path + Rename { old: PathBuf, new: PathBuf }, + /// Restore a path from the trash + Restore { path: PathBuf }, +} + +impl Operation { + pub fn delete(path: impl Into) -> Self { + Self::Delete { path: path.into() } + } + + pub fn rename(old: impl Into, new: impl Into) -> Self { + Self::Rename { + old: old.into(), + new: new.into(), + } + } + + pub fn restore(path: impl Into) -> Self { + Self::Restore { path: path.into() } + } + + pub fn reverse(self) -> Self { + match self { + Self::Delete { path } => Self::Restore { path }, + Self::Rename { old, new } => Self::Rename { old: new, new: old }, + Self::Restore { path } => Self::Delete { path }, + } + } +} + +#[cfg(test)] +mod tests { + use super::Operation; + + #[test] + fn operation() { + assert_eq!( + Operation::delete("foo").reverse(), + Operation::restore("foo") + ); + assert_eq!( + Operation::rename("foo", "bar").reverse(), + Operation::rename("bar", "foo") + ); + assert_eq!( + Operation::restore("foo").reverse(), + Operation::delete("foo") + ); + } +}