From 5de5793e74193d5c96b75d4cd13703ace1d0104f Mon Sep 17 00:00:00 2001 From: lukeflo Date: Sun, 30 Mar 2025 20:33:59 +0200 Subject: yank multiple fields + open a selection menu when pressing `y` + select a field: citekey, weblink, filepath + copy value of selected field to clipboard --- src/app.rs | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'src/app.rs') diff --git a/src/app.rs b/src/app.rs index 1eaa1a3..24d9eed 100644 --- a/src/app.rs +++ b/src/app.rs @@ -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 => { -- cgit v1.2.3