1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-03-13 10:29:35 +01:00

Reorder tabs when a new file is inserted/renamed

Fixes #5402
This commit is contained in:
Martino Facchin 2016-10-27 11:54:12 +02:00
parent 4e84238527
commit c6642c1bd2
2 changed files with 19 additions and 0 deletions

View File

@ -1691,6 +1691,24 @@ public class Editor extends JFrame implements RunnerListener {
selectTab(0);
}
private static final Comparator<EditorTab> CODE_DOCS_COMPARATOR = new Comparator<EditorTab>() {
@Override
public int compare(EditorTab x, EditorTab y) {
if (x.getSketchFile().isPrimary() && !y.getSketchFile().isPrimary())
return -1;
if (y.getSketchFile().isPrimary() && !x.getSketchFile().isPrimary())
return 1;
return x.getSketchFile().getFileName().compareTo(y.getSketchFile().getFileName());
}
};
/**
* Reorders tabs as per current sketch's files order
*/
public void reorderTabs() {
Collections.sort(tabs, CODE_DOCS_COMPARATOR);
}
/**
* Add a new tab.
*

View File

@ -323,6 +323,7 @@ public class EditorHeader extends JComponent {
if (sketch != null) {
menu.addSeparator();
editor.reorderTabs();
int i = 0;
for (EditorTab tab : editor.getTabs()) {
SketchFile file = tab.getSketchFile();