diff --git a/app/src/cc/arduino/view/findreplace/FindReplace.java b/app/src/cc/arduino/view/findreplace/FindReplace.java index 81891ab1b..b585fe0dd 100644 --- a/app/src/cc/arduino/view/findreplace/FindReplace.java +++ b/app/src/cc/arduino/view/findreplace/FindReplace.java @@ -327,10 +327,10 @@ public class FindReplace extends javax.swing.JFrame { if (nextIndex == -1) { // Nothing found on this tab: Search other tabs if required if (searchTabs) { - // editor. + int numTabs = editor.getTabs().size(); Sketch sketch = editor.getSketch(); - if (sketch.getCodeCount() > 1) { - int realCurrentTab = sketch.getCodeIndex(sketch.getCurrentCode()); + if (numTabs > 1) { + int realCurrentTab = editor.getCurrentTabIndex(); if (originTab != realCurrentTab) { if (originTab < 0) { @@ -338,7 +338,8 @@ public class FindReplace extends javax.swing.JFrame { } if (!wrap) { - if ((!backwards && realCurrentTab + 1 >= sketch.getCodeCount()) || (backwards && realCurrentTab - 1 < 0)) { + if ((!backwards && realCurrentTab + 1 >= numTabs) + || (backwards && realCurrentTab - 1 < 0)) { return false; // Can't continue without wrap } } diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 414a8fe78..f183c11ef 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -1574,6 +1574,21 @@ public class Editor extends JFrame implements RunnerListener { public EditorTab getCurrentTab() { return tabs.get(currentTabIndex); } + + /** + * Gets the index of the currently displaying tab. + */ + public int getCurrentTabIndex() { + return currentTabIndex; + } + + /** + * Returns an (unmodifiable) list of currently opened tabs. + */ + public List getTabs() { + return Collections.unmodifiableList(tabs); + } + // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . /** * Change the currently displayed tab. @@ -1962,10 +1977,12 @@ public class Editor extends JFrame implements RunnerListener { if (sketch == null) { return; } - if (sketch.getName().equals(sketch.getCurrentCode().getPrettyName())) { + SketchCode current = getCurrentTab().getSketchCode(); + if (sketch.getName().equals(current.getPrettyName())) { setTitle(I18n.format(tr("{0} | Arduino {1}"), sketch.getName(), BaseNoGui.VERSION_NAME_LONG)); } else { - setTitle(I18n.format(tr("{0} - {1} | Arduino {2}"), sketch.getName(), sketch.getCurrentCode().getFileName(), BaseNoGui.VERSION_NAME_LONG)); + setTitle(I18n.format(tr("{0} - {1} | Arduino {2}"), sketch.getName(), + current.getFileName(), BaseNoGui.VERSION_NAME_LONG)); } } @@ -2591,7 +2608,7 @@ public class Editor extends JFrame implements RunnerListener { printerJob.setPrintable(getCurrentTab().getTextArea()); } // set the name of the job to the code name - printerJob.setJobName(sketch.getCurrentCode().getPrettyName()); + printerJob.setJobName(getCurrentTab().getSketchCode().getPrettyName()); if (printerJob.printDialog()) { try { diff --git a/app/src/processing/app/EditorHeader.java b/app/src/processing/app/EditorHeader.java index 37ac14b56..b9d9e778e 100644 --- a/app/src/processing/app/EditorHeader.java +++ b/app/src/processing/app/EditorHeader.java @@ -32,7 +32,7 @@ import static processing.app.I18n.tr; import java.awt.*; import java.awt.event.*; import java.io.IOException; - +import java.util.List; import javax.swing.*; import static processing.app.Theme.scale; @@ -235,15 +235,18 @@ public class EditorHeader extends JComponent { g.setColor(backgroundColor); g.fillRect(0, 0, imageW, imageH); - int codeCount = sketch.getCodeCount(); + List tabs = editor.getTabs(); + + int codeCount = tabs.size(); if ((tabLeft == null) || (tabLeft.length < codeCount)) { tabLeft = new int[codeCount]; tabRight = new int[codeCount]; } int x = scale(6); // offset from left edge of the component - for (int i = 0; i < sketch.getCodeCount(); i++) { - SketchCode code = sketch.getCode(i); + int i = 0; + for (EditorTab tab : tabs) { + SketchCode code = tab.getSketchCode(); String codeName = code.isExtension(sketch.getHiddenExtensions()) ? code.getPrettyName() : code.getFileName(); @@ -257,7 +260,7 @@ public class EditorHeader extends JComponent { int pieceCount = 2 + (textWidth / PIECE_WIDTH); int pieceWidth = pieceCount * PIECE_WIDTH; - int state = (code == sketch.getCurrentCode()) ? SELECTED : UNSELECTED; + int state = (i == editor.getCurrentTabIndex()) ? SELECTED : UNSELECTED; g.drawImage(pieces[state][LEFT], x, 0, null); x += PIECE_WIDTH; @@ -277,6 +280,7 @@ public class EditorHeader extends JComponent { g.drawImage(pieces[state][RIGHT], x, 0, null); x += PIECE_WIDTH - 1; // overlap by 1 pixel + i++; } menuLeft = sizeW - (16 + menuButtons[0].getWidth(this)); @@ -323,7 +327,8 @@ public class EditorHeader extends JComponent { if (sketch != null) { menu.addSeparator(); int i = 0; - for (SketchCode code : sketch.getCodes()) { + for (EditorTab tab : editor.getTabs()) { + SketchCode code = tab.getSketchCode(); final int index = i++; item = new JMenuItem(code.isExtension(sketch.getDefaultExtension()) ? code.getPrettyName() : code.getFileName());