Open annotated versions if they exist
This commit is contained in:
parent
182675d14e
commit
d7379a2a9f
17
src/sheet.rs
17
src/sheet.rs
@ -1,10 +1,12 @@
|
||||
use std::{
|
||||
cmp::Ordering,
|
||||
ffi::OsStr,
|
||||
fs,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use log::debug;
|
||||
use strum_macros::{EnumDiscriminants, EnumIter};
|
||||
|
||||
pub trait PdfSheet {
|
||||
@ -49,10 +51,19 @@ impl Ord for Sheet {
|
||||
}
|
||||
|
||||
impl Sheet {
|
||||
pub fn open_file(&self) {
|
||||
pub fn open_file_or_annotated_version_if_exists(&self) {
|
||||
let path = &self.pdf.path;
|
||||
// TODO: open on first_page
|
||||
opener::open(path).unwrap();
|
||||
|
||||
let mut annotated_path = path.with_extension("").into_os_string();
|
||||
annotated_path.push("_annotated.pdf");
|
||||
let annotated_version = Path::new(&annotated_path);
|
||||
if annotated_version.exists() {
|
||||
// TODO: open on first_page
|
||||
opener::open(annotated_version).unwrap();
|
||||
} else {
|
||||
// TODO: open on first_page
|
||||
opener::open(path).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_part_of_book(&self) -> bool {
|
||||
|
@ -64,6 +64,16 @@ fn validate_sheet_files(sheets: Vec<Sheet>, dir: impl AsRef<Path>) -> FileValida
|
||||
|
||||
// TODO: improve performance?
|
||||
for pdf_file in find_all_pdfs_in_directory_recursive(dir) {
|
||||
// Make sure annotated files are not handled (they are then only opened if existent)
|
||||
if pdf_file
|
||||
.file_name()
|
||||
.unwrap()
|
||||
.to_string_lossy()
|
||||
.ends_with("_annotated.pdf")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Some((i, _)) = invalidated_sheets
|
||||
.iter()
|
||||
.enumerate()
|
||||
|
@ -175,7 +175,7 @@ impl AsyncComponent for AppModel {
|
||||
.forward(sender.input_sender(), |_| todo!()),
|
||||
);
|
||||
} else {
|
||||
sheet.open_file();
|
||||
sheet.open_file_or_annotated_version_if_exists();
|
||||
let mut sheet = sheet;
|
||||
sheet.last_opened = I64DateTime(Utc::now());
|
||||
sheet_dao::update_sheet_last_opened(&self.database, &sheet)
|
||||
|
Loading…
x
Reference in New Issue
Block a user