action to show list of all tabs from keyboard (IDEA-81685)

This commit is contained in:
Dmitry Jemerov
2012-02-21 20:37:54 +01:00
parent 7edc3e605b
commit 3bfa520cbb
5 changed files with 75 additions and 5 deletions
@@ -64,7 +64,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
public class JBTabsImpl extends JComponent
implements JBTabs, PropertyChangeListener, TimerListener, DataProvider, PopupMenuListener, Disposable, JBTabsPresentation, Queryable, QuickActionProvider {
static DataKey<JBTabsImpl> NAVIGATION_ACTIONS_KEY = DataKey.create("JBTabs");
public static DataKey<JBTabsImpl> NAVIGATION_ACTIONS_KEY = DataKey.create("JBTabs");
public static final String EDITOR_TABS = "main.editor.tabs";
public static final Color MAC_AQUA_BG_COLOR = Gray._200;
@@ -518,13 +518,22 @@ public class JBTabsImpl extends JComponent
}
}
private void showMorePopup(final MouseEvent e) {
public boolean canShowMorePopup() {
final SingleRowPassInfo lastLayout = mySingleRowLayout.myLastSingRowLayout;
return lastLayout != null && lastLayout.moreRect != null;
}
public void showMorePopup(@Nullable final MouseEvent e) {
final SingleRowPassInfo lastLayout = mySingleRowLayout.myLastSingRowLayout;
if (lastLayout == null) {
return;
}
mySingleRowLayout.myMorePopup = new JPopupMenu();
for (final TabInfo each : myVisibleInfos) {
final JCheckBoxMenuItem item = new JCheckBoxMenuItem(each.getText());
Color color = UIManager.getColor("MenuItem.background");
if (color != null) {
if (mySingleRowLayout.myLastSingRowLayout.toDrop.contains(each)) {
if (lastLayout.toDrop.contains(each)) {
color = new Color((int) (color.getRed() * 0.85f), (int) (color.getGreen() * 0.85f), (int) (color.getBlue() * 0.85f));
}
@@ -555,7 +564,15 @@ public class JBTabsImpl extends JComponent
}
});
mySingleRowLayout.myMorePopup.show(this, e.getX(), e.getY());
if (e != null) {
mySingleRowLayout.myMorePopup.show(this, e.getX(), e.getY());
}
else {
final Rectangle rect = lastLayout.moreRect;
if (rect != null) {
mySingleRowLayout.myMorePopup.show(this, rect.x, rect.y+rect.height);
}
}
}
@@ -0,0 +1,48 @@
/*
* 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.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.ui.tabs.impl.JBTabsImpl;
/**
* Shows the popup of all tabs when single row editor tab layout is used and all tabs don't fit on the screen.
*
* @author yole
*/
public class TabListAction extends AnAction {
@Override
public void actionPerformed(AnActionEvent e) {
JBTabsImpl tabs = e.getData(JBTabsImpl.NAVIGATION_ACTIONS_KEY);
if (tabs != null) {
tabs.showMorePopup(null);
}
}
@Override
public void update(AnActionEvent e) {
e.getPresentation().setEnabled(isTabListAvailable(e));
}
private static boolean isTabListAvailable(AnActionEvent e) {
JBTabsImpl tabs = e.getData(JBTabsImpl.NAVIGATION_ACTIONS_KEY);
if (tabs == null || !tabs.isEditorTabs()) {
return false;
}
return tabs.canShowMorePopup();
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* 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.
@@ -464,6 +464,7 @@ public class EditorWindow {
return myPanel.getSize();
}
@Nullable
public EditorTabbedContainer getTabbedPane() {
return myTabbedPane;
}
@@ -1309,3 +1309,6 @@ action.Images.ShowThumbnails.description=Show thumbnails view for current direct
action.Diff.UpdatedFiles.text=Show Diff
action.Diff.UpdatedFiles.description=Show diff with version before update
action.TabList.text=Show All Tabs
action.TabList.description=Show dropdown with the list of all tabs in single-row tab layout
@@ -320,6 +320,7 @@
<action id="PreviousTab" class="com.intellij.ide.actions.PreviousTabAction"/>
<action id="CloseActiveTab" class="com.intellij.ide.actions.CloseActiveTabAction"/>
<action id="PinActiveTab" class="com.intellij.ide.actions.PinActiveTabAction"/>
<action id="TabList" class="com.intellij.ide.actions.TabListAction"/>
<separator/>
<group id="CloseEditorsGroup">
<action id="CloseContent" class="com.intellij.ide.actions.CloseAction"/>