aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--src/app.rs37
-rw-r--r--src/bibiman.rs53
-rw-r--r--src/tui/popup.rs1
-rw-r--r--src/tui/ui.rs4
5 files changed, 83 insertions, 14 deletions
diff --git a/README.md b/README.md
index 407aaaa..e39d8dd 100644
--- a/README.md
+++ b/README.md
@@ -301,7 +301,7 @@ Use the following keybindings to manage the TUI:
| `s` | Sort entries by current column (toggles) |
| `S` | Sort entries by position in file |
| `PageDown`, `PageUp` \| `Alt-j`, `Alt-k` | Scroll Info window |
-| `y` | Yank/copy citekey of selected entry |
+| `y` | Yank/copy field value of selected entry to clipboard |
| `e` | Open editor at selected entry |
| `a` | Add entry through DOI |
| `o` | Open related PDF or URL/DOI |
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 => {
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 "
};