Skip to content

Commit 46fe93b

Browse files
Simplify SketchController.addFile using FileUtils.hasExtension
1 parent 66a6fc3 commit 46fe93b

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

app/src/processing/app/SketchController.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -704,19 +704,15 @@ public void handleAddFile() {
704704
public boolean addFile(File sourceFile) {
705705
String filename = sourceFile.getName();
706706
File destFile = null;
707-
String codeExtension = null;
707+
boolean isData = false;
708708
boolean replacement = false;
709709

710-
for (String extension : Sketch.EXTENSIONS) {
711-
String lower = filename.toLowerCase();
712-
if (lower.endsWith("." + extension)) {
713-
destFile = new File(sketch.getFolder(), filename);
714-
codeExtension = extension;
715-
}
716-
}
717-
if (codeExtension == null) {
710+
if (FileUtils.hasExtension(sourceFile, Sketch.EXTENSIONS)) {
711+
destFile = new File(sketch.getFolder(), filename);
712+
} else {
718713
prepareDataFolder();
719714
destFile = new File(sketch.getDataFolder(), filename);
715+
isData = true;
720716
}
721717

722718
// check whether this file already exists
@@ -752,7 +748,7 @@ public boolean addFile(File sourceFile) {
752748
}
753749

754750
// make sure they aren't the same file
755-
if ((codeExtension == null) && sourceFile.equals(destFile)) {
751+
if (isData && sourceFile.equals(destFile)) {
756752
Base.showWarning(tr("You can't fool me"),
757753
tr("This file has already been copied to the\n" +
758754
"location from which where you're trying to add it.\n" +
@@ -774,7 +770,7 @@ public boolean addFile(File sourceFile) {
774770
}
775771
}
776772

777-
if (codeExtension != null) {
773+
if (!isData) {
778774
SketchCode newCode = new SketchCode(destFile, false);
779775

780776
if (replacement) {

0 commit comments

Comments
 (0)