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.
This commit is contained in:
Matthijs Kooijman 2015-12-29 17:11:30 +01:00 committed by Martino Facchin
parent 1d15c434dc
commit c4e77a7c3c
2 changed files with 6 additions and 6 deletions

View File

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

View File

@ -91,10 +91,12 @@ public class SketchFile {
* @param primary
* Whether this file is the primary file of the sketch
*/
public SketchFile(Sketch sketch, File file, boolean primary) {
public SketchFile(Sketch sketch, File file) {
this.sketch = sketch;
this.file = file;
this.primary = primary;
FileUtils.SplitFile split = FileUtils.splitFilename(file);
this.primary = split.basename.equals(sketch.getFolder().getName())
&& Sketch.SKETCH_EXTENSIONS.contains(split.extension);
}
/**