diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/app.rs | 37 | ||||
| -rw-r--r-- | src/bibiman.rs | 53 | ||||
| -rw-r--r-- | src/tui/popup.rs | 1 | ||||
| -rw-r--r-- | src/tui/ui.rs | 4 |
4 files changed, 82 insertions, 13 deletions
@@ -179,7 +179,9 @@ impl App { Some(PopupKind::Help) => { self.bibiman.popup_area.popup_scroll_down(); } - Some(PopupKind::OpenRes) | Some(PopupKind::AppendToFile) => { + Some(PopupKind::OpenRes) + | Some(PopupKind::AppendToFile) + | Some(PopupKind::YankItem) => { self.bibiman.popup_area.popup_state.scroll_down_by(1) } _ => {} @@ -198,7 +200,9 @@ impl App { Some(PopupKind::Help) => { self.bibiman.popup_area.popup_scroll_up(); } - Some(PopupKind::OpenRes) | Some(PopupKind::AppendToFile) => { + Some(PopupKind::OpenRes) + | Some(PopupKind::AppendToFile) + | Some(PopupKind::YankItem) => { self.bibiman.popup_area.popup_state.scroll_up_by(1) } _ => {} @@ -256,6 +260,8 @@ impl App { } else if let Some(PopupKind::AppendToFile) = self.bibiman.popup_area.popup_kind { self.bibiman.close_popup(); + } else if let Some(PopupKind::YankItem) = self.bibiman.popup_area.popup_kind { + self.bibiman.close_popup(); } } else { self.bibiman.reset_current_list(); @@ -272,6 +278,8 @@ impl App { } else if let Some(PopupKind::AppendToFile) = self.bibiman.popup_area.popup_kind { self.bibiman.append_entry_to_file()? + } else if let Some(PopupKind::YankItem) = self.bibiman.popup_area.popup_kind { + self.bibiman.yank_entry_field()? } } } @@ -285,20 +293,25 @@ impl App { } CmdAction::YankItem => { if let CurrentArea::EntryArea = self.bibiman.current_area { - let citekey: &str = &self.bibiman.entry_table.entry_table_items[self + let idx = self .bibiman .entry_table .entry_table_state .selected() - .unwrap()] - .citekey; - - Bibiman::yank_text(citekey); - self.bibiman.popup_area.popup_message( - "Yanked citekey to clipboard: ", - citekey, // self.bibiman.get_selected_citekey(), - true, - ); + .unwrap(); + let entry = self.bibiman.entry_table.entry_table_items[idx].clone(); + let mut items = vec!["Citekey".to_owned()]; + if entry.doi_url.is_some() { + items.push("Weblink".to_owned()) + } + if entry.filepath.is_some() { + items.push("Filepath".to_owned()) + } + self.bibiman.popup_area.popup_kind = Some(PopupKind::YankItem); + self.bibiman.popup_area.popup_selection(items); + self.bibiman.former_area = Some(FormerArea::EntryArea); + self.bibiman.current_area = CurrentArea::PopupArea; + self.bibiman.popup_area.popup_state.select(Some(0)); } } CmdAction::EditFile => { diff --git a/src/bibiman.rs b/src/bibiman.rs index e36d268..c90905f 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -568,6 +568,59 @@ impl Bibiman { Ok(()) } + pub fn yank_entry_field(&mut self) -> Result<()> { + // Index of selected entry + let entry_idx = self.entry_table.entry_table_state.selected().unwrap(); + + // Index of selected popup field + let popup_idx = self.popup_area.popup_state.selected().unwrap(); + + match self.popup_area.popup_list[popup_idx] + .to_lowercase() + .as_str() + { + "citekey" => { + let citekey = &self.entry_table.entry_table_items[entry_idx].citekey; + Bibiman::yank_text(citekey); + self.popup_area.popup_message( + "Yanked citekey to clipboard: ", + citekey, // self.bibiman.get_selected_citekey(), + true, + ); + } + "weblink" => { + let link = &self.entry_table.entry_table_items[entry_idx].doi_url; + if let Some(l) = link { + Bibiman::yank_text(l); + self.popup_area.popup_message( + "Yanked weblink to clipboard: ", + l, // self.bibiman.get_selected_link(), + true, + ); + } + } + "filepath" => { + let path = self.entry_table.entry_table_items[entry_idx] + .filepath + .clone(); + if let Some(p) = path { + let p = p.as_os_str().to_str(); + if let Some(p) = p { + Bibiman::yank_text(p); + self.popup_area.popup_message( + "Yanked filepath to clipboard: ", + p, // self.bibiman.get_selected_link(), + true, + ); + } + } + } + _ => {} + }; + + Ok(()) + } + /// Formats a raw BibTeX entry string for better readability. pub fn format_bibtex_entry(entry: &str, file_path: &str) -> String { let mut formatted = String::new(); diff --git a/src/tui/popup.rs b/src/tui/popup.rs index f226429..2a6f18a 100644 --- a/src/tui/popup.rs +++ b/src/tui/popup.rs @@ -31,6 +31,7 @@ pub enum PopupKind { OpenRes, AppendToFile, AddEntry, + YankItem, } #[derive(Debug, Default)] diff --git a/src/tui/ui.rs b/src/tui/ui.rs index 2d58aec..921cbb1 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -272,7 +272,7 @@ pub fn render_popup(app: &mut App, cfg: &BibiConfig, frame: &mut Frame) { frame.render_widget(Clear, popup_area); frame.render_widget(&content, popup_area) } - Some(PopupKind::OpenRes) | Some(PopupKind::AppendToFile) => { + Some(PopupKind::OpenRes) | Some(PopupKind::AppendToFile) | Some(PopupKind::YankItem) => { let list_items: Vec<ListItem> = app .bibiman .popup_area @@ -285,6 +285,8 @@ pub fn render_popup(app: &mut App, cfg: &BibiConfig, frame: &mut Frame) { " Open " } else if let Some(PopupKind::AppendToFile) = app.bibiman.popup_area.popup_kind { " Select file to append entry " + } else if let Some(PopupKind::YankItem) = app.bibiman.popup_area.popup_kind { + " Yank to clipboard " } else { " Select " }; |
