IDEA-89035 File Tab Alphabetical

This commit is contained in:
Konstantin Bulenkov
2012-08-03 01:03:35 +02:00
parent f76801f06e
commit 4bf2fd564a
5 changed files with 73 additions and 3 deletions
@@ -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);
}
@@ -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<TabInfo> visibleInfos) {
if (JBEditorTabs.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);
@@ -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();
@@ -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);
}
}
@@ -258,3 +258,4 @@ dark.laf.available=true
actionSystem.force.alt.gr=false
completion.show.intention.icon=true
tabs.alphabetical=false
@@ -346,6 +346,7 @@
<action id="TabsPlacementLeft" text="Left" class="com.intellij.ide.actions.TabsPlacementAction$Left" />
<action id="TabsPlacementRight" text="Right" class="com.intellij.ide.actions.TabsPlacementAction$Right" />
</group>
<action id="TabsAlphabeticalMode" class="com.intellij.ide.actions.TabsAlphabeticalModeSwitcher" text="Alphabetical Mode"/>
</group>
<group id="BackgroundTasks" popup="true">
@@ -436,6 +437,7 @@
<reference ref="ChangeSplitOrientation"/>
<reference ref="PinActiveTab"/>
<reference ref="TabsPlacementGroup"/>
<reference ref="TabsAlphabeticalMode"/>
<separator/>
<reference ref="NextTab"/>
<reference ref="PreviousTab"/>