aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app.rs27
-rw-r--r--src/bibiman/bibisetup.rs63
-rw-r--r--src/bibiman/entries.rs2
-rw-r--r--src/bibiman/search.rs5
-rw-r--r--src/tui/popup.rs22
-rw-r--r--src/tui/ui.rs16
6 files changed, 74 insertions, 61 deletions
diff --git a/src/app.rs b/src/app.rs
index f751716..15cdfe3 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -350,7 +350,19 @@ impl App {
entry.filepath.unwrap().iter().for_each(|p| {
items.push((
"File (PDF/EPUB): ".into(),
- p.clone().into_string().unwrap(),
+ // p.clone().into_string().unwrap(),
+ if entry.file_field && cfg.general.file_prefix.is_some() {
+ cfg.general
+ .file_prefix
+ .clone()
+ .unwrap()
+ .join(p)
+ .into_os_string()
+ .into_string()
+ .unwrap()
+ } else {
+ p.clone().into_string().unwrap()
+ },
))
});
}
@@ -360,7 +372,7 @@ impl App {
} else {
self.bibiman.open_popup(
PopupKind::MessageError,
- Some("Selected entry has no connected ressources: "),
+ Some("Selected entry has no connected resources: "),
Some(&entry.citekey),
None,
)?;
@@ -389,11 +401,12 @@ 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 = 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();
diff --git a/src/bibiman/bibisetup.rs b/src/bibiman/bibisetup.rs
index 92e02fc..bf5baf5 100644
--- a/src/bibiman/bibisetup.rs
+++ b/src/bibiman/bibisetup.rs
@@ -53,6 +53,7 @@ pub struct BibiData {
pub abstract_text: String,
pub doi_url: Option<String>,
pub filepath: Option<Vec<OsString>>,
+ pub file_field: bool,
pub subtitle: Option<String>,
}
@@ -115,10 +116,9 @@ impl BibiData {
self.doi_url.as_ref().unwrap()
}
- // pub fn filepath(&self) -> &OsStr {
- // self.filepath.as_ref().unwrap()
- // }
-
+ // Gets the path of the associated file for a bib entry. If one is set explicitly
+ // as a field, use that. If not, try to match it to one of the files found in the
+ // pdf_files dir.
pub fn filepath(&mut self) -> Vec<&OsStr> {
self.filepath
.as_mut()
@@ -207,19 +207,25 @@ impl BibiSetup {
citekeys
.iter()
.enumerate()
- .map(|(i, k)| BibiData {
- id: i as u32,
- authors: Self::get_authors(k, bibliography),
- short_author: String::new(),
- title: Self::get_title(k, bibliography),
- year: Self::get_year(k, bibliography),
- pubtype: Self::get_pubtype(k, bibliography),
- keywords: Self::get_keywords(k, bibliography),
- citekey: k.to_owned(),
- abstract_text: Self::get_abstract(k, bibliography),
- doi_url: Self::get_weblink(k, bibliography),
- filepath: Self::get_filepath(k, bibliography, &mut pdf_files),
- subtitle: Self::get_subtitle(k, bibliography),
+ .map(|(i, k)| {
+ let filepaths: (Option<Vec<OsString>>, bool) =
+ { Self::get_filepath(k, bibliography, &mut pdf_files) };
+
+ BibiData {
+ id: i as u32,
+ authors: Self::get_authors(k, bibliography),
+ short_author: String::new(),
+ title: Self::get_title(k, bibliography),
+ year: Self::get_year(k, bibliography),
+ pubtype: Self::get_pubtype(k, bibliography),
+ keywords: Self::get_keywords(k, bibliography),
+ citekey: k.to_owned(),
+ abstract_text: Self::get_abstract(k, bibliography),
+ doi_url: Self::get_weblink(k, bibliography),
+ filepath: filepaths.0,
+ file_field: filepaths.1,
+ subtitle: Self::get_subtitle(k, bibliography),
+ }
})
.collect()
}
@@ -354,19 +360,22 @@ impl BibiSetup {
citekey: &str,
biblio: &Bibliography,
pdf_files: &mut Option<HashMap<String, Vec<PathBuf>>>,
- ) -> Option<Vec<OsString>> {
+ ) -> (Option<Vec<OsString>>, bool) {
if biblio.get(citekey).unwrap().file().is_ok() {
- Some(vec![biblio
- .get(citekey)
- .unwrap()
- .file()
- .unwrap()
- .trim()
- .into()])
+ (
+ Some(vec![biblio
+ .get(citekey)
+ .unwrap()
+ .file()
+ .unwrap()
+ .trim()
+ .into()]),
+ true,
+ )
} else if pdf_files.is_some() {
- Self::merge_filepath_or_none(&citekey, pdf_files)
+ (Self::merge_filepath_or_none(&citekey, pdf_files), false)
} else {
- None
+ (None, false)
}
}
diff --git a/src/bibiman/entries.rs b/src/bibiman/entries.rs
index b7c7c9b..88a1583 100644
--- a/src/bibiman/entries.rs
+++ b/src/bibiman/entries.rs
@@ -157,6 +157,7 @@ mod tests {
abstract_text: "An abstract".to_string(),
doi_url: None,
filepath: None,
+ file_field: false,
subtitle: None,
};
@@ -174,6 +175,7 @@ mod tests {
abstract_text: "An abstract".to_string(),
doi_url: None,
filepath: None,
+ file_field: false,
subtitle: None,
};
diff --git a/src/bibiman/search.rs b/src/bibiman/search.rs
index 1855092..f391aed 100644
--- a/src/bibiman/search.rs
+++ b/src/bibiman/search.rs
@@ -117,6 +117,8 @@ pub fn search_pattern_in_file<'a>(pattern: &str, file: &'a PathBuf) -> Option<&'
#[cfg(test)]
mod tests {
+ use std::ffi::OsString;
+
use super::*;
#[test]
@@ -132,7 +134,8 @@ mod tests {
citekey: "author_1999".to_string(),
abstract_text: "An abstract with multiple sentences. Here is the second".to_string(),
doi_url: Some("https://www.bibiman.org".to_string()),
- filepath: Some("/home/file/path.pdf".to_string().into()),
+ filepath: Some(vec![OsString::from("/home/file/path.pdf")]),
+ file_field: true,
subtitle: None,
};
diff --git a/src/tui/popup.rs b/src/tui/popup.rs
index f3f6d58..93b01c3 100644
--- a/src/tui/popup.rs
+++ b/src/tui/popup.rs
@@ -114,28 +114,6 @@ impl PopupArea {
Text::from(helptext)
}
- /// Creates a popup message. The needed arguments are:
- ///
- /// - `message` as `str`: The message displayed in the popup.
- /// - `object` as `str`: A possible object added to the message. E.g. the content
- /// which gets copied to the clipboard.
- /// - `msg_confirm` as `bool`: if `true` its a confirmation message displayed in
- /// in the set `confirm_color` (default: green), if `false` its a warning
- /// message displayed in the set `warn_color` (default: red).
- pub fn popup_message(&mut self, message: &str, object: &str, msg_confirm: bool) {
- if object.is_empty() {
- self.popup_message = message.to_owned();
- } else {
- self.popup_message = message.to_owned() + object; //format!("{} \"{}\"", message, object);
- }
- if msg_confirm {
- self.popup_kind = Some(PopupKind::MessageConfirm);
- } else {
- self.popup_kind = Some(PopupKind::MessageError)
- }
- self.is_popup = true;
- }
-
/// Opens a popup with a selectable list
///
/// The list items are passed as argument of the kind `Vec<(String, String)>`.
diff --git a/src/tui/ui.rs b/src/tui/ui.rs
index a998bc7..2126135 100644
--- a/src/tui/ui.rs
+++ b/src/tui/ui.rs
@@ -320,16 +320,24 @@ pub fn render_popup(app: &mut App, cfg: &BibiConfig, frame: &mut Frame) {
// To find the longest line, we need to collect the chars of every item
// and add.
- let list_widths: Vec<u16> = app
+ let list_widths = app
.bibiman
.popup_area
.popup_list
.iter()
- .map(|(m, o)| m.chars().count() as u16 + o.chars().count() as u16)
- .collect();
+ .max_by(|(mes, obj), (m, o)| {
+ let x = mes.chars().count() + obj.chars().count();
+ let y = m.chars().count() + o.chars().count();
+ x.cmp(&y)
+ })
+ .unwrap();
+ // .map(|(m, o)| m.chars().count() as u16 + o.chars().count() as u16)
+ // .collect();
// Now take the max number for the width of the popup
- let max_item = list_widths.iter().max().unwrap().to_owned();
+ // let max_item = list_widths.iter().max().unwrap().to_owned();
+ let max_item =
+ list_widths.0.chars().count() as u16 + list_widths.1.chars().count() as u16;
// Check if the popup would exceed the terminal frame width
let popup_width = if max_item + 2 > frame.area().width - 2 {