Skip to content

Commit 83d0a5e

Browse files
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.
1 parent 8519b5d commit 83d0a5e

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

app/src/processing/app/Sketch.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ protected void load() throws IOException {
192192
// it would be otherwise possible to sneak in nasty filenames. [0116]
193193
if (Sketch.isSanitaryName(base)) {
194194
code[codeCount++] =
195-
new SketchCode(new File(folder, filename), extension);
195+
new SketchCode(new File(folder, filename));
196196
} else {
197197
editor.console.message(I18n.format("File name {0} is invalid: ignored", filename), true, false);
198198
}
@@ -487,7 +487,7 @@ protected void nameCode(String newName) {
487487
}
488488
}
489489

490-
if (!current.renameTo(newFile, newExtension)) {
490+
if (!current.renameTo(newFile)) {
491491
Base.showWarning(_("Error"),
492492
I18n.format(
493493
_("Could not rename \"{0}\" to \"{1}\""),
@@ -532,7 +532,7 @@ protected void nameCode(String newName) {
532532
editor.base.rebuildSketchbookMenus();
533533

534534
} else { // else if something besides code[0]
535-
if (!current.renameTo(newFile, newExtension)) {
535+
if (!current.renameTo(newFile)) {
536536
Base.showWarning(_("Error"),
537537
I18n.format(
538538
_("Could not rename \"{0}\" to \"{1}\""),
@@ -558,7 +558,7 @@ protected void nameCode(String newName) {
558558
), e);
559559
return;
560560
}
561-
SketchCode newCode = new SketchCode(newFile, newExtension);
561+
SketchCode newCode = new SketchCode(newFile);
562562
//System.out.println("new code is named " + newCode.getPrettyName() + " " + newCode.getFile());
563563
insertCode(newCode);
564564
}
@@ -789,7 +789,7 @@ protected boolean renameCodeToInoExtension(File pdeFile) {
789789

790790
String pdeName = pdeFile.getPath();
791791
pdeName = pdeName.substring(0, pdeName.length() - 4) + ".ino";
792-
return c.renameTo(new File(pdeName), "ino");
792+
return c.renameTo(new File(pdeName));
793793
}
794794
return false;
795795
}
@@ -1076,7 +1076,7 @@ public boolean addFile(File sourceFile) {
10761076
}
10771077

10781078
if (codeExtension != null) {
1079-
SketchCode newCode = new SketchCode(destFile, codeExtension);
1079+
SketchCode newCode = new SketchCode(destFile);
10801080

10811081
if (replacement) {
10821082
replaceCode(newCode);

app/src/processing/app/SketchCode.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import javax.swing.text.Document;
3232

3333
import static processing.app.I18n._;
34+
import processing.app.helpers.FileUtils;
3435

3536

3637
/**
@@ -43,9 +44,6 @@ public class SketchCode {
4344
/** File object for where this code is located */
4445
private File file;
4546

46-
/** Extension for this file (no dots, and in lowercase). */
47-
private String extension;
48-
4947
/** Text of the program text for this tab */
5048
private String program;
5149

@@ -72,9 +70,8 @@ public class SketchCode {
7270
private int preprocOffset;
7371

7472

75-
public SketchCode(File file, String extension) {
73+
public SketchCode(File file) {
7674
this.file = file;
77-
this.extension = extension;
7875

7976
makePrettyName();
8077

@@ -127,11 +124,10 @@ public boolean accept(File pathname) {
127124
}
128125

129126

130-
protected boolean renameTo(File what, String ext) {
127+
protected boolean renameTo(File what) {
131128
boolean success = file.renameTo(what);
132129
if (success) {
133130
file = what;
134-
extension = ext;
135131
makePrettyName();
136132
}
137133
return success;
@@ -153,17 +149,12 @@ public String getPrettyName() {
153149
}
154150

155151

156-
public String getExtension() {
157-
return extension;
158-
}
159-
160-
161152
public boolean isExtension(String... extensions) {
162153
return isExtension(Arrays.asList(extensions));
163154
}
164155

165156
public boolean isExtension(List<String> extensions) {
166-
return extensions.contains(extension);
157+
return FileUtils.hasExtension(file, extensions);
167158
}
168159

169160

0 commit comments

Comments
 (0)