matthiasblaesing commented on a change in pull request #1015: [NETBEANS-1622]
Sort editor tabs when a document opens
URL:
https://github.com/apache/incubator-netbeans/pull/1015#discussion_r233135646
##########
File path:
platform/core.windows/src/org/netbeans/core/windows/model/DefaultModeModel.java
##########
@@ -142,6 +146,10 @@ public void insertOpenedTopComponent(TopComponent tc, int
index) {
}
private void sortOpenedTopComponents() {
+ if (getKind() == Constants.MODE_KIND_EDITOR) {
Review comment:
The if-cascade with early returns makes the function more complex then
necessary. I suggest to change it to:
```java
private void sortOpenedTopComponents() {
if (getKind() == Constants.MODE_KIND_EDITOR) {
sortByFile(getSortType());
} else if( getKind() == Constants.MODE_KIND_SLIDING &&
Switches.isModeSlidingEnabled()) {
WindowManagerImpl wm = WindowManagerImpl.getInstance();
List<TopComponent> opened =
topComponentSubModel.getOpenedTopComponents();
final List<String> prevModes = new
ArrayList<String>(opened.size());
final Map<TopComponent, String> tc2modeName = new
HashMap<TopComponent, String>(opened.size());
for (TopComponent tc : opened) {
String tcId = wm.findTopComponentID(tc);
if (null == tcId) {
continue;
}
ModeImpl prevMode = getTopComponentPreviousMode(tcId);
if (null == prevMode) {
continue;
}
if (!prevModes.contains(prevMode.getName())) {
prevModes.add(prevMode.getName());
}
tc2modeName.put(tc, prevMode.getName());
}
if (prevModes.isEmpty()) {
return; //nothing to sort by (shouldn't really happen)
}
Collections.sort(opened, new Comparator<TopComponent>() {
@Override
public int compare(TopComponent o1, TopComponent o2) {
String mode1 = tc2modeName.get(o1);
String mode2 = tc2modeName.get(o2);
if (null == mode1 && null != mode2) {
return 1;
} else if (null != mode1 && null == mode2) {
return -1;
}
return prevModes.indexOf(mode1) -
prevModes.indexOf(mode2);
}
});
topComponentSubModel.setOpenedTopComponents(opened);
}
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists