From 5df5b4a40534189babe4a5215d13f649e19b9472 Mon Sep 17 00:00:00 2001 From: 0xboobface <0xboobface@gmail.com> Date: Fri, 16 Nov 2018 20:27:41 +0100 Subject: [PATCH] Add open dir menu entry for recordings ... to open the directory of the recording in the systems file manager --- .../java/ctbrec/ui/DesktopIntegration.java | 48 ++++++++++++++++--- src/main/java/ctbrec/ui/RecordingsTab.java | 13 +++++ 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/main/java/ctbrec/ui/DesktopIntegration.java b/src/main/java/ctbrec/ui/DesktopIntegration.java index e99dd34b..5601732a 100644 --- a/src/main/java/ctbrec/ui/DesktopIntegration.java +++ b/src/main/java/ctbrec/ui/DesktopIntegration.java @@ -1,6 +1,7 @@ package ctbrec.ui; import java.awt.Desktop; +import java.io.File; import java.io.IOException; import java.net.URI; @@ -46,17 +47,52 @@ public class DesktopIntegration { } // all attempts failed, show a dialog with URL at least - Alert shutdownInfo = new AutosizeAlert(Alert.AlertType.ERROR); - shutdownInfo.setTitle("Open URL"); - shutdownInfo.setContentText("Couldn't open URL"); + Alert info = new AutosizeAlert(Alert.AlertType.ERROR); + info.setTitle("Open URL"); + info.setContentText("Couldn't open URL"); BorderPane pane = new BorderPane(); pane.setTop(new Label()); TextField urlField = new TextField(uri); urlField.setPadding(new Insets(10)); urlField.setEditable(false); pane.setCenter(urlField); - shutdownInfo.getDialogPane().setExpandableContent(pane); - shutdownInfo.getDialogPane().setExpanded(true); - shutdownInfo.show(); + info.getDialogPane().setExpandableContent(pane); + info.getDialogPane().setExpanded(true); + info.show(); + } + + public static void open(File f) { + try { + Desktop.getDesktop().open(f); + return; + } catch (Exception e) { + LOG.debug("Couldn't open file with Desktop {}", f); + } + + // try external helpers + String[] externalHelpers = {"kde-open5", "kde-open", "gnome-open", "xdg-open"}; + Runtime rt = Runtime.getRuntime(); + for (String helper : externalHelpers) { + try { + rt.exec(helper + " " + f.getAbsolutePath()); + return; + } catch (IOException e) { + LOG.debug("Couldn't open file with {} {}", helper, f); + } + } + + // all attempts failed, show a dialog with path at least + Alert info = new AutosizeAlert(Alert.AlertType.ERROR); + info.setTitle("Open file"); + info.setContentText("Couldn't open file"); + BorderPane pane = new BorderPane(); + pane.setTop(new Label()); + TextField urlField = new TextField(f.toString()); + urlField.setPadding(new Insets(10)); + urlField.setEditable(false); + pane.setCenter(urlField); + info.getDialogPane().setExpandableContent(pane); + info.getDialogPane().setExpanded(true); + info.show(); } } diff --git a/src/main/java/ctbrec/ui/RecordingsTab.java b/src/main/java/ctbrec/ui/RecordingsTab.java index 488fad65..96a730d1 100644 --- a/src/main/java/ctbrec/ui/RecordingsTab.java +++ b/src/main/java/ctbrec/ui/RecordingsTab.java @@ -291,6 +291,19 @@ public class RecordingsTab extends Tab implements TabSelectionListener { contextMenu.getItems().add(deleteRecording); } + MenuItem openDir = new MenuItem("Open directory"); + openDir.setOnAction((e) -> { + String recordingsDir = Config.getInstance().getSettings().recordingsDir; + String path = recording.getPath(); + File recdir = new File(recordingsDir, path); + new Thread(() -> { + DesktopIntegration.open(recdir); + }).start(); + }); + if(Config.getInstance().getSettings().localRecording) { + contextMenu.getItems().add(openDir); + } + MenuItem downloadRecording = new MenuItem("Download"); downloadRecording.setOnAction((e) -> { try {