aboutsummaryrefslogtreecommitdiff
path: root/src/bibiman.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bibiman.rs')
-rw-r--r--src/bibiman.rs35
1 files changed, 31 insertions, 4 deletions
diff --git a/src/bibiman.rs b/src/bibiman.rs
index 767dec1..0fde852 100644
--- a/src/bibiman.rs
+++ b/src/bibiman.rs
@@ -15,6 +15,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
/////
+use crate::app::App;
use crate::bibiman::entries::EntryTableColumn;
use crate::bibiman::{bibisetup::*, search::BibiSearch};
use crate::cliargs::CLIArgs;
@@ -384,9 +385,12 @@ impl Bibiman {
}
// Open file connected with entry through 'file' or 'pdf' field
- pub fn open_connected_file(&mut self) -> Result<()> {
+ pub fn open_connected_file(&self) -> Result<()> {
let idx = self.entry_table.entry_table_state.selected().unwrap();
- let filepath = &self.entry_table.entry_table_items[idx].filepath.clone();
+ let filepath = self.entry_table.entry_table_items[idx]
+ .filepath
+ .as_ref()
+ .unwrap();
// Build command to execute pdf-reader. 'xdg-open' is Linux standard
let cmd = {
@@ -401,7 +405,7 @@ impl Bibiman {
// Pass filepath as argument, pipe stdout and stderr to /dev/null
// to keep the TUI clean (where is it piped on Windows???)
let _ = Command::new(&cmd)
- .arg(filepath.as_ref().unwrap())
+ .arg(filepath)
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
@@ -410,7 +414,7 @@ impl Bibiman {
Ok(())
}
- pub fn open_doi_url(&mut self) -> Result<()> {
+ pub fn open_doi_url(&self) -> Result<()> {
let idx = self.entry_table.entry_table_state.selected().unwrap();
let web_adress = self.entry_table.entry_table_items[idx]
.doi_url
@@ -642,3 +646,26 @@ impl Bibiman {
}
}
}
+
+pub fn open_connected_res(object: &str) -> Result<()> {
+ // Build command to execute pdf-reader. 'xdg-open' is Linux standard
+ let cmd = {
+ match std::env::consts::OS {
+ "linux" => String::from("xdg-open"),
+ "macos" => String::from("open"),
+ "windows" => String::from("start"),
+ _ => panic!("Couldn't detect OS for setting correct opener"),
+ }
+ };
+
+ // Pass filepath as argument, pipe stdout and stderr to /dev/null
+ // to keep the TUI clean (where is it piped on Windows???)
+ let _ = Command::new(&cmd)
+ .arg(object)
+ .stdout(Stdio::null())
+ .stderr(Stdio::null())
+ .spawn()
+ .wrap_err("Opening file not possible");
+
+ Ok(())
+}