Skip to content

Commit b3ad637

Browse files
matthijskooijmanfacchinm
authored andcommitted
Simplify SketchController.addFile using FileUtils.hasExtension
1 parent d70900e commit b3ad637

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
@@ -703,19 +703,15 @@ public void handleAddFile() {
703703
public boolean addFile(File sourceFile) {
704704
String filename = sourceFile.getName();
705705
File destFile = null;
706-
String codeExtension = null;
706+
boolean isData = false;
707707
boolean replacement = false;
708708

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

721717
// check whether this file already exists
@@ -751,7 +747,7 @@ public boolean addFile(File sourceFile) {
751747
}
752748

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

776-
if (codeExtension != null) {
772+
if (!isData) {
777773
SketchCode newCode = new SketchCode(destFile, false);
778774

779775
if (replacement) {

0 commit comments

Comments
 (0)