aboutsummaryrefslogtreecommitdiff
path: root/src/bibiman.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bibiman.rs')
-rw-r--r--src/bibiman.rs86
1 files changed, 20 insertions, 66 deletions
diff --git a/src/bibiman.rs b/src/bibiman.rs
index e3509a9..583d849 100644
--- a/src/bibiman.rs
+++ b/src/bibiman.rs
@@ -28,6 +28,7 @@ use color_eyre::eyre::{Error, Result};
use editor_command::EditorBuilder;
use ratatui::widgets::ScrollbarState;
use regex::Regex;
+use std::ffi::OsString;
use std::fs::{self, read_to_string};
use std::fs::{File, OpenOptions};
use std::io::Write;
@@ -666,6 +667,7 @@ impl Bibiman {
// Index of selected popup field
let popup_idx = self.popup_area.popup_state.selected().unwrap();
+ let popup_entry = self.popup_area.popup_list[popup_idx].1.clone();
// Choose ressource depending an selected popup field
if self.popup_area.popup_list[popup_idx].0.contains("Weblink") {
@@ -674,8 +676,9 @@ impl Bibiman {
app::open_connected_link(cfg, &url)?;
} else if self.popup_area.popup_list[popup_idx].0.contains("File") {
// TODO: Selection for multiple files
- let object = self.entry_table.entry_table_items[entry_idx].filepath()[0];
- app::open_connected_file(cfg, object)?;
+ // let object = self.entry_table.entry_table_items[entry_idx].filepath()[0];
+ let object: OsString = popup_entry.into();
+ app::open_connected_file(cfg, &object)?;
} else {
eprintln!("Unable to find ressource to open");
};
@@ -686,76 +689,27 @@ impl Bibiman {
}
pub fn yank_entry_field(&mut self) -> Result<()> {
- // self.close_popup();
- // 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();
+ let popup_entry = self.popup_area.popup_list[popup_idx].1.clone();
- match self.popup_area.popup_list[popup_idx]
+ let kind = self.popup_area.popup_list[popup_idx]
.0
.to_lowercase()
- .as_str()
- .split_whitespace()
+ .split(":")
.next()
- {
- Some("citekey:") => {
- let citekey = &self.entry_table.entry_table_items[entry_idx].citekey;
- Bibiman::yank_text(citekey);
- self.open_popup(
- PopupKind::MessageConfirm,
- Some("Yanked citekey to clipboard: "),
- Some(citekey.clone().as_str()),
- None,
- )?;
- // self.popup_area.popup_message(
- // "Yanked citekey to clipboard: ",
- // citekey, // self.bibiman.get_selected_citekey(),
- // true,
- // );
- }
- Some("weblink:") => {
- let link = &self.entry_table.entry_table_items[entry_idx].doi_url;
- if let Some(l) = link {
- Bibiman::yank_text(l);
- self.open_popup(
- PopupKind::MessageConfirm,
- Some("Yanked weblink to clipboard: "),
- Some(l.clone().as_str()),
- None,
- )?;
- // self.popup_area.popup_message(
- // "Yanked weblink to clipboard: ",
- // l, // self.bibiman.get_selected_link(),
- // true,
- // );
- }
- }
- Some("filepath:") => {
- let path = self.entry_table.entry_table_items[entry_idx]
- .filepath
- .clone();
- if let Some(p) = path {
- let p = p[0].as_os_str().to_str();
- if let Some(p) = p {
- Bibiman::yank_text(p);
- self.open_popup(
- PopupKind::MessageConfirm,
- Some("Yanked filepath to clipboard: "),
- Some(p),
- None,
- )?;
- // self.popup_area.popup_message(
- // "Yanked filepath to clipboard: ",
- // p, // self.bibiman.get_selected_link(),
- // true,
- // );
- }
- }
- }
- _ => {}
- };
+ .unwrap()
+ .to_owned();
+
+ let msg = format!("Yanked {} to clipboard: ", &kind);
+
+ Bibiman::yank_text(&popup_entry);
+ self.open_popup(
+ PopupKind::MessageConfirm,
+ Some(&msg),
+ Some(&popup_entry),
+ None,
+ )?;
Ok(())
}