Compare commits

..

No commits in common. "e2015392193867f4f7c85442ceacaf726b253da0" and "182675d14ea4b7831ccfe1e3c801a32c97e25cb0" have entirely different histories.

5 changed files with 36 additions and 102 deletions

View File

@ -54,10 +54,7 @@
buildInputs =
with pkgs;
[
gtk4
xournalpp # not needed for building
]
[ gtk4 ]
++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
# Additional darwin specific inputs can be set here
pkgs.libiconv

View File

@ -3,7 +3,7 @@ base_resource_path = "/org/gtkrs/"
# List of icon names you found (shipped with this crate)
# Note: the file ending `-symbolic.svg` isn't part of the icon name.
icons = ["refresh", "edit", "arrow-sort-regular", "playlist-shuffle", "user-trash", "open-filled", "document-settings-filled"]
icons = ["refresh", "edit", "arrow-sort-regular", "playlist-shuffle", "user-trash"]
# Optional: Specify a folder containing your own SVG icons
# icon_folder = "my_svg_icons"

View File

@ -1,12 +1,10 @@
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 {
@ -51,27 +49,10 @@ impl Ord for Sheet {
}
impl Sheet {
pub fn construct_xopp_file_path(&self) -> PathBuf {
let mut xopp_path = self.pdf.path.with_extension("").into_os_string();
xopp_path.push(".xopp");
PathBuf::from(xopp_path)
}
pub fn construct_annotated_file_path(&self) -> PathBuf {
let mut annotated_path = self.pdf.path.with_extension("").into_os_string();
annotated_path.push("_annotated.pdf");
PathBuf::from(annotated_path)
}
pub fn open_file_or_annotated_version_if_exists(&self) {
let annotated_version = self.construct_annotated_file_path();
if annotated_version.exists() {
pub fn open_file(&self) {
let path = &self.pdf.path;
// TODO: open on first_page
opener::open(annotated_version).unwrap();
} else {
// TODO: open on first_page
opener::open(&self.pdf.path).unwrap();
}
opener::open(path).unwrap();
}
pub fn is_part_of_book(&self) -> bool {

View File

@ -64,16 +64,6 @@ 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()

View File

@ -1,4 +1,4 @@
use std::{path::PathBuf, process::Command, sync::Arc};
use std::{path::PathBuf, sync::Arc};
use chrono::Utc;
use gtk::prelude::*;
@ -11,7 +11,7 @@ use relm4::{
use relm4_icons::icon_names;
use crate::{
database::{self, Database},
database::Database,
sheet::{I64DateTime, Sheet},
sheet_dao, sheet_validation,
ui::mcdu::McduOutput,
@ -28,18 +28,11 @@ pub struct AppModel {
directory: Arc<PathBuf>,
mcdu: Controller<McduModel>,
sheets_listing: Controller<SheetListingModel>,
click_mode: ClickMode,
edit_mode: bool,
scroll_adjustment: Adjustment,
sheet_edit_dialog: Option<AsyncController<SheetEditDialogModel>>,
}
#[derive(Debug)]
pub enum ClickMode {
Open,
Edit,
Annotate,
}
#[derive(Debug)]
pub enum AppInput {
SearchStarted(String),
@ -47,7 +40,7 @@ pub enum AppInput {
Refresh,
Sort,
Shuffle,
SetClickMode(ClickMode),
SetEditMode(bool),
SheetListingContentsChanged,
}
@ -85,6 +78,11 @@ impl AsyncComponent for AppModel {
set_margin_end: 10,
connect_clicked[sender] => move |_| sender.input(AppInput::Refresh),
},
gtk::ToggleButton {
set_icon_name: icon_names::EDIT,
set_margin_end: 10,
connect_clicked[sender] => move |button| sender.input(AppInput::SetEditMode(button.is_active())),
},
#[name = "button_sort"]
gtk::ToggleButton {
set_icon_name: icon_names::ARROW_SORT_REGULAR,
@ -94,25 +92,8 @@ impl AsyncComponent for AppModel {
gtk::ToggleButton {
set_icon_name: icon_names::PLAYLIST_SHUFFLE,
set_group: Some(&button_sort),
set_margin_end: 10,
connect_clicked[sender] => move |_| sender.input(AppInput::Shuffle),
},
#[name = "button_open"]
gtk::ToggleButton {
set_icon_name: icon_names::OPEN_FILLED,
set_active: true,
connect_clicked[sender] => move |button| if button.is_active() { sender.input(AppInput::SetClickMode(ClickMode::Open)) },
},
gtk::ToggleButton {
set_icon_name: icon_names::DOCUMENT_SETTINGS_FILLED,
set_group: Some(&button_open),
connect_clicked[sender] => move |button| if button.is_active() { sender.input(AppInput::SetClickMode(ClickMode::Edit)) },
},
gtk::ToggleButton {
set_icon_name: icon_names::EDIT,
set_group: Some(&button_open),
connect_clicked[sender] => move |button| if button.is_active() { sender.input(AppInput::SetClickMode(ClickMode::Annotate)) },
},
},
gtk::ScrolledWindow {
model.sheets_listing.widget(),
@ -134,12 +115,10 @@ impl AsyncComponent for AppModel {
sender: AsyncComponentSender<Self>,
) -> AsyncComponentParts<Self> {
relm4_icons::initialize_icons();
gtk::init().unwrap();
let display = gdk::Display::default().unwrap();
let theme = gtk::IconTheme::for_display(&display);
theme.add_resource_path("/org/gtkrs/icons/");
// theme.add_resource_path("/org/gtkrs/icons/scalable/actions/");
theme.add_resource_path("/org/gtkrs/icons/scalable/actions/");
let mcdu = McduModel::builder()
.launch(())
@ -163,7 +142,7 @@ impl AsyncComponent for AppModel {
directory: Arc::new(init_data.directory),
mcdu,
sheets_listing,
click_mode: ClickMode::Open,
edit_mode: false,
scroll_adjustment: Adjustment::builder().build(),
sheet_edit_dialog: None,
};
@ -185,9 +164,7 @@ impl AsyncComponent for AppModel {
.emit(SheetListingInput::Query(query.clone()));
}
AppInput::SheetPressed(sheet) => {
match self.click_mode {
ClickMode::Open => open_sheet(&sheet, &self.database).await,
ClickMode::Edit => {
if self.edit_mode {
self.sheet_edit_dialog = Some(
SheetEditDialogModel::builder()
.transient_for(root)
@ -197,9 +174,14 @@ impl AsyncComponent for AppModel {
})
.forward(sender.input_sender(), |_| todo!()),
);
} else {
sheet.open_file();
let mut sheet = sheet;
sheet.last_opened = I64DateTime(Utc::now());
sheet_dao::update_sheet_last_opened(&self.database, &sheet)
.await
.unwrap();
}
ClickMode::Annotate => annotate_sheet(&sheet).await,
};
}
AppInput::Refresh => {
let db = Arc::clone(&self.database);
@ -210,7 +192,7 @@ impl AsyncComponent for AppModel {
}
AppInput::Sort => self.sheets_listing.emit(SheetListingInput::Sort),
AppInput::Shuffle => self.sheets_listing.emit(SheetListingInput::Shuffle),
AppInput::SetClickMode(click_mode) => self.click_mode = click_mode,
AppInput::SetEditMode(edit_mode) => self.edit_mode = edit_mode,
AppInput::SheetListingContentsChanged => self.scroll_adjustment.set_value(0.0),
}
}
@ -228,19 +210,3 @@ impl AsyncComponent for AppModel {
.emit(SheetListingInput::ReloadSheets(sheets));
}
}
async fn open_sheet(sheet: &Sheet, database: &Database) {
sheet.open_file_or_annotated_version_if_exists();
let mut sheet = sheet.to_owned();
sheet.last_opened = I64DateTime(Utc::now());
sheet_dao::update_sheet_last_opened(database, &sheet)
.await
.unwrap();
}
async fn annotate_sheet(sheet: &Sheet) {
Command::new("xournalpp")
.arg(&sheet.pdf.path)
.spawn()
.expect("failed to execute process");
}