file associations

This commit is contained in:
Radek Davidek 2026-01-16 17:01:47 +01:00
parent 896eafe62b
commit 78cea4d18d

View File

@ -891,10 +891,28 @@ public class FilePanelTab extends JPanel {
} }
} else if (item.isDirectory()) { } else if (item.isDirectory()) {
loadDirectory(item.getFile()); loadDirectory(item.getFile());
} else if (item.getFile().isFile()) {
openFileNative(item.getFile());
} }
} }
} }
private void openFileNative(File file) {
try {
if (file.canExecute() && !file.isDirectory()) {
new ProcessBuilder(file.getAbsolutePath())
.directory(file.getParentFile())
.start();
} else if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
Desktop.getDesktop().open(file);
}
} catch (Exception ex) {
try {
JOptionPane.showMessageDialog(this, "Error opening file: " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
} catch (Exception ignore) {}
}
}
/** /**
* Open the item located at the given point (used for double-clicks while * Open the item located at the given point (used for double-clicks while
* mouse-driven selection is blocked). This mirrors the behavior of * mouse-driven selection is blocked). This mirrors the behavior of
@ -931,6 +949,8 @@ public class FilePanelTab extends JPanel {
} }
} else if (item.isDirectory()) { } else if (item.isDirectory()) {
loadDirectory(item.getFile()); loadDirectory(item.getFile());
} else if (item.getFile().isFile()) {
openFileNative(item.getFile());
} }
} }
@ -949,13 +969,7 @@ public class FilePanelTab extends JPanel {
if (item.isDirectory()) { if (item.isDirectory()) {
loadDirectory(item.getFile()); loadDirectory(item.getFile());
} else { } else {
try { openFileNative(item.getFile());
if (Desktop.isDesktopSupported()) {
Desktop.getDesktop().open(item.getFile());
}
} catch (Exception ex) {
try { JOptionPane.showMessageDialog(FilePanelTab.this, "Cannot open: " + ex.getMessage()); } catch (Exception ignore) {}
}
} }
}); });
menu.add(openItem); menu.add(openItem);