From ddb94ed75edae7c77786408167f977bfcceba49c Mon Sep 17 00:00:00 2001 From: ix0rai Date: Wed, 21 Aug 2024 20:16:55 -0500 Subject: [PATCH] fix mappings chooser not accepting directories and missing translations --- .../quiltmc/enigma/gui/element/MenuBar.java | 3 ++- .../enigma/gui/util/ExtensionFileFilter.java | 18 ++++++------------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java index 53ccb984d..ec42d7065 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java @@ -472,6 +472,7 @@ private void onGithubClicked() { private void onOpenMappingsClicked() { this.gui.mappingsFileChooser.setCurrentDirectory(new File(Config.main().stats.lastSelectedDir.value())); + this.gui.mappingsFileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); List types = this.gui.getController().getEnigma().getReadWriteServices().stream().filter(ReadWriteService::supportsReading).toList(); ExtensionFileFilter.setupFileChooser(this.gui, this.gui.mappingsFileChooser, types.toArray(new ReadWriteService[0])); @@ -486,7 +487,7 @@ private void onOpenMappingsClicked() { } else { String nonParseableMessage = I18n.translateFormatted("menu.file.open.non_parseable.unsupported_format", selectedFile); if (format.isPresent()) { - nonParseableMessage = I18n.translateFormatted("menu.file.open.non_parseable", I18n.translate("mapping_format." + format.get().getId().toLowerCase(Locale.ROOT))); + nonParseableMessage = I18n.translateFormatted("menu.file.open.non_parseable", I18n.translate("mapping_format." + format.get().getId().split(":")[1].toLowerCase())); } JOptionPane.showMessageDialog(this.gui.getFrame(), nonParseableMessage, I18n.translate("menu.file.open.cannot_open"), JOptionPane.ERROR_MESSAGE); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ExtensionFileFilter.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ExtensionFileFilter.java index d460ef842..56e9cda03 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ExtensionFileFilter.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ExtensionFileFilter.java @@ -37,7 +37,6 @@ public List getExtensions() { @Override public boolean accept(File f) { - // Always accept directories so the user can see them. if (f.isDirectory()) { return true; } @@ -78,17 +77,12 @@ public static void setupFileChooser(Gui gui, JFileChooser fileChooser, ReadWrite fileChooser.resetChoosableFileFilters(); for (ReadWriteService service : services) { - if (service.getFileType().isDirectory()) { - fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - } else { - fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - String formatName = I18n.translate("mapping_format." + service.getId().toLowerCase()); - var filter = new ExtensionFileFilter(formatName, service.getFileType().getExtensions()); - // Add our new filter to the list... - fileChooser.addChoosableFileFilter(filter); - // ...and choose it as the default. - fileChooser.setFileFilter(filter); - } + String formatName = I18n.translate("mapping_format." + service.getId().split(":")[1].toLowerCase()); + var filter = new ExtensionFileFilter(formatName, service.getFileType().getExtensions()); + // Add our new filter to the list... + fileChooser.addChoosableFileFilter(filter); + // ...and choose it as the default. + fileChooser.setFileFilter(filter); } if (services.length > 1) {