1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-10 21:24:12 +01:00

Let SketchFile store a reference to the Sketch it belongs to

This allows simplifying some other things later.
This commit is contained in:
Matthijs Kooijman 2015-12-29 16:42:14 +01:00 committed by Martino Facchin
parent b28f1a479d
commit 74e5228a0f
2 changed files with 11 additions and 3 deletions

View File

@ -105,7 +105,7 @@ public class Sketch {
if (BaseNoGui.isSanitaryName(file.getName())) { if (BaseNoGui.isSanitaryName(file.getName())) {
FileUtils.SplitFile split = FileUtils.splitFilename(file); FileUtils.SplitFile split = FileUtils.splitFilename(file);
boolean isPrimary = split.basename.equals(folder.getName()) && SKETCH_EXTENSIONS.contains(split.extension); boolean isPrimary = split.basename.equals(folder.getName()) && SKETCH_EXTENSIONS.contains(split.extension);
result.add(new SketchFile(file, isPrimary)); result.add(new SketchFile(this, file, isPrimary));
} else if (showWarnings) { } else if (showWarnings) {
System.err.println(I18n.format(tr("File name {0} is invalid: ignored"), file.getName())); System.err.println(I18n.format(tr("File name {0} is invalid: ignored"), file.getName()));
} }
@ -305,7 +305,7 @@ public class Sketch {
checkNewFilename(newFile); checkNewFilename(newFile);
// Add a new sketchFile // Add a new sketchFile
SketchFile sketchFile = new SketchFile(newFile, false); SketchFile sketchFile = new SketchFile(this, newFile, false);
files.add(sketchFile); files.add(sketchFile);
Collections.sort(files, CODE_DOCS_COMPARATOR); Collections.sort(files, CODE_DOCS_COMPARATOR);

View File

@ -45,6 +45,11 @@ public class SketchFile {
*/ */
private File file; private File file;
/**
* The sketch this file belongs to.
*/
private Sketch sketch;
/** /**
* Is this the primary file in the sketch? * Is this the primary file in the sketch?
*/ */
@ -79,12 +84,15 @@ public class SketchFile {
/** /**
* Create a new SketchFile * Create a new SketchFile
* *
* @param sketch
* The sketch this file belongs to
* @param file * @param file
* The file this SketchFile represents * The file this SketchFile represents
* @param primary * @param primary
* Whether this file is the primary file of the sketch * Whether this file is the primary file of the sketch
*/ */
public SketchFile(File file, boolean primary) { public SketchFile(Sketch sketch, File file, boolean primary) {
this.sketch = sketch;
this.file = file; this.file = file;
this.primary = primary; this.primary = primary;
} }