Simplify SketchController.addFile using FileUtils.hasExtension

This commit is contained in:
Matthijs Kooijman 2015-12-17 12:13:59 +01:00 committed by Martino Facchin
parent d70900e5ad
commit b3ad637f8c
1 changed files with 7 additions and 11 deletions

View File

@ -703,19 +703,15 @@ public class SketchController {
public boolean addFile(File sourceFile) {
String filename = sourceFile.getName();
File destFile = null;
String codeExtension = null;
boolean isData = false;
boolean replacement = false;
for (String extension : Sketch.EXTENSIONS) {
String lower = filename.toLowerCase();
if (lower.endsWith("." + extension)) {
destFile = new File(sketch.getFolder(), filename);
codeExtension = extension;
}
}
if (codeExtension == null) {
if (FileUtils.hasExtension(sourceFile, Sketch.EXTENSIONS)) {
destFile = new File(sketch.getFolder(), filename);
} else {
prepareDataFolder();
destFile = new File(sketch.getDataFolder(), filename);
isData = true;
}
// check whether this file already exists
@ -751,7 +747,7 @@ public class SketchController {
}
// make sure they aren't the same file
if ((codeExtension == null) && sourceFile.equals(destFile)) {
if (isData && sourceFile.equals(destFile)) {
Base.showWarning(tr("You can't fool me"),
tr("This file has already been copied to the\n" +
"location from which where you're trying to add it.\n" +
@ -773,7 +769,7 @@ public class SketchController {
}
}
if (codeExtension != null) {
if (!isData) {
SketchCode newCode = new SketchCode(destFile, false);
if (replacement) {