From 84f183ab845ec2e96ade590fdad1a62f63161874 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Sun, 6 Apr 2025 19:13:25 +0300 Subject: [PATCH] remove Task, count changes explicitly --- src/keys/quit.rs | 2 +- src/keys/save.rs | 12 +++++++++--- src/model.rs | 19 ++++++++----------- src/model/column.rs | 4 ++-- src/model/task.rs | 20 -------------------- src/view/dialog.rs | 4 ++-- src/view/status.rs | 2 +- 7 files changed, 23 insertions(+), 40 deletions(-) delete mode 100644 src/model/task.rs diff --git a/src/keys/quit.rs b/src/keys/quit.rs index ffd680e..0420993 100644 --- a/src/keys/quit.rs +++ b/src/keys/quit.rs @@ -20,7 +20,7 @@ impl Taggart { } } pub fn quit_begin (&mut self, input: &TuiIn) { - if self.tasks.len() == 0 { + if self.changes == 0 { input.done() } else { self.mode = Some(Mode::Quit { choice: 1 }) diff --git a/src/keys/save.rs b/src/keys/save.rs index fdfeb90..c1e1688 100644 --- a/src/keys/save.rs +++ b/src/keys/save.rs @@ -11,8 +11,14 @@ impl Taggart { choice: (choice + 1) % 3 }) }, press!(Enter) => match choice { - 0 => { self.tasks = vec![]; self.mode = None; }, - 1 => { self.mode = None }, + 0 => { + todo!("clear modified_tag"); + //self.tasks = vec![]; + self.mode = None; + }, + 1 => { + self.mode = None + }, 2 => todo!(), _ => unreachable!(), }, @@ -20,7 +26,7 @@ impl Taggart { } } pub fn save_begin (&mut self) { - if self.tasks.len() > 0 { + if self.changes > 0 { self.mode = Some(Mode::Save { choice: 1 }) } } diff --git a/src/model.rs b/src/model.rs index e9abd41..bacdc41 100644 --- a/src/model.rs +++ b/src/model.rs @@ -2,7 +2,6 @@ use crate::*; mod column; pub use self::column::*; mod entry; pub use self::entry::*; -mod task; pub use self::task::*; /// The application state. pub struct Taggart { @@ -13,11 +12,10 @@ pub struct Taggart { pub column: usize, pub columns: ColumnsOption>, fn(&mut Self, usize, &str)>, pub display: Measure, - pub tasks: Vec, /// State of modal dialog of editing field pub mode: Option, - /// Count of modified items - pub modified: usize, + /// Count of changes to items + pub changes: usize, } #[derive(Debug)] @@ -38,9 +36,8 @@ impl Taggart { display: Measure::new(), mode: None, columns: Columns::default(), - tasks: vec![], entries, - modified: 0 + changes: 0 }) } /// Make sure cursor is always in view @@ -62,14 +59,14 @@ impl Taggart { } } /// Count modified entries - pub(crate) fn count_modified (&mut self) -> usize { - let mut modified = 0; + pub(crate) fn count_changes (&mut self) -> usize { + let mut changes = 0; for entry in self.entries.iter() { if entry.is_modified() { - modified += 1; + changes += 1; } } - self.modified = modified; - self.modified + self.changes = changes; + self.changes } } diff --git a/src/model/column.rs b/src/model/column.rs index 1cfc5fb..57c8c9f 100644 --- a/src/model/column.rs +++ b/src/model/column.rs @@ -69,7 +69,7 @@ macro_rules! setter { if let Some(entries) = entries_under(&mut state.entries, index) { for (_path, entry) in entries.into_iter() { if entry.write().unwrap().$set(&value) { - state.count_modified(); + state.count_changes(); //state.tasks.retain(|t|{(t.path != p) || (t.item.key() != item.key())}); //state.tasks.push(Task { path: p, item, }); }; @@ -77,7 +77,7 @@ macro_rules! setter { } else if let Some(entry) = state.entries.get_mut(index) { //let p = entry.path.clone(); if entry.$set(&value) { - state.count_modified(); + state.count_changes(); //state.tasks.retain(|t|{(t.path != p) || (t.item.key() != item.key())}); //state.tasks.push(Task { path: p, item, }); }; diff --git a/src/model/task.rs b/src/model/task.rs deleted file mode 100644 index 5aa27df..0000000 --- a/src/model/task.rs +++ /dev/null @@ -1,20 +0,0 @@ -use crate::*; -use lofty::tag::TagItem; - -/// An update to a file's metadata to be performed. -pub struct Task { - pub path: Arc, - pub item: TagItem -} - -impl Task { - fn new (path: &impl AsRef, item: TagItem) -> Self { - Self { - path: path.as_ref().to_path_buf().into(), - item - } - } - fn apply (&self) -> Usually<()> { - todo!("apply {:?} to {:?}", self.item, self.path) - } -} diff --git a/src/view/dialog.rs b/src/view/dialog.rs index ba10821..9ea0cac 100644 --- a/src/view/dialog.rs +++ b/src/view/dialog.rs @@ -23,7 +23,7 @@ impl Taggart { if choice == 2 { "[ Write and continue ]" } else { " Write and continue " }, ]; Self::dialog(Bsp::s( - format!("Save {} change(s)?", self.tasks.len()), + format!("Save {} change(s)?", self.changes), Bsp::s("", Bsp::e(choices[0], Bsp::e(choices[1], choices[2]))))) } fn dialog_quit (&self, choice: u8) -> impl Content { @@ -33,7 +33,7 @@ impl Taggart { if choice == 2 { "[ Write and exit ]" } else { " Write and exit " }, ]; Self::dialog(Bsp::s( - format!("Save {} change(s) before exiting?", self.tasks.len()), + format!("Save {} change(s) before exiting?", self.changes), Bsp::s("", Bsp::e(choices[0], Bsp::e(choices[1], choices[2]))))) } pub fn render_dialog (&self, to: &mut TuiOut) { diff --git a/src/view/status.rs b/src/view/status.rs index 67cc834..55b8e89 100644 --- a/src/view/status.rs +++ b/src/view/status.rs @@ -32,7 +32,7 @@ impl Taggart { ))), Fill::x(Align::e(format!( " {} unsaved changes ", - self.modified + self.changes ))) ) )