add clear_changes

This commit is contained in:
🪞👃🪞 2025-04-06 19:46:01 +03:00
parent 36423fc994
commit 38f97558a7
3 changed files with 25 additions and 17 deletions

View file

@ -12,8 +12,7 @@ impl Taggart {
}) }, }) },
press!(Enter) => match choice { press!(Enter) => match choice {
0 => { 0 => {
todo!("clear modified_tag"); self.clear_changes();
//self.tasks = vec![];
self.mode = None; self.mode = None;
}, },
1 => { 1 => {

View file

@ -69,4 +69,15 @@ impl Taggart {
self.changes = changes; self.changes = changes;
self.changes self.changes
} }
/// Clear all modified tags.
pub(crate) fn clear_changes (&mut self) {
for entry in self.entries.iter_mut() {
if let Metadata::Music {
modified_tag, ..
} = &mut *entry.info.write().unwrap() {
*modified_tag = None;
}
}
self.changes = 0;
}
} }

View file

@ -200,21 +200,6 @@ macro_rules! generated_field {
} }
} }
} }
generated_field!(hash = |self|match self {
Metadata::Image { hash, .. } => Some(hash.clone()),
Metadata::Music { hash, .. } => Some(hash.clone()),
Metadata::Unknown { hash, .. } => Some(hash.clone()),
_ => None
});
generated_field!(size = |self|match self {
Metadata::Image { size, .. } => Some(size.clone()),
Metadata::Music { size, .. } => Some(size.clone()),
Metadata::Unknown { size, .. } => Some(size.clone()),
_ => None
});
macro_rules! music_tag_field { macro_rules! music_tag_field {
(string: $get:ident $set:ident $del:ident $key:expr) => { (string: $get:ident $set:ident $del:ident $key:expr) => {
impl Entry { impl Entry {
@ -334,6 +319,19 @@ macro_rules! music_tag_field {
}; };
} }
generated_field!(hash = |self|match self {
Metadata::Image { hash, .. } => Some(hash.clone()),
Metadata::Music { hash, .. } => Some(hash.clone()),
Metadata::Unknown { hash, .. } => Some(hash.clone()),
_ => None
});
generated_field!(size = |self|match self {
Metadata::Image { size, .. } => Some(size.clone()),
Metadata::Music { size, .. } => Some(size.clone()),
Metadata::Unknown { size, .. } => Some(size.clone()),
_ => None
});
music_tag_field!(string: artist set_artist remove_artist ItemKey::TrackArtist); music_tag_field!(string: artist set_artist remove_artist ItemKey::TrackArtist);
music_tag_field!(number: year set_year remove_year ItemKey::Year); music_tag_field!(number: year set_year remove_year ItemKey::Year);
music_tag_field!(string: album set_album remove_album ItemKey::AlbumTitle); music_tag_field!(string: album set_album remove_album ItemKey::AlbumTitle);