mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
vcs: Do not show "Version Control" tool window mnemonic if "Commit" tool window is available
6c8e2b2092d252e25ad2b6131588b5f92ac243cd follow-up GitOrigin-RevId: 65977c860d3d983c685f5724c8d8548a7ffd2c13
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1b86de6fd0
commit
da0fccd5b2
@@ -13,6 +13,7 @@ import com.intellij.openapi.wm.ToolWindow;
|
||||
import com.intellij.openapi.wm.ToolWindowManager;
|
||||
import com.intellij.openapi.wm.impl.ToolWindowImpl;
|
||||
import com.intellij.ui.SizedIcon;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -25,13 +26,20 @@ import java.awt.event.KeyEvent;
|
||||
* Usually shown in View|Tool-windows sub-menu.
|
||||
* Dynamically registered in Settings|Keymap for each newly-registered tool window.
|
||||
*/
|
||||
@SuppressWarnings("ComponentNotRegistered")
|
||||
public class ActivateToolWindowAction extends DumbAwareAction {
|
||||
private final String myToolWindowId;
|
||||
|
||||
private ActivateToolWindowAction(@NotNull String toolWindowId) {
|
||||
@ApiStatus.Internal
|
||||
protected ActivateToolWindowAction(@NotNull String toolWindowId) {
|
||||
myToolWindowId = toolWindowId;
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected boolean useMnemonicFromShortcuts(@NotNull Project project) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getToolWindowId() {
|
||||
return myToolWindowId;
|
||||
@@ -111,6 +119,7 @@ public class ActivateToolWindowAction extends DumbAwareAction {
|
||||
* @param id {@code id} of tool window to be activated.
|
||||
*/
|
||||
@NonNls
|
||||
@NotNull
|
||||
public static String getActionIdForToolWindow(@NotNull String id) {
|
||||
return "Activate" + id.replaceAll(" ", "") + "ToolWindow";
|
||||
}
|
||||
@@ -121,9 +130,17 @@ public class ActivateToolWindowAction extends DumbAwareAction {
|
||||
* Mac OS X user, because Alt+digit types strange characters into the
|
||||
* editor.
|
||||
*/
|
||||
public static int getMnemonicForToolWindow(@NotNull String id) {
|
||||
public static int getMnemonicForToolWindow(@NotNull Project project, @NotNull String toolWindowId) {
|
||||
AnAction action = ActionManager.getInstance().getAction(getActionIdForToolWindow(toolWindowId));
|
||||
boolean useMnemonicFromShortcuts =
|
||||
!(action instanceof ActivateToolWindowAction) || ((ActivateToolWindowAction)action).useMnemonicFromShortcuts(project);
|
||||
|
||||
return useMnemonicFromShortcuts ? getMnemonicFromShortcuts(toolWindowId) : -1;
|
||||
}
|
||||
|
||||
private static int getMnemonicFromShortcuts(@NotNull String toolWindowId) {
|
||||
Keymap activeKeymap = KeymapManager.getInstance().getActiveKeymap();
|
||||
for (Shortcut shortcut : activeKeymap.getShortcuts(getActionIdForToolWindow(id))) {
|
||||
for (Shortcut shortcut : activeKeymap.getShortcuts(getActionIdForToolWindow(toolWindowId))) {
|
||||
if (!(shortcut instanceof KeyboardShortcut)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.ide.actions;
|
||||
|
||||
import com.intellij.featureStatistics.FeatureUsageTracker;
|
||||
@@ -884,11 +884,11 @@ public final class Switcher extends AnAction implements DumbAware {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Map<String, ToolWindow> createShortcuts(@NotNull List<ToolWindow> windows) {
|
||||
private Map<String, ToolWindow> createShortcuts(@NotNull List<ToolWindow> windows) {
|
||||
final Map<String, ToolWindow> keymap = new HashMap<>(windows.size());
|
||||
final List<ToolWindow> otherTW = new ArrayList<>();
|
||||
for (ToolWindow window : windows) {
|
||||
int index = ActivateToolWindowAction.getMnemonicForToolWindow(((ToolWindowImpl)window).getId());
|
||||
int index = ActivateToolWindowAction.getMnemonicForToolWindow(project, ((ToolWindowImpl)window).getId());
|
||||
if (index >= '0' && index <= '9') {
|
||||
keymap.put(getIndexShortcut(index - '0'), window);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.ide.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.ActionGroup;
|
||||
@@ -16,30 +16,13 @@ import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import static java.lang.String.CASE_INSENSITIVE_ORDER;
|
||||
import static java.util.Comparator.comparingInt;
|
||||
|
||||
/**
|
||||
* @author Vladimir Kondratyev
|
||||
*/
|
||||
public final class ToolWindowsGroup extends ActionGroup implements DumbAware {
|
||||
|
||||
private static final Comparator<ActivateToolWindowAction> COMPARATOR = (a1, a2) -> {
|
||||
int m1 = ActivateToolWindowAction.getMnemonicForToolWindow(a1.getToolWindowId());
|
||||
int m2 = ActivateToolWindowAction.getMnemonicForToolWindow(a2.getToolWindowId());
|
||||
|
||||
if (m1 != -1 && m2 == -1) {
|
||||
return -1;
|
||||
}
|
||||
else if (m1 == -1 && m2 != -1) {
|
||||
return 1;
|
||||
}
|
||||
else if (m1 != -1) {
|
||||
return m1 - m2;
|
||||
}
|
||||
else {
|
||||
// Both actions have no mnemonic, therefore they are sorted alphabetically
|
||||
return a1.getToolWindowId().compareToIgnoreCase(a2.getToolWindowId());
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent e) {
|
||||
e.getPresentation().setEnabledAndVisible(getEventProject(e) != null);
|
||||
@@ -65,7 +48,20 @@ public final class ToolWindowsGroup extends ActionGroup implements DumbAware {
|
||||
result.add((ActivateToolWindowAction)action);
|
||||
}
|
||||
}
|
||||
Collections.sort(result, COMPARATOR);
|
||||
Collections.sort(result, getActionComparator(project));
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Comparator<ActivateToolWindowAction> getActionComparator(@NotNull Project project) {
|
||||
return comparingMnemonic(project).thenComparing(it -> it.getToolWindowId(), CASE_INSENSITIVE_ORDER);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Comparator<ActivateToolWindowAction> comparingMnemonic(@NotNull Project project) {
|
||||
return comparingInt(it -> {
|
||||
int mnemonic = ActivateToolWindowAction.getMnemonicForToolWindow(project, it.getToolWindowId());
|
||||
return mnemonic != -1 ? mnemonic : Integer.MAX_VALUE;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,7 +344,7 @@ public final class StripeButton extends AnchoredButton implements DataProvider {
|
||||
String text = toolWindow.getStripeTitle();
|
||||
if (UISettings.getInstance().getShowToolWindowsNumbers()) {
|
||||
String toolWindowId = toolWindow.getId();
|
||||
int mnemonic = ActivateToolWindowAction.getMnemonicForToolWindow(toolWindowId);
|
||||
int mnemonic = ActivateToolWindowAction.getMnemonicForToolWindow(toolWindow.getToolWindowManager().getProject(), toolWindowId);
|
||||
if (mnemonic != -1) {
|
||||
text = (char)mnemonic + ": " + text;
|
||||
setMnemonic2(mnemonic);
|
||||
|
||||
@@ -459,6 +459,8 @@
|
||||
<add-to-group group-id="Diff.KeymapGroup" anchor="after" relative-to-action="CompareClipboardWithSelection"/>
|
||||
</group>
|
||||
|
||||
<action id="ActivateVersionControlToolWindow" class="com.intellij.openapi.vcs.changes.ui.ActivateVersionControlToolWindowAction"/>
|
||||
|
||||
<group id="Vcs.Show.Toolwindow.Tab">
|
||||
<add-to-group group-id="VcsGeneral.KeymapGroup"/>
|
||||
<action id="Vcs.Show.Local.Changes" class="com.intellij.vcs.VcsShowLocalChangesAction"/>
|
||||
|
||||
+8
@@ -1,9 +1,12 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.openapi.vcs.changes.ui
|
||||
|
||||
import com.intellij.ide.actions.ActivateToolWindowAction
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager.Companion.COMMIT_TOOLWINDOW_ID
|
||||
import com.intellij.openapi.wm.ToolWindow
|
||||
import com.intellij.openapi.wm.ToolWindowId
|
||||
import com.intellij.openapi.wm.ToolWindowManager
|
||||
import com.intellij.openapi.wm.impl.content.ToolWindowContentUi.HIDE_ID_LABEL
|
||||
|
||||
class ChangesViewToolWindowFactory : VcsToolWindowFactory() {
|
||||
@@ -20,4 +23,9 @@ class CommitToolWindowFactory : VcsToolWindowFactory() {
|
||||
toolWindow.component.putClientProperty(HIDE_ID_LABEL, "true")
|
||||
super.createToolWindowContent(project, toolWindow)
|
||||
}
|
||||
}
|
||||
|
||||
internal class ActivateVersionControlToolWindowAction : ActivateToolWindowAction(ToolWindowId.VCS) {
|
||||
override fun useMnemonicFromShortcuts(project: Project): Boolean =
|
||||
ToolWindowManager.getInstance(project).getToolWindow(COMMIT_TOOLWINDOW_ID)?.isAvailable != true
|
||||
}
|
||||
Reference in New Issue
Block a user