Skip to content

Commit

Permalink
Merge pull request #60 from glencoesoftware/openfile
Browse files Browse the repository at this point in the history
Handle missing files when using the "Show Resulting File" button
  • Loading branch information
sbesson authored May 8, 2024
2 parents 75ebd3f + 6412cf0 commit 32b1a95
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.kordamp.ikonli.javafx.FontIcon;

import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;

Expand Down Expand Up @@ -110,13 +111,23 @@ public class MultiButtonTableCell extends TableCell<BaseWorkflow, Void> {
showFile.setGraphic(openDirIcon);
showFile.setTooltip(new Tooltip("Open containing folder"));
showFile.setOnAction(evt -> {
File target = getTableRow().getItem().finalOutput;
if (!target.exists()) {
// If the user split the file we might need to show the parent directory instead.
target = target.getParentFile();
if (!target.exists()) {
// User probably nuked the entire directory
getTableRow().getItem().controller.updateStatus("Unable to locate output file");
return;
}
}
Desktop desktop = Desktop.getDesktop();
try {
desktop.browseFileDirectory(getTableRow().getItem().finalOutput);
desktop.browseFileDirectory(target);
} catch (UnsupportedOperationException e) {
// Some Windows versions don't support browse for some reason
// Some Windows versions don't support browsing to a specific file for some reason
try {
desktop.open(getTableRow().getItem().finalOutput.getParentFile());
desktop.open(target.getParentFile());
} catch (IOException ex) {
throw new RuntimeException(ex);
}
Expand Down

0 comments on commit 32b1a95

Please sign in to comment.