diff --git a/app/src/processing/app/SketchController.java b/app/src/processing/app/SketchController.java index 662ca114d..902c9e333 100644 --- a/app/src/processing/app/SketchController.java +++ b/app/src/processing/app/SketchController.java @@ -140,7 +140,7 @@ public class SketchController { // Add the extension here, this simplifies some of the logic below. if (newName.indexOf('.') == -1) { - newName += "." + sketch.getDefaultExtension(); + newName += "." + Sketch.DEFAULT_SKETCH_EXTENSION; } // if renaming to the same thing as before, just ignore. @@ -167,17 +167,17 @@ public class SketchController { return; } - String newExtension = newName.substring(dot+1).toLowerCase(); - if (!validExtension(newExtension)) { + FileUtils.SplitFile split = FileUtils.splitFilename(newName); + if (!Sketch.EXTENSIONS.contains(split.extension)) { Base.showWarning(tr("Problem with rename"), - I18n.format( - tr("\".{0}\" is not a valid extension."), newExtension - ), null); + I18n.format(tr("\".{0}\" is not a valid extension."), + split.extension), + null); return; } // Don't let the user create the main tab as a .java file instead of .pde - if (!isDefaultExtension(newExtension)) { + if (!split.extension.equals(Sketch.DEFAULT_SKETCH_EXTENSION)) { if (renamingCode) { // If creating a new tab, don't show this error if (current.isPrimary()) { // If this is the main tab, disallow Base.showWarning(tr("Problem with rename"), @@ -189,14 +189,9 @@ public class SketchController { } } - // dots are allowed for the .pde and .java, but not in the name - // make sure the user didn't name things poo.time.pde - // or something like that (nothing against poo time) - String shortName = newName.substring(0, dot); - String sanitaryName = BaseNoGui.sanitizeName(shortName); - if (!shortName.equals(sanitaryName)) { - newName = sanitaryName + "." + newExtension; - } + // Sanitize name + String sanitaryName = BaseNoGui.sanitizeName(split.basename); + newName = sanitaryName + "." + split.extension; // In Arduino, we want to allow files with the same name but different // extensions, so compare the full names (including extensions). This @@ -1058,23 +1053,6 @@ public class SketchController { return code.isExtension(sketch.getDefaultExtension()); } - - /** - * True if the specified extension is the default file extension. - */ - private boolean isDefaultExtension(String what) { - return what.equals(sketch.getDefaultExtension()); - } - - - /** - * Check this extension (no dots, please) against the list of valid - * extensions. - */ - private boolean validExtension(String what) { - return Sketch.EXTENSIONS.contains(what); - } - /** * Create the data folder if it does not exist already. As a convenience, * it also returns the data folder, since it's likely about to be used. diff --git a/arduino-core/src/processing/app/Sketch.java b/arduino-core/src/processing/app/Sketch.java index 90e3964a3..a598841ab 100644 --- a/arduino-core/src/processing/app/Sketch.java +++ b/arduino-core/src/processing/app/Sketch.java @@ -15,7 +15,8 @@ import static processing.app.I18n.tr; */ public class Sketch { - public static final List SKETCH_EXTENSIONS = Arrays.asList("ino", "pde"); + public static final String DEFAULT_SKETCH_EXTENSION = "ino"; + public static final List SKETCH_EXTENSIONS = Arrays.asList(DEFAULT_SKETCH_EXTENSION, "pde"); public static final List OTHER_ALLOWED_EXTENSIONS = Arrays.asList("c", "cpp", "h", "hh", "hpp", "s"); public static final List EXTENSIONS = Stream.concat(SKETCH_EXTENSIONS.stream(), OTHER_ALLOWED_EXTENSIONS.stream()).collect(Collectors.toList());