diff --git a/platform/platform-api/src/com/intellij/ui/tabs/impl/JBEditorTabs.java b/platform/platform-api/src/com/intellij/ui/tabs/impl/JBEditorTabs.java index 120651799e70..9a7202125242 100644 --- a/platform/platform-api/src/com/intellij/ui/tabs/impl/JBEditorTabs.java +++ b/platform/platform-api/src/com/intellij/ui/tabs/impl/JBEditorTabs.java @@ -19,6 +19,7 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.ActionManager; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.wm.IdeFocusManager; import com.intellij.ui.ColorUtil; import com.intellij.ui.tabs.JBTabsPosition; @@ -39,6 +40,7 @@ import java.util.List; * @author pegov */ public class JBEditorTabs extends JBTabsImpl { + private static final String TABS_ALPHABETICAL_KEY = "tabs.alphabetical"; public JBEditorTabs(@Nullable Project project, ActionManager actionManager, IdeFocusManager focusManager, @NotNull Disposable parent) { super(project, actionManager, focusManager, parent); @@ -113,7 +115,15 @@ public class JBEditorTabs extends JBTabsImpl { g2d.setColor(new Color(255, 255, 255, 100)); g2d.drawRect(_x, _y, _width - 1, _height - 1); } - + + public static boolean isAlphabeticalMode() { + return Registry.is(TABS_ALPHABETICAL_KEY); + } + + public static void setAlphabeticalMode(boolean on) { + Registry.get(TABS_ALPHABETICAL_KEY).setValue(on); + } + private static Color multiplyColor(Color c) { return new Color(c.getRed() * c.getRed() / 255, c.getGreen() * c.getGreen() / 255, c.getBlue() * c.getBlue() / 255); } diff --git a/platform/platform-api/src/com/intellij/ui/tabs/impl/singleRow/SingleRowLayout.java b/platform/platform-api/src/com/intellij/ui/tabs/impl/singleRow/SingleRowLayout.java index 8e8956e5bc65..75b2980cedcb 100644 --- a/platform/platform-api/src/com/intellij/ui/tabs/impl/singleRow/SingleRowLayout.java +++ b/platform/platform-api/src/com/intellij/ui/tabs/impl/singleRow/SingleRowLayout.java @@ -15,6 +15,7 @@ */ 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.TabsUtil; @@ -25,6 +26,8 @@ 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 { @@ -140,6 +143,15 @@ public class SingleRowLayout extends TabLayout { } public LayoutPassInfo layoutSingleRow(List visibleInfos) { + if (JBEditorTabs.isAlphabeticalMode()) { + Collections.sort(visibleInfos, new Comparator() { + @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); @@ -147,13 +159,11 @@ public class SingleRowLayout extends TabLayout { data = myLastSingRowLayout; } - final TabInfo selected = myTabs.getSelectedInfo(); prepareLayoutPassInfo(data, selected); myTabs.resetLayout(layoutLabels || myTabs.isHideTabs()); - if (layoutLabels && !myTabs.isHideTabs()) { data.position = getStrategy().getStartPosition(data) - getScrollOffset(); diff --git a/platform/platform-impl/src/com/intellij/ide/actions/TabsAlphabeticalModeSwitcher.java b/platform/platform-impl/src/com/intellij/ide/actions/TabsAlphabeticalModeSwitcher.java new file mode 100644 index 000000000000..8431364c5d61 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ide/actions/TabsAlphabeticalModeSwitcher.java @@ -0,0 +1,47 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.ide.actions; + +import com.intellij.ide.ui.UISettings; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.ToggleAction; +import com.intellij.ui.tabs.impl.JBEditorTabs; + +import javax.swing.*; + +/** + * @author Konstantin Bulenkov + */ +public class TabsAlphabeticalModeSwitcher extends ToggleAction { + @Override + public boolean isSelected(AnActionEvent e) { + return JBEditorTabs.isAlphabeticalMode(); + } + + @Override + public void setSelected(AnActionEvent e, boolean state) { + JBEditorTabs.setAlphabeticalMode(state); + } + + @Override + public void update(AnActionEvent e) { + super.update(e); + final int place = UISettings.getInstance().EDITOR_TAB_PLACEMENT; + e.getPresentation().setEnabled(UISettings.getInstance().SCROLL_TAB_LAYOUT_IN_EDITOR + || place == SwingConstants.LEFT + || place == SwingConstants.RIGHT); + } +} diff --git a/platform/platform-resources-en/src/misc/registry.properties b/platform/platform-resources-en/src/misc/registry.properties index 9cc2b1759cf7..8fc3a6e2adf9 100644 --- a/platform/platform-resources-en/src/misc/registry.properties +++ b/platform/platform-resources-en/src/misc/registry.properties @@ -258,3 +258,4 @@ dark.laf.available=true actionSystem.force.alt.gr=false completion.show.intention.icon=true +tabs.alphabetical=false diff --git a/platform/platform-resources/src/idea/PlatformActions.xml b/platform/platform-resources/src/idea/PlatformActions.xml index 518110f6a040..8a15a24d37ec 100644 --- a/platform/platform-resources/src/idea/PlatformActions.xml +++ b/platform/platform-resources/src/idea/PlatformActions.xml @@ -346,6 +346,7 @@ + @@ -436,6 +437,7 @@ +