Add open dir menu entry for recordings

... to open the directory of the recording in the systems file
manager
This commit is contained in:
0xboobface 2018-11-16 20:27:41 +01:00
parent c36052f854
commit 5df5b4a405
2 changed files with 55 additions and 6 deletions

View File

@ -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();
}
}

View File

@ -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 {