Skip to content

Commit c85027f

Browse files
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 8b43317 commit c85027f

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
@@ -2024,7 +2024,7 @@ private void updateTitle() {
20242024
return;
20252025
}
20262026
SketchCode current = getCurrentTab().getSketchCode();
2027-
if (sketch.getName().equals(current.getPrettyName())) {
2027+
if (current.isPrimary()) {
20282028
setTitle(I18n.format(tr("{0} | Arduino {1}"), sketch.getName(),
20292029
BaseNoGui.VERSION_NAME_LONG));
20302030
} else {

app/src/processing/app/SketchController.java

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

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

0 commit comments

Comments
 (0)