diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java index b4808075..88fd687f 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java @@ -456,10 +456,11 @@ private static void prepareSaveMappingsAsMenu(JMenu saveMappingsAsMenu, JMenuIte // Check that the file name ends with the extension. String fileName = savePath.getFileName().toString(); String extension = format.getFileType().extension(); + assert extension != null; - if (!fileName.endsWith("." + extension)) { + if (!fileName.endsWith(extension)) { // If not, add the extension. - savePath = savePath.resolveSibling(fileName + "." + extension); + savePath = savePath.resolveSibling(fileName + extension); // Store the adjusted file, so that it shows up properly // the next time this dialog is used. fileChooser.setSelectedFile(savePath.toFile()); diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/util/ExtensionFileFilter.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/util/ExtensionFileFilter.java index a51bffbd..31c19530 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/util/ExtensionFileFilter.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/util/ExtensionFileFilter.java @@ -12,6 +12,12 @@ public final class ExtensionFileFilter extends FileFilter { private final String formatName; private final List extensions; + /** + * Constructs an {@code ExtensionFileFilter}. + * + * @param formatName the human-readable name of the file format + * @param extensions the file extensions with their leading dots (e.g. {@code .txt}) + */ public ExtensionFileFilter(String formatName, String... extensions) { this.formatName = formatName; this.extensions = List.of(extensions); @@ -25,7 +31,7 @@ public boolean accept(File f) { } for (String extension : extensions) { - if (f.getName().endsWith("." + extension)) { + if (f.getName().endsWith(extension)) { return true; } } @@ -38,7 +44,7 @@ public String getDescription() { var joiner = new StringJoiner(", "); for (String extension : extensions) { - joiner.add("*." + extension); + joiner.add("*" + extension); } return I18n.translateFormatted("menu.file.mappings.file_filter", formatName, joiner.toString()); diff --git a/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingFormat.java b/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingFormat.java index ae294237..22ab8dd5 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingFormat.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingFormat.java @@ -78,15 +78,15 @@ public FileType getFileType() { * A file type. It can be either a single file with an extension, or a directory * with a {@code null} extension. * - * @param extension the file extension without the trailing dot {@code .}, or {@code null} for a directory + * @param extension the file extension with the leading dot {@code .}, or {@code null} for a directory */ public record FileType(@Nullable String extension) { public static final FileType DIRECTORY = new FileType(null); - public static final FileType MAPPING = new FileType("mapping"); - public static final FileType SRG = new FileType("srg"); - public static final FileType TINY = new FileType("tiny"); - public static final FileType TXT = new FileType("txt"); - public static final FileType ZIP = new FileType("zip"); + public static final FileType MAPPING = new FileType(".mapping"); + public static final FileType SRG = new FileType(".srg"); + public static final FileType TINY = new FileType(".tiny"); + public static final FileType TXT = new FileType(".txt"); + public static final FileType ZIP = new FileType(".zip"); public boolean isDirectory() { return extension == null;