Skip to content

Commit 39dea53

Browse files
Let SketchFile figure out if it is primary by itself
Previously, the caller of the constructor did this, but now that SketchFile keeps a reference to its containing sketch, it can figure it out itself.
1 parent 300e0d7 commit 39dea53

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

arduino-core/src/processing/app/Sketch.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ private List<SketchFile> listSketchFiles(boolean showWarnings) throws IOExceptio
103103
Set<SketchFile> result = new TreeSet<>(CODE_DOCS_COMPARATOR);
104104
for (File file : FileUtils.listFiles(folder, false, EXTENSIONS)) {
105105
if (BaseNoGui.isSanitaryName(file.getName())) {
106-
FileUtils.SplitFile split = FileUtils.splitFilename(file);
107-
boolean isPrimary = split.basename.equals(folder.getName()) && SKETCH_EXTENSIONS.contains(split.extension);
108-
result.add(new SketchFile(this, file, isPrimary));
106+
result.add(new SketchFile(this, file));
109107
} else if (showWarnings) {
110108
System.err.println(I18n.format(tr("File name {0} is invalid: ignored"), file.getName()));
111109
}
@@ -287,7 +285,7 @@ public SketchFile addFile(String newName) throws IOException {
287285
checkNewFilename(newFile);
288286

289287
// Add a new sketchFile
290-
SketchFile sketchFile = new SketchFile(this, newFile, false);
288+
SketchFile sketchFile = new SketchFile(this, newFile);
291289
files.add(sketchFile);
292290
Collections.sort(files, CODE_DOCS_COMPARATOR);
293291

arduino-core/src/processing/app/SketchFile.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,12 @@ public static interface TextStorage {
9191
* @param primary
9292
* Whether this file is the primary file of the sketch
9393
*/
94-
public SketchFile(Sketch sketch, File file, boolean primary) {
94+
public SketchFile(Sketch sketch, File file) {
9595
this.sketch = sketch;
9696
this.file = file;
97-
this.primary = primary;
97+
FileUtils.SplitFile split = FileUtils.splitFilename(file);
98+
this.primary = split.basename.equals(sketch.getFolder().getName())
99+
&& Sketch.SKETCH_EXTENSIONS.contains(split.extension);
98100
}
99101

100102
/**

0 commit comments

Comments
 (0)