Skip to content

Commit 3d573a7

Browse files
matthijskooijmanfacchinm
authored andcommitted
Use SketchCode.isPrimary() in more places
This should be more reliable than comparing filenames or assuming the primary file is always at index 0.
1 parent dd5c178 commit 3d573a7

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

app/src/processing/app/Editor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2016,7 +2016,7 @@ private void updateTitle() {
20162016
return;
20172017
}
20182018
SketchCode current = getCurrentTab().getSketchCode();
2019-
if (sketch.getName().equals(current.getPrettyName())) {
2019+
if (current.isPrimary()) {
20202020
setTitle(I18n.format(tr("{0} | Arduino {1}"), sketch.getName(),
20212021
BaseNoGui.VERSION_NAME_LONG));
20222022
} else {

app/src/processing/app/SketchController.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ protected void nameCode(String newName) {
181181
// Don't let the user create the main tab as a .java file instead of .pde
182182
if (!isDefaultExtension(newExtension)) {
183183
if (renamingCode) { // If creating a new tab, don't show this error
184-
if (current == sketch.getCode(0)) { // If this is the main tab, disallow
184+
if (current.isPrimary()) { // If this is the main tab, disallow
185185
Base.showWarning(tr("Problem with rename"),
186186
tr("The main file can't use an extension.\n" +
187187
"(It may be time for your to graduate to a\n" +
@@ -572,9 +572,8 @@ protected boolean saveAs() throws IOException {
572572
// make sure there doesn't exist a .cpp file with that name already
573573
// but ignore this situation for the first tab, since it's probably being
574574
// resaved (with the same name) to another location/folder.
575-
for (int i = 1; i < sketch.getCodeCount(); i++) {
576-
SketchCode code = sketch.getCode(i);
577-
if (newName.equalsIgnoreCase(code.getPrettyName())) {
575+
for (SketchCode code : sketch.getCodes()) {
576+
if (!code.isPrimary() && newName.equalsIgnoreCase(code.getPrettyName())) {
578577
Base.showMessage(tr("Error"),
579578
I18n.format(tr("You can't save the sketch as \"{0}\"\n" +
580579
"because the sketch already has a file with that name."), newName
@@ -619,7 +618,7 @@ protected boolean saveAs() throws IOException {
619618

620619
// save the other tabs to their new location
621620
for (SketchCode code : sketch.getCodes()) {
622-
if (sketch.indexOfCode(code) == 0) continue;
621+
if (code.isPrimary()) continue;
623622
File newFile = new File(newFolder, code.getFileName());
624623
code.saveAs(newFile);
625624
}

0 commit comments

Comments
 (0)