mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-06 06:21:16 +07:00
IDEA-90597 Next Tab/Previous Tab work incorrectly when Alphabetical mode is enabled.
This commit is contained in:
@@ -22,7 +22,8 @@ import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.util.registry.RegistryValue;
|
||||
import com.intellij.openapi.util.registry.RegistryValueListener;
|
||||
import com.intellij.openapi.wm.IdeFocusManager;
|
||||
import com.intellij.ui.Gray;
|
||||
import com.intellij.ui.JBColor;
|
||||
@@ -37,8 +38,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -52,6 +51,19 @@ public class JBEditorTabs extends JBTabsImpl {
|
||||
|
||||
public JBEditorTabs(@Nullable Project project, @NotNull ActionManager actionManager, IdeFocusManager focusManager, @NotNull Disposable parent) {
|
||||
super(project, actionManager, focusManager, parent);
|
||||
Registry.get(TABS_ALPHABETICAL_KEY).addListener(new RegistryValueListener.Adapter() {
|
||||
|
||||
@Override
|
||||
public void afterValueChanged(RegistryValue value) {
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
resetTabsCache();
|
||||
relayout(true, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -171,14 +183,6 @@ public class JBEditorTabs extends JBTabsImpl {
|
||||
@Override
|
||||
protected void doPaintBackground(Graphics2D g2d, Rectangle clip) {
|
||||
List<TabInfo> visibleInfos = getVisibleInfos();
|
||||
if (isAlphabeticalMode()) {
|
||||
Collections.sort(visibleInfos, new Comparator<TabInfo>() {
|
||||
@Override
|
||||
public int compare(TabInfo o1, TabInfo o2) {
|
||||
return StringUtil.naturalCompare(o1.getText(), o2.getText());
|
||||
}
|
||||
});
|
||||
}
|
||||
final boolean vertical = getTabsPosition() == JBTabsPosition.left || getTabsPosition() == JBTabsPosition.right;
|
||||
|
||||
Insets insets = getTabsBorder().getEffectiveBorder();
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.*;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.wm.*;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
@@ -67,6 +68,12 @@ public class JBTabsImpl extends JComponent
|
||||
public static final DataKey<JBTabsImpl> NAVIGATION_ACTIONS_KEY = DataKey.create("JBTabs");
|
||||
|
||||
public static final Color MAC_AQUA_BG_COLOR = Gray._200;
|
||||
private static final Comparator<TabInfo> ABC_COMPARATOR = new Comparator<TabInfo>() {
|
||||
@Override
|
||||
public int compare(TabInfo o1, TabInfo o2) {
|
||||
return StringUtil.naturalCompare(o1.getText(), o2.getText());
|
||||
}
|
||||
};
|
||||
|
||||
@NotNull final ActionManager myActionManager;
|
||||
private final List<TabInfo> myVisibleInfos = new ArrayList<TabInfo>();
|
||||
@@ -424,7 +431,7 @@ public class JBTabsImpl extends JComponent
|
||||
myTabListeners.clear();
|
||||
}
|
||||
|
||||
void resetTabsCache() {
|
||||
protected void resetTabsCache() {
|
||||
myAllTabs = null;
|
||||
}
|
||||
|
||||
@@ -1296,14 +1303,15 @@ public class JBTabsImpl extends JComponent
|
||||
private TabInfo findEnabledForward(int from, boolean cycle) {
|
||||
if (from < 0) return null;
|
||||
int index = from;
|
||||
List<TabInfo> infos = getVisibleInfos();
|
||||
while (true) {
|
||||
index++;
|
||||
if (index == myVisibleInfos.size()) {
|
||||
if (index == infos.size()) {
|
||||
if (!cycle) break;
|
||||
index = 0;
|
||||
}
|
||||
if (index == from) break;
|
||||
final TabInfo each = myVisibleInfos.get(index);
|
||||
final TabInfo each = infos.get(index);
|
||||
if (each.isEnabled()) return each;
|
||||
}
|
||||
|
||||
@@ -1318,14 +1326,15 @@ public class JBTabsImpl extends JComponent
|
||||
private TabInfo findEnabledBackward(int from, boolean cycle) {
|
||||
if (from < 0) return null;
|
||||
int index = from;
|
||||
List<TabInfo> infos = getVisibleInfos();
|
||||
while (true) {
|
||||
index--;
|
||||
if (index == -1) {
|
||||
if (!cycle) break;
|
||||
index = myVisibleInfos.size() - 1;
|
||||
index = infos.size() - 1;
|
||||
}
|
||||
if (index == from) break;
|
||||
final TabInfo each = myVisibleInfos.get(index);
|
||||
final TabInfo each = infos.get(index);
|
||||
if (each.isEnabled()) return each;
|
||||
}
|
||||
|
||||
@@ -1352,6 +1361,9 @@ public class JBTabsImpl extends JComponent
|
||||
for (TabInfo each : myHiddenInfos.keySet()) {
|
||||
result.add(getIndexInVisibleArray(each), each);
|
||||
}
|
||||
if (isAlphabeticalMode()) {
|
||||
Collections.sort(result, ABC_COMPARATOR);
|
||||
}
|
||||
|
||||
myAllTabs = result;
|
||||
|
||||
@@ -1484,7 +1496,7 @@ public class JBTabsImpl extends JComponent
|
||||
|
||||
|
||||
List<TabInfo> visible = new ArrayList<TabInfo>();
|
||||
visible.addAll(myVisibleInfos);
|
||||
visible.addAll(getVisibleInfos());
|
||||
|
||||
if (myDropInfo != null && !visible.contains(myDropInfo) && myShowDropLocation) {
|
||||
if (getDropInfoIndex() >= 0 && getDropInfoIndex() < visible.size()) {
|
||||
@@ -2070,7 +2082,13 @@ public class JBTabsImpl extends JComponent
|
||||
}
|
||||
|
||||
protected List<TabInfo> getVisibleInfos() {
|
||||
return myVisibleInfos;
|
||||
if (!isAlphabeticalMode()) {
|
||||
return myVisibleInfos;
|
||||
} else {
|
||||
List<TabInfo> sortedCopy = new ArrayList<TabInfo>(myVisibleInfos);
|
||||
Collections.sort(sortedCopy, ABC_COMPARATOR);
|
||||
return sortedCopy;
|
||||
}
|
||||
}
|
||||
|
||||
protected LayoutPassInfo getLastLayoutPass() {
|
||||
@@ -2946,7 +2964,10 @@ public class JBTabsImpl extends JComponent
|
||||
|
||||
@Override
|
||||
protected void _actionPerformed(final AnActionEvent e, final JBTabsImpl tabs, final int selectedIndex) {
|
||||
tabs.select(tabs.findEnabledForward(selectedIndex, true), true);
|
||||
TabInfo tabInfo = tabs.findEnabledForward(selectedIndex, true);
|
||||
if (tabInfo != null) {
|
||||
tabs.select(tabInfo, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2962,7 +2983,10 @@ public class JBTabsImpl extends JComponent
|
||||
|
||||
@Override
|
||||
protected void _actionPerformed(final AnActionEvent e, final JBTabsImpl tabs, final int selectedIndex) {
|
||||
tabs.select(tabs.findEnabledBackward(selectedIndex, true), true);
|
||||
TabInfo tabInfo = tabs.findEnabledBackward(selectedIndex, true);
|
||||
if (tabInfo != null) {
|
||||
tabs.select(tabInfo, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.intellij.ui.tabs.impl.singleRow;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.tabs.JBTabsPosition;
|
||||
import com.intellij.ui.tabs.TabInfo;
|
||||
import com.intellij.ui.tabs.impl.*;
|
||||
@@ -25,8 +24,6 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class SingleRowLayout extends TabLayout {
|
||||
@@ -146,15 +143,6 @@ public class SingleRowLayout extends TabLayout {
|
||||
}
|
||||
|
||||
public LayoutPassInfo layoutSingleRow(List<TabInfo> visibleInfos) {
|
||||
if (myTabs.isAlphabeticalMode()) {
|
||||
Collections.sort(visibleInfos, new Comparator<TabInfo>() {
|
||||
@Override
|
||||
public int compare(TabInfo o1, TabInfo o2) {
|
||||
return StringUtil.naturalCompare(o1.getText(), o2.getText());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
SingleRowPassInfo data = new SingleRowPassInfo(this, visibleInfos);
|
||||
|
||||
final boolean layoutLabels = checkLayoutLabels(data);
|
||||
|
||||
Reference in New Issue
Block a user