From 3bfa520cbbb5179d46deee4ca19e387fbae8c17f Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 21 Feb 2012 20:37:54 +0100 Subject: [PATCH] action to show list of all tabs from keyboard (IDEA-81685) --- .../com/intellij/ui/tabs/impl/JBTabsImpl.java | 25 ++++++++-- .../intellij/ide/actions/TabListAction.java | 48 +++++++++++++++++++ .../openapi/fileEditor/impl/EditorWindow.java | 3 +- .../src/messages/ActionsBundle.properties | 3 ++ .../src/idea/PlatformActions.xml | 1 + 5 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 platform/platform-impl/src/com/intellij/ide/actions/TabListAction.java diff --git a/platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsImpl.java b/platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsImpl.java index a5f519ecf09e..d7db0511d9e8 100644 --- a/platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsImpl.java +++ b/platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsImpl.java @@ -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 NAVIGATION_ACTIONS_KEY = DataKey.create("JBTabs"); + public static DataKey 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); + } + } } diff --git a/platform/platform-impl/src/com/intellij/ide/actions/TabListAction.java b/platform/platform-impl/src/com/intellij/ide/actions/TabListAction.java new file mode 100644 index 000000000000..a91f5bbc13fc --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ide/actions/TabListAction.java @@ -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(); + } +} diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorWindow.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorWindow.java index 0f1e765f909b..7e39542cf1fc 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorWindow.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorWindow.java @@ -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; } diff --git a/platform/platform-resources-en/src/messages/ActionsBundle.properties b/platform/platform-resources-en/src/messages/ActionsBundle.properties index a5150687296c..33cb7db819ff 100644 --- a/platform/platform-resources-en/src/messages/ActionsBundle.properties +++ b/platform/platform-resources-en/src/messages/ActionsBundle.properties @@ -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 diff --git a/platform/platform-resources/src/idea/PlatformActions.xml b/platform/platform-resources/src/idea/PlatformActions.xml index d0f904632b35..ea6c38ec027d 100644 --- a/platform/platform-resources/src/idea/PlatformActions.xml +++ b/platform/platform-resources/src/idea/PlatformActions.xml @@ -320,6 +320,7 @@ +