Skip to content

Commit 32b1a95

Browse files
authored
Merge pull request #60 from glencoesoftware/openfile
Handle missing files when using the "Show Resulting File" button
2 parents 75ebd3f + 6412cf0 commit 32b1a95

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/main/java/com/glencoesoftware/convert/tables/MultiButtonTableCell.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.kordamp.ikonli.javafx.FontIcon;
1818

1919
import java.awt.*;
20+
import java.io.File;
2021
import java.io.IOException;
2122
import java.util.Arrays;
2223

@@ -110,13 +111,23 @@ public class MultiButtonTableCell extends TableCell<BaseWorkflow, Void> {
110111
showFile.setGraphic(openDirIcon);
111112
showFile.setTooltip(new Tooltip("Open containing folder"));
112113
showFile.setOnAction(evt -> {
114+
File target = getTableRow().getItem().finalOutput;
115+
if (!target.exists()) {
116+
// If the user split the file we might need to show the parent directory instead.
117+
target = target.getParentFile();
118+
if (!target.exists()) {
119+
// User probably nuked the entire directory
120+
getTableRow().getItem().controller.updateStatus("Unable to locate output file");
121+
return;
122+
}
123+
}
113124
Desktop desktop = Desktop.getDesktop();
114125
try {
115-
desktop.browseFileDirectory(getTableRow().getItem().finalOutput);
126+
desktop.browseFileDirectory(target);
116127
} catch (UnsupportedOperationException e) {
117-
// Some Windows versions don't support browse for some reason
128+
// Some Windows versions don't support browsing to a specific file for some reason
118129
try {
119-
desktop.open(getTableRow().getItem().finalOutput.getParentFile());
130+
desktop.open(target.getParentFile());
120131
} catch (IOException ex) {
121132
throw new RuntimeException(ex);
122133
}

0 commit comments

Comments
 (0)