Don't store the extension in SketchCode

Nobody was using it anymore, except for checking against specific
extensions, which is easily done against the filename itself. This
prepares for some simplification of Sketch.load next.
This commit is contained in:
Matthijs Kooijman 2014-07-08 15:35:38 +02:00 committed by Cristian Maglie
parent 43dac3a902
commit e994c52729
2 changed files with 16 additions and 19 deletions

View File

@ -192,7 +192,7 @@ public class Sketch {
// it would be otherwise possible to sneak in nasty filenames. [0116]
if (Sketch.isSanitaryName(base)) {
code[codeCount++] =
new SketchCode(new File(folder, filename), extension);
new SketchCode(new File(folder, filename));
} else {
editor.console.message(I18n.format("File name {0} is invalid: ignored", filename), true, false);
}
@ -487,7 +487,7 @@ public class Sketch {
}
}
if (!current.renameTo(newFile, newExtension)) {
if (!current.renameTo(newFile)) {
Base.showWarning(_("Error"),
I18n.format(
_("Could not rename \"{0}\" to \"{1}\""),
@ -531,7 +531,7 @@ public class Sketch {
editor.base.rebuildSketchbookMenus();
} else { // else if something besides code[0]
if (!current.renameTo(newFile, newExtension)) {
if (!current.renameTo(newFile)) {
Base.showWarning(_("Error"),
I18n.format(
_("Could not rename \"{0}\" to \"{1}\""),
@ -557,7 +557,7 @@ public class Sketch {
), e);
return;
}
SketchCode newCode = new SketchCode(newFile, newExtension);
SketchCode newCode = new SketchCode(newFile);
//System.out.println("new code is named " + newCode.getPrettyName() + " " + newCode.getFile());
insertCode(newCode);
}
@ -788,7 +788,7 @@ public class Sketch {
String pdeName = pdeFile.getPath();
pdeName = pdeName.substring(0, pdeName.length() - 4) + ".ino";
return c.renameTo(new File(pdeName), "ino");
return c.renameTo(new File(pdeName));
}
return false;
}
@ -1075,7 +1075,7 @@ public class Sketch {
}
if (codeExtension != null) {
SketchCode newCode = new SketchCode(destFile, codeExtension);
SketchCode newCode = new SketchCode(destFile);
if (replacement) {
replaceCode(newCode);

View File

@ -25,10 +25,13 @@
package processing.app;
import java.io.*;
import java.util.List;
import java.util.Arrays;
import javax.swing.text.Document;
import static processing.app.I18n._;
import processing.app.helpers.FileUtils;
/**
@ -41,9 +44,6 @@ public class SketchCode {
/** File object for where this code is located */
private File file;
/** Extension for this file (no dots, and in lowercase). */
private String extension;
/** Text of the program text for this tab */
private String program;
@ -70,9 +70,8 @@ public class SketchCode {
private int preprocOffset;
public SketchCode(File file, String extension) {
public SketchCode(File file) {
this.file = file;
this.extension = extension;
makePrettyName();
@ -125,11 +124,10 @@ public class SketchCode {
}
protected boolean renameTo(File what, String ext) {
protected boolean renameTo(File what) {
boolean success = file.renameTo(what);
if (success) {
file = what;
extension = ext;
makePrettyName();
}
return success;
@ -151,13 +149,12 @@ public class SketchCode {
}
public String getExtension() {
return extension;
public boolean isExtension(String... extensions) {
return isExtension(Arrays.asList(extensions));
}
public boolean isExtension(String what) {
return extension.equals(what);
public boolean isExtension(List<String> extensions) {
return FileUtils.hasExtension(file, extensions);
}