mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-06 01:26:43 +01:00
remove Task, count changes explicitly
This commit is contained in:
parent
4de94beafb
commit
84f183ab84
7 changed files with 23 additions and 40 deletions
|
|
@ -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 })
|
||||
|
|
|
|||
|
|
@ -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 })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
19
src/model.rs
19
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: Columns<fn(&Entry)->Option<Arc<str>>, fn(&mut Self, usize, &str)>,
|
||||
pub display: Measure<TuiOut>,
|
||||
pub tasks: Vec<Task>,
|
||||
/// State of modal dialog of editing field
|
||||
pub mode: Option<Mode>,
|
||||
/// 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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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, });
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
@ -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<TuiOut> {
|
||||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ impl Taggart {
|
|||
))),
|
||||
Fill::x(Align::e(format!(
|
||||
" {} unsaved changes ",
|
||||
self.modified
|
||||
self.changes
|
||||
)))
|
||||
)
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue