Do not store the sketch name in Sketch

Sketch already stores the sketch folder, and the sketch name should be
identical to the folder name. In the case where the filename passed to
the sketch constructor is not the primary .ino file (named after the
sketch), this will slightly change behaviour. However, the calling code
should prevent this from happening, and with the old code, some internal
assumptions were probably violated, so this changes makes handling this
situation a bit more robust.

Since the actual filename passed to Sketch is no longer used, it is no
longer required to pass the name of the primary .ino file. At some
point, the constructor should probably be changed to accept a folder
name instead of a filename, but that would require a lot of changes
to trace this back through the code, so this is something for later.
This commit is contained in:
Matthijs Kooijman 2015-12-18 16:27:16 +01:00 committed by Martino Facchin
parent 7a73d0b3db
commit 0c62ac8985
1 changed files with 2 additions and 14 deletions

View File

@ -25,12 +25,6 @@ public class Sketch {
*/
private File folder;
/**
* Name of sketch, which is the name of main file (without .pde or .java
* extension)
*/
private String name;
private List<SketchFile> files = new ArrayList<SketchFile>();
private static final Comparator<SketchFile> CODE_DOCS_COMPARATOR = new Comparator<SketchFile>() {
@ -49,15 +43,9 @@ public class Sketch {
* on disk to get populate the list of files in this sketch.
*
* @param file
* The primary file for this sketch.
* Any file inside the sketch directory.
*/
Sketch(File file) throws IOException {
// get the name of the sketch by chopping .pde or .java
// off of the main file name
String mainFilename = primaryFile.getName();
int suffixLength = getDefaultExtension().length() + 1;
name = mainFilename.substring(0, mainFilename.length() - suffixLength);
folder = new File(file.getParent());
files = listSketchFiles(true);
}
@ -195,7 +183,7 @@ public class Sketch {
}
public String getName() {
return name;
return folder.getName();
}
public File getFolder() {