remove Task, count changes explicitly

This commit is contained in:
🪞👃🪞 2025-04-06 19:13:25 +03:00
parent 4de94beafb
commit 84f183ab84
7 changed files with 23 additions and 40 deletions

View file

@ -20,7 +20,7 @@ impl Taggart {
} }
} }
pub fn quit_begin (&mut self, input: &TuiIn) { pub fn quit_begin (&mut self, input: &TuiIn) {
if self.tasks.len() == 0 { if self.changes == 0 {
input.done() input.done()
} else { } else {
self.mode = Some(Mode::Quit { choice: 1 }) self.mode = Some(Mode::Quit { choice: 1 })

View file

@ -11,8 +11,14 @@ impl Taggart {
choice: (choice + 1) % 3 choice: (choice + 1) % 3
}) }, }) },
press!(Enter) => match choice { press!(Enter) => match choice {
0 => { self.tasks = vec![]; self.mode = None; }, 0 => {
1 => { self.mode = None }, todo!("clear modified_tag");
//self.tasks = vec![];
self.mode = None;
},
1 => {
self.mode = None
},
2 => todo!(), 2 => todo!(),
_ => unreachable!(), _ => unreachable!(),
}, },
@ -20,7 +26,7 @@ impl Taggart {
} }
} }
pub fn save_begin (&mut self) { pub fn save_begin (&mut self) {
if self.tasks.len() > 0 { if self.changes > 0 {
self.mode = Some(Mode::Save { choice: 1 }) self.mode = Some(Mode::Save { choice: 1 })
} }
} }

View file

@ -2,7 +2,6 @@ use crate::*;
mod column; pub use self::column::*; mod column; pub use self::column::*;
mod entry; pub use self::entry::*; mod entry; pub use self::entry::*;
mod task; pub use self::task::*;
/// The application state. /// The application state.
pub struct Taggart { pub struct Taggart {
@ -13,11 +12,10 @@ pub struct Taggart {
pub column: usize, pub column: usize,
pub columns: Columns<fn(&Entry)->Option<Arc<str>>, fn(&mut Self, usize, &str)>, pub columns: Columns<fn(&Entry)->Option<Arc<str>>, fn(&mut Self, usize, &str)>,
pub display: Measure<TuiOut>, pub display: Measure<TuiOut>,
pub tasks: Vec<Task>,
/// State of modal dialog of editing field /// State of modal dialog of editing field
pub mode: Option<Mode>, pub mode: Option<Mode>,
/// Count of modified items /// Count of changes to items
pub modified: usize, pub changes: usize,
} }
#[derive(Debug)] #[derive(Debug)]
@ -38,9 +36,8 @@ impl Taggart {
display: Measure::new(), display: Measure::new(),
mode: None, mode: None,
columns: Columns::default(), columns: Columns::default(),
tasks: vec![],
entries, entries,
modified: 0 changes: 0
}) })
} }
/// Make sure cursor is always in view /// Make sure cursor is always in view
@ -62,14 +59,14 @@ impl Taggart {
} }
} }
/// Count modified entries /// Count modified entries
pub(crate) fn count_modified (&mut self) -> usize { pub(crate) fn count_changes (&mut self) -> usize {
let mut modified = 0; let mut changes = 0;
for entry in self.entries.iter() { for entry in self.entries.iter() {
if entry.is_modified() { if entry.is_modified() {
modified += 1; changes += 1;
} }
} }
self.modified = modified; self.changes = changes;
self.modified self.changes
} }
} }

View file

@ -69,7 +69,7 @@ macro_rules! setter {
if let Some(entries) = entries_under(&mut state.entries, index) { if let Some(entries) = entries_under(&mut state.entries, index) {
for (_path, entry) in entries.into_iter() { for (_path, entry) in entries.into_iter() {
if entry.write().unwrap().$set(&value) { 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.retain(|t|{(t.path != p) || (t.item.key() != item.key())});
//state.tasks.push(Task { path: p, item, }); //state.tasks.push(Task { path: p, item, });
}; };
@ -77,7 +77,7 @@ macro_rules! setter {
} else if let Some(entry) = state.entries.get_mut(index) { } else if let Some(entry) = state.entries.get_mut(index) {
//let p = entry.path.clone(); //let p = entry.path.clone();
if entry.$set(&value) { if entry.$set(&value) {
state.count_modified(); state.count_changes();
//state.tasks.retain(|t|{(t.path != p) || (t.item.key() != item.key())}); //state.tasks.retain(|t|{(t.path != p) || (t.item.key() != item.key())});
//state.tasks.push(Task { path: p, item, }); //state.tasks.push(Task { path: p, item, });
}; };

View file

@ -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<PathBuf>,
pub item: TagItem
}
impl Task {
fn new (path: &impl AsRef<Path>, item: TagItem) -> Self {
Self {
path: path.as_ref().to_path_buf().into(),
item
}
}
fn apply (&self) -> Usually<()> {
todo!("apply {:?} to {:?}", self.item, self.path)
}
}

View file

@ -23,7 +23,7 @@ impl Taggart {
if choice == 2 { "[ Write and continue ]" } else { " Write and continue " }, if choice == 2 { "[ Write and continue ]" } else { " Write and continue " },
]; ];
Self::dialog(Bsp::s( 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]))))) Bsp::s("", Bsp::e(choices[0], Bsp::e(choices[1], choices[2])))))
} }
fn dialog_quit (&self, choice: u8) -> impl Content<TuiOut> { fn dialog_quit (&self, choice: u8) -> impl Content<TuiOut> {
@ -33,7 +33,7 @@ impl Taggart {
if choice == 2 { "[ Write and exit ]" } else { " Write and exit " }, if choice == 2 { "[ Write and exit ]" } else { " Write and exit " },
]; ];
Self::dialog(Bsp::s( 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]))))) Bsp::s("", Bsp::e(choices[0], Bsp::e(choices[1], choices[2])))))
} }
pub fn render_dialog (&self, to: &mut TuiOut) { pub fn render_dialog (&self, to: &mut TuiOut) {

View file

@ -32,7 +32,7 @@ impl Taggart {
))), ))),
Fill::x(Align::e(format!( Fill::x(Align::e(format!(
" {} unsaved changes ", " {} unsaved changes ",
self.modified self.changes
))) )))
) )
) )