Skip to content

Commit 74e5228

Browse files
matthijskooijmanfacchinm
authored andcommitted
Let SketchFile store a reference to the Sketch it belongs to
This allows simplifying some other things later.
1 parent b28f1a4 commit 74e5228

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private List<SketchFile> listSketchFiles(boolean showWarnings) throws IOExceptio
105105
if (BaseNoGui.isSanitaryName(file.getName())) {
106106
FileUtils.SplitFile split = FileUtils.splitFilename(file);
107107
boolean isPrimary = split.basename.equals(folder.getName()) && SKETCH_EXTENSIONS.contains(split.extension);
108-
result.add(new SketchFile(file, isPrimary));
108+
result.add(new SketchFile(this, file, isPrimary));
109109
} else if (showWarnings) {
110110
System.err.println(I18n.format(tr("File name {0} is invalid: ignored"), file.getName()));
111111
}
@@ -305,7 +305,7 @@ public SketchFile addFile(String newName) throws IOException {
305305
checkNewFilename(newFile);
306306

307307
// Add a new sketchFile
308-
SketchFile sketchFile = new SketchFile(newFile, false);
308+
SketchFile sketchFile = new SketchFile(this, newFile, false);
309309
files.add(sketchFile);
310310
Collections.sort(files, CODE_DOCS_COMPARATOR);
311311

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ public class SketchFile {
4545
*/
4646
private File file;
4747

48+
/**
49+
* The sketch this file belongs to.
50+
*/
51+
private Sketch sketch;
52+
4853
/**
4954
* Is this the primary file in the sketch?
5055
*/
@@ -79,12 +84,15 @@ public static interface TextStorage {
7984
/**
8085
* Create a new SketchFile
8186
*
87+
* @param sketch
88+
* The sketch this file belongs to
8289
* @param file
8390
* The file this SketchFile represents
8491
* @param primary
8592
* Whether this file is the primary file of the sketch
8693
*/
87-
public SketchFile(File file, boolean primary) {
94+
public SketchFile(Sketch sketch, File file, boolean primary) {
95+
this.sketch = sketch;
8896
this.file = file;
8997
this.primary = primary;
9098
}

0 commit comments

Comments
 (0)