Skip to content

Commit

Permalink
fix mappings chooser not accepting directories and missing translations
Browse files Browse the repository at this point in the history
  • Loading branch information
ix0rai committed Aug 22, 2024
1 parent 2943d36 commit ddb94ed
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReadWriteService> types = this.gui.getController().getEnigma().getReadWriteServices().stream().filter(ReadWriteService::supportsReading).toList();
ExtensionFileFilter.setupFileChooser(this.gui, this.gui.mappingsFileChooser, types.toArray(new ReadWriteService[0]));
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public List<String> getExtensions() {

@Override
public boolean accept(File f) {
// Always accept directories so the user can see them.
if (f.isDirectory()) {
return true;
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit ddb94ed

Please sign in to comment.