diff options
| author | lukeflo | 2024-12-23 19:07:24 +0100 |
|---|---|---|
| committer | lukeflo | 2024-12-23 21:03:19 +0100 |
| commit | 6ff6b82e0fcea4344db8b17ea5be2d72b3d9d9f2 (patch) | |
| tree | 9b388462c25c39186a52cef047d651a728d4369c /src | |
| parent | bf93bbee1b59c9804a01a7476e12264bbbcf5f40 (diff) | |
| download | bibiman-6ff6b82e0fcea4344db8b17ea5be2d72b3d9d9f2.tar.gz bibiman-6ff6b82e0fcea4344db8b17ea5be2d72b3d9d9f2.zip | |
better error messages for doi-add
Diffstat (limited to 'src')
| -rw-r--r-- | src/app.rs | 42 | ||||
| -rw-r--r-- | src/bibiman.rs | 4 | ||||
| -rw-r--r-- | src/tui/popup.rs | 4 | ||||
| -rw-r--r-- | src/tui/ui.rs | 6 |
4 files changed, 31 insertions, 25 deletions
@@ -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; diff --git a/src/bibiman.rs b/src/bibiman.rs index 0dc64e0..5d6aa30 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -133,14 +133,14 @@ impl Bibiman { if let Ok(entry) = new_entry { // Save generated bibtex entry in structs field self.popup_area.popup_sel_item = entry; - self.popup_area.popup_kind = Some(PopupKind::SelectFile); + self.popup_area.popup_kind = Some(PopupKind::AppendToFile); self.append_to_file(args); self.former_area = Some(FormerArea::EntryArea); self.current_area = CurrentArea::PopupArea; self.popup_area.popup_state.select(Some(0)) } else { self.popup_area - .popup_message("Failed to add new entry", "", false); + .popup_message("Can't find DOI: ", &doi_string, false); } } diff --git a/src/tui/popup.rs b/src/tui/popup.rs index 352b328..78a0719 100644 --- a/src/tui/popup.rs +++ b/src/tui/popup.rs @@ -28,8 +28,8 @@ pub enum PopupKind { Help, MessageConfirm, MessageError, - SelectRes, - SelectFile, + OpenRes, + AppendToFile, AddEntry, } diff --git a/src/tui/ui.rs b/src/tui/ui.rs index 6a3b8de..4f64338 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -283,7 +283,7 @@ pub fn render_popup(app: &mut App, args: &CLIArgs, frame: &mut Frame) { frame.render_widget(Clear, popup_area); frame.render_widget(&content, popup_area) } - Some(PopupKind::SelectRes) | Some(PopupKind::SelectFile) => { + Some(PopupKind::OpenRes) | Some(PopupKind::AppendToFile) => { let list_items: Vec<ListItem> = app .bibiman .popup_area @@ -292,9 +292,9 @@ pub fn render_popup(app: &mut App, args: &CLIArgs, frame: &mut Frame) { .map(|item| ListItem::from(item.to_owned())) .collect(); - let title = if let Some(PopupKind::SelectRes) = app.bibiman.popup_area.popup_kind { + let title = if let Some(PopupKind::OpenRes) = app.bibiman.popup_area.popup_kind { " Open " - } else if let Some(PopupKind::SelectFile) = app.bibiman.popup_area.popup_kind { + } else if let Some(PopupKind::AppendToFile) = app.bibiman.popup_area.popup_kind { " Select file to append entry " } else { " Select " |
