From 6412cf0e6a26b3670f0a30c5fc7c004c9e78ed4c Mon Sep 17 00:00:00 2001 From: David Stirling Date: Thu, 22 Feb 2024 13:53:19 +0000 Subject: [PATCH] Handle missing files when using the "Show" button --- .../convert/tables/MultiButtonTableCell.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/glencoesoftware/convert/tables/MultiButtonTableCell.java b/src/main/java/com/glencoesoftware/convert/tables/MultiButtonTableCell.java index 76aa866..5b18133 100644 --- a/src/main/java/com/glencoesoftware/convert/tables/MultiButtonTableCell.java +++ b/src/main/java/com/glencoesoftware/convert/tables/MultiButtonTableCell.java @@ -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; @@ -110,13 +111,23 @@ public class MultiButtonTableCell extends TableCell { 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); }