aboutsummaryrefslogtreecommitdiff
path: root/src/app.rs
diff options
context:
space:
mode:
authorlukeflo2024-12-23 19:07:24 +0100
committerlukeflo2024-12-23 21:03:19 +0100
commit6ff6b82e0fcea4344db8b17ea5be2d72b3d9d9f2 (patch)
tree9b388462c25c39186a52cef047d651a728d4369c /src/app.rs
parentbf93bbee1b59c9804a01a7476e12264bbbcf5f40 (diff)
downloadbibiman-6ff6b82e0fcea4344db8b17ea5be2d72b3d9d9f2.tar.gz
bibiman-6ff6b82e0fcea4344db8b17ea5be2d72b3d9d9f2.zip
better error messages for doi-add
Diffstat (limited to 'src/app.rs')
-rw-r--r--src/app.rs42
1 files changed, 24 insertions, 18 deletions
diff --git a/src/app.rs b/src/app.rs
index a3691d6..a3b0522 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -139,7 +139,12 @@ impl App {
self.bibiman.close_popup();
self.input_mode = false;
// Check if the DOI pattern is valid. If not, show warning and break
- if doi.starts_with("10.") || doi.starts_with("http") {
+ if doi.starts_with("10.")
+ || doi.starts_with("https://doi.org")
+ || doi.starts_with("https://dx.doi.org")
+ || doi.starts_with("http://doi.org")
+ || doi.starts_with("http://dx.doi.org")
+ {
self.bibiman.handle_new_entry_submission(args, doi);
} else {
self.bibiman.popup_area.popup_message(
@@ -177,7 +182,7 @@ impl App {
Some(PopupKind::Help) => {
self.bibiman.popup_area.popup_scroll_down();
}
- Some(PopupKind::SelectRes) | Some(PopupKind::SelectFile) => {
+ Some(PopupKind::OpenRes) | Some(PopupKind::AppendToFile) => {
self.bibiman.popup_area.popup_state.scroll_down_by(1)
}
_ => {}
@@ -196,7 +201,7 @@ impl App {
Some(PopupKind::Help) => {
self.bibiman.popup_area.popup_scroll_up();
}
- Some(PopupKind::SelectRes) | Some(PopupKind::SelectFile) => {
+ Some(PopupKind::OpenRes) | Some(PopupKind::AppendToFile) => {
self.bibiman.popup_area.popup_state.scroll_up_by(1)
}
_ => {}
@@ -249,9 +254,10 @@ impl App {
if let Some(PopupKind::Help) = self.bibiman.popup_area.popup_kind {
self.bibiman.popup_area.popup_scroll_pos = 0;
self.bibiman.close_popup()
- } else if let Some(PopupKind::SelectRes) = self.bibiman.popup_area.popup_kind {
+ } else if let Some(PopupKind::OpenRes) = self.bibiman.popup_area.popup_kind {
self.bibiman.close_popup()
- } else if let Some(PopupKind::SelectFile) = self.bibiman.popup_area.popup_kind {
+ } else if let Some(PopupKind::AppendToFile) = self.bibiman.popup_area.popup_kind
+ {
self.bibiman.close_popup();
}
} else {
@@ -264,7 +270,7 @@ impl App {
} else if let CurrentArea::PopupArea = self.bibiman.current_area {
if let Some(PopupKind::Help) = self.bibiman.popup_area.popup_kind {
self.bibiman.close_popup();
- } else if let Some(PopupKind::SelectRes) = self.bibiman.popup_area.popup_kind {
+ } else if let Some(PopupKind::OpenRes) = self.bibiman.popup_area.popup_kind {
// Index of selected entry
let entry_idx = self
.bibiman
@@ -291,26 +297,27 @@ impl App {
};
// run command to open file/Url
self.bibiman.close_popup()
- } else if let Some(PopupKind::SelectFile) = self.bibiman.popup_area.popup_kind {
+ } else if let Some(PopupKind::AppendToFile) = self.bibiman.popup_area.popup_kind
+ {
// Index of selected popup field
let popup_idx = self.bibiman.popup_area.popup_state.selected().unwrap();
// regex pattern to match citekey in fetched bibtexstring
let pattern = Regex::new(r"\{([^\{\},]*),").unwrap();
- let citekey = PathBuf::from(
- pattern
- .captures(&self.bibiman.popup_area.popup_sel_item)
- .unwrap()
- .get(1)
- .unwrap()
- .as_str(),
- );
+ let citekey = pattern
+ .captures(&self.bibiman.popup_area.popup_sel_item)
+ .unwrap()
+ .get(1)
+ .unwrap()
+ .as_str()
+ .to_string();
// Check if new file or existing file was choosen
let mut file = if self.bibiman.popup_area.popup_list[popup_idx]
.contains("Create new file")
{
+ let citekey = PathBuf::from(&citekey);
// Get path of current files
let path: PathBuf = if args.files[0].is_file() {
args.files[0].parent().unwrap().to_owned()
@@ -338,8 +345,7 @@ impl App {
self.bibiman.close_popup();
// Select newly created entry
- self.bibiman
- .select_entry_by_citekey(citekey.to_str().unwrap());
+ self.bibiman.select_entry_by_citekey(&citekey);
}
}
}
@@ -388,7 +394,7 @@ impl App {
if entry.filepath.is_some() {
items.push("File (PDF/EPUB)".to_owned())
}
- self.bibiman.popup_area.popup_kind = Some(PopupKind::SelectRes);
+ self.bibiman.popup_area.popup_kind = Some(PopupKind::OpenRes);
self.bibiman.popup_area.popup_selection(items);
self.bibiman.former_area = Some(FormerArea::EntryArea);
self.bibiman.current_area = CurrentArea::PopupArea;