From ae1667410b0a812fff8d464251548f23f88ae024 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Sun, 29 Jun 2025 20:31:41 +0200 Subject: some more tests for notes, need to elaborate function for opening notes --- src/app.rs | 22 +++++++++++++--------- src/bibiman.rs | 5 ++--- tests/note-files/aristotle:poetics.txt | 0 tests/note-files/aristotle:rhetoric.md | 0 tests/note-files/bertram.txt | 1 + tests/note-files/betram.txt | 1 - tests/test-config.toml | 2 +- 7 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 tests/note-files/aristotle:poetics.txt create mode 100644 tests/note-files/aristotle:rhetoric.md create mode 100644 tests/note-files/bertram.txt delete mode 100644 tests/note-files/betram.txt diff --git a/src/app.rs b/src/app.rs index 5f2d16b..f015494 100644 --- a/src/app.rs +++ b/src/app.rs @@ -410,15 +410,6 @@ impl App { pub fn open_connected_file(cfg: &BibiConfig, file: &OsStr) -> Result<()> { // Build command to execute pdf-reader. 'xdg-open' is Linux standard let cmd = &cfg.general.pdf_opener; - // If necessary, replace ~ with /home dir - // let file = if cfg.general.file_prefix.is_some() { - // cfg.general.file_prefix.clone().unwrap().join(file) - // } else { - // PathBuf::from(file) - // }; - // let file = PathBuf::from(file); - - // let file = expand_home(&file).into_os_string(); // Pass filepath as argument, pipe stdout and stderr to /dev/null // to keep the TUI clean (where is it piped on Windows???) @@ -432,6 +423,19 @@ pub fn open_connected_file(cfg: &BibiConfig, file: &OsStr) -> Result<()> { Ok(()) } +pub fn open_connected_note(cfg: &BibiConfig, file: &OsStr) -> Result<()> { + // let cmd = cfg.general.editor.as_ref().unwrap(); + + let _ = Command::new("xdg-open") + .arg(file) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .spawn() + .wrap_err("Opening file not possible"); + + Ok(()) +} + pub fn open_connected_link(cfg: &BibiConfig, link: &str) -> Result<()> { // Build command to execute pdf-reader. 'xdg-open' is Linux standard let cmd = &cfg.general.url_opener; diff --git a/src/bibiman.rs b/src/bibiman.rs index 96a733c..1f19b24 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -692,12 +692,11 @@ impl Bibiman { None, )?; } - } - if self.popup_area.popup_list[popup_idx].0.contains("Note") { + } else if self.popup_area.popup_list[popup_idx].0.contains("Note") { let file = expand_home(&PathBuf::from(popup_entry.clone())); // let object: OsString = popup_entry.into(); if file.is_file() { - app::open_connected_file(cfg, &file.into_os_string())?; + app::open_connected_note(cfg, &file.into_os_string())?; self.close_popup(); } else { self.open_popup( diff --git a/tests/note-files/aristotle:poetics.txt b/tests/note-files/aristotle:poetics.txt new file mode 100644 index 0000000..e69de29 diff --git a/tests/note-files/aristotle:rhetoric.md b/tests/note-files/aristotle:rhetoric.md new file mode 100644 index 0000000..e69de29 diff --git a/tests/note-files/bertram.txt b/tests/note-files/bertram.txt new file mode 100644 index 0000000..54d31e5 --- /dev/null +++ b/tests/note-files/bertram.txt @@ -0,0 +1 @@ +A simple text file with notes about this Betram dude diff --git a/tests/note-files/betram.txt b/tests/note-files/betram.txt deleted file mode 100644 index 54d31e5..0000000 --- a/tests/note-files/betram.txt +++ /dev/null @@ -1 +0,0 @@ -A simple text file with notes about this Betram dude diff --git a/tests/test-config.toml b/tests/test-config.toml index fd39b29..99d1d00 100644 --- a/tests/test-config.toml +++ b/tests/test-config.toml @@ -4,7 +4,7 @@ bibfiles = [ "tests/biblatex-test.bib" ] ## Default editor to use when editing files. Arguments are possible -# editor = "vim" # with args: "vim -y" +editor = "vim" # with args: "vim -y" ## Default app to open PDFs/Epubs # pdf_opener = "xdg-open" -- cgit v1.2.3