Skip to content

Commit c6642c1

Browse files
committed
Reorder tabs when a new file is inserted/renamed
Fixes #5402
1 parent 4e84238 commit c6642c1

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

app/src/processing/app/Editor.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,6 +1691,24 @@ public void createTabs() {
16911691
selectTab(0);
16921692
}
16931693

1694+
private static final Comparator<EditorTab> CODE_DOCS_COMPARATOR = new Comparator<EditorTab>() {
1695+
@Override
1696+
public int compare(EditorTab x, EditorTab y) {
1697+
if (x.getSketchFile().isPrimary() && !y.getSketchFile().isPrimary())
1698+
return -1;
1699+
if (y.getSketchFile().isPrimary() && !x.getSketchFile().isPrimary())
1700+
return 1;
1701+
return x.getSketchFile().getFileName().compareTo(y.getSketchFile().getFileName());
1702+
}
1703+
};
1704+
1705+
/**
1706+
* Reorders tabs as per current sketch's files order
1707+
*/
1708+
public void reorderTabs() {
1709+
Collections.sort(tabs, CODE_DOCS_COMPARATOR);
1710+
}
1711+
16941712
/**
16951713
* Add a new tab.
16961714
*

app/src/processing/app/EditorHeader.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ public void rebuildMenu() {
323323
if (sketch != null) {
324324
menu.addSeparator();
325325

326+
editor.reorderTabs();
326327
int i = 0;
327328
for (EditorTab tab : editor.getTabs()) {
328329
SketchFile file = tab.getSketchFile();

0 commit comments

Comments
 (0)