multi definition of association

This commit is contained in:
Radek Davidek 2026-01-20 19:16:12 +01:00
parent e585341b69
commit c1e2bce59c

View File

@ -1248,25 +1248,37 @@ public class FilePanelTab extends JPanel {
patterns.sort((a, b) -> Integer.compare(b.length(), a.length())); patterns.sort((a, b) -> Integer.compare(b.length(), a.length()));
for (String pattern : patterns) { for (String pattern : patterns) {
String glob = pattern; String fullCommand = associations.get(pattern);
// If user just provided an extension like "txt", convert to "*.txt" // Support multiple patterns separated by semicolon (e.g. "jpg;png;gif")
if (!glob.contains("*") && !glob.contains("?")) { String[] subPatterns = pattern.split(";");
glob = "*." + glob; boolean matched = false;
}
try { for (String sub : subPatterns) {
java.nio.file.PathMatcher matcher = java.nio.file.FileSystems.getDefault().getPathMatcher("glob:" + glob); String glob = sub.trim();
if (matcher.matches(java.nio.file.Paths.get(name))) { if (glob.isEmpty()) continue;
command = associations.get(pattern);
break; // If user just provided an extension like "txt", convert to "*.txt"
if (!glob.contains("*") && !glob.contains("?")) {
glob = "*." + glob;
} }
} catch (Exception ignore) {
// Fallback for simple extension match if glob is invalid try {
if (name.toLowerCase().endsWith("." + pattern.toLowerCase())) { java.nio.file.PathMatcher matcher = java.nio.file.FileSystems.getDefault().getPathMatcher("glob:" + glob);
command = associations.get(pattern); if (matcher.matches(java.nio.file.Paths.get(name))) {
break; command = fullCommand;
matched = true;
break;
}
} catch (Exception ignore) {
// Fallback for simple extension match if glob is invalid
if (name.toLowerCase().endsWith("." + glob.toLowerCase())) {
command = fullCommand;
matched = true;
break;
}
} }
} }
if (matched) break;
} }
if (command != null && !command.trim().isEmpty()) { if (command != null && !command.trim().isEmpty()) {