forked from j62/ctbrec
Add open dir menu entry for recordings
... to open the directory of the recording in the systems file manager
This commit is contained in:
parent
c36052f854
commit
5df5b4a405
|
@ -1,6 +1,7 @@
|
||||||
package ctbrec.ui;
|
package ctbrec.ui;
|
||||||
|
|
||||||
import java.awt.Desktop;
|
import java.awt.Desktop;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
|
@ -46,17 +47,52 @@ public class DesktopIntegration {
|
||||||
}
|
}
|
||||||
|
|
||||||
// all attempts failed, show a dialog with URL at least
|
// all attempts failed, show a dialog with URL at least
|
||||||
Alert shutdownInfo = new AutosizeAlert(Alert.AlertType.ERROR);
|
Alert info = new AutosizeAlert(Alert.AlertType.ERROR);
|
||||||
shutdownInfo.setTitle("Open URL");
|
info.setTitle("Open URL");
|
||||||
shutdownInfo.setContentText("Couldn't open URL");
|
info.setContentText("Couldn't open URL");
|
||||||
BorderPane pane = new BorderPane();
|
BorderPane pane = new BorderPane();
|
||||||
pane.setTop(new Label());
|
pane.setTop(new Label());
|
||||||
TextField urlField = new TextField(uri);
|
TextField urlField = new TextField(uri);
|
||||||
urlField.setPadding(new Insets(10));
|
urlField.setPadding(new Insets(10));
|
||||||
urlField.setEditable(false);
|
urlField.setEditable(false);
|
||||||
pane.setCenter(urlField);
|
pane.setCenter(urlField);
|
||||||
shutdownInfo.getDialogPane().setExpandableContent(pane);
|
info.getDialogPane().setExpandableContent(pane);
|
||||||
shutdownInfo.getDialogPane().setExpanded(true);
|
info.getDialogPane().setExpanded(true);
|
||||||
shutdownInfo.show();
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -291,6 +291,19 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
|
||||||
contextMenu.getItems().add(deleteRecording);
|
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");
|
MenuItem downloadRecording = new MenuItem("Download");
|
||||||
downloadRecording.setOnAction((e) -> {
|
downloadRecording.setOnAction((e) -> {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue