From b9096dc991f635f5e02c07b6142cf6f9a0bb95b6 Mon Sep 17 00:00:00 2001 From: Konstantin Kolosovsky Date: Sat, 15 Apr 2017 18:48:26 +0300 Subject: [PATCH] Move "CommonShortcuts.shortcutsById()" to "KeymapUtil" and rename --- .../openapi/actionSystem/CommonShortcuts.java | 58 ++++++++----------- .../intellij/openapi/keymap/KeymapUtil.java | 14 ++++- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/actionSystem/CommonShortcuts.java b/platform/platform-api/src/com/intellij/openapi/actionSystem/CommonShortcuts.java index 536b3900cb1b..47d9df55409d 100644 --- a/platform/platform-api/src/com/intellij/openapi/actionSystem/CommonShortcuts.java +++ b/platform/platform-api/src/com/intellij/openapi/actionSystem/CommonShortcuts.java @@ -15,12 +15,8 @@ */ package com.intellij.openapi.actionSystem; -import com.intellij.openapi.application.Application; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.keymap.KeymapManager; import com.intellij.openapi.util.SystemInfo; import com.intellij.util.BitUtil; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.event.InputEvent; @@ -28,6 +24,8 @@ import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.util.ArrayList; +import static com.intellij.openapi.keymap.KeymapUtil.getActiveKeymapShortcuts; + public class CommonShortcuts { private CommonShortcuts() {} @@ -74,96 +72,86 @@ public class CommonShortcuts { } public static ShortcutSet getCopy() { - return shortcutsById(IdeActions.ACTION_COPY); + return getActiveKeymapShortcuts(IdeActions.ACTION_COPY); } public static ShortcutSet getPaste() { - return shortcutsById(IdeActions.ACTION_PASTE); + return getActiveKeymapShortcuts(IdeActions.ACTION_PASTE); } public static ShortcutSet getRerun() { - return shortcutsById(IdeActions.ACTION_RERUN); + return getActiveKeymapShortcuts(IdeActions.ACTION_RERUN); } public static ShortcutSet getEditSource() { - return shortcutsById(IdeActions.ACTION_EDIT_SOURCE); + return getActiveKeymapShortcuts(IdeActions.ACTION_EDIT_SOURCE); } public static ShortcutSet getViewSource() { - return shortcutsById(IdeActions.ACTION_VIEW_SOURCE); + return getActiveKeymapShortcuts(IdeActions.ACTION_VIEW_SOURCE); } public static ShortcutSet getNew() { - return shortcutsById(IdeActions.ACTION_NEW_ELEMENT); + return getActiveKeymapShortcuts(IdeActions.ACTION_NEW_ELEMENT); } public static ShortcutSet getDuplicate() { - return shortcutsById(IdeActions.ACTION_EDITOR_DUPLICATE); + return getActiveKeymapShortcuts(IdeActions.ACTION_EDITOR_DUPLICATE); } public static ShortcutSet getMove() { - return shortcutsById(IdeActions.ACTION_MOVE); + return getActiveKeymapShortcuts(IdeActions.ACTION_MOVE); } public static ShortcutSet getRename() { - return shortcutsById(IdeActions.ACTION_RENAME); + return getActiveKeymapShortcuts(IdeActions.ACTION_RENAME); } public static ShortcutSet getDiff() { - return shortcutsById(IdeActions.ACTION_SHOW_DIFF_COMMON); + return getActiveKeymapShortcuts(IdeActions.ACTION_SHOW_DIFF_COMMON); } public static ShortcutSet getFind() { - return shortcutsById(IdeActions.ACTION_FIND); + return getActiveKeymapShortcuts(IdeActions.ACTION_FIND); } public static ShortcutSet getContextHelp() { - return shortcutsById(IdeActions.ACTION_CONTEXT_HELP); + return getActiveKeymapShortcuts(IdeActions.ACTION_CONTEXT_HELP); } public static ShortcutSet getCloseActiveWindow() { - return shortcutsById(IdeActions.ACTION_CLOSE); + return getActiveKeymapShortcuts(IdeActions.ACTION_CLOSE); } public static ShortcutSet getMoveUp() { - return shortcutsById(IdeActions.ACTION_EDITOR_MOVE_CARET_UP); + return getActiveKeymapShortcuts(IdeActions.ACTION_EDITOR_MOVE_CARET_UP); } public static ShortcutSet getMoveDown() { - return shortcutsById(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN); + return getActiveKeymapShortcuts(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN); } public static ShortcutSet getMovePageUp() { - return shortcutsById(IdeActions.ACTION_EDITOR_MOVE_CARET_PAGE_UP); + return getActiveKeymapShortcuts(IdeActions.ACTION_EDITOR_MOVE_CARET_PAGE_UP); } public static ShortcutSet getMovePageDown() { - return shortcutsById(IdeActions.ACTION_EDITOR_MOVE_CARET_PAGE_DOWN); + return getActiveKeymapShortcuts(IdeActions.ACTION_EDITOR_MOVE_CARET_PAGE_DOWN); } public static ShortcutSet getMoveHome() { - return shortcutsById(IdeActions.ACTION_EDITOR_MOVE_LINE_START); + return getActiveKeymapShortcuts(IdeActions.ACTION_EDITOR_MOVE_LINE_START); } public static ShortcutSet getMoveEnd() { - return shortcutsById(IdeActions.ACTION_EDITOR_MOVE_LINE_END); + return getActiveKeymapShortcuts(IdeActions.ACTION_EDITOR_MOVE_LINE_END); } public static ShortcutSet getRecentFiles() { - return shortcutsById(IdeActions.ACTION_RECENT_FILES); + return getActiveKeymapShortcuts(IdeActions.ACTION_RECENT_FILES); } public static ShortcutSet getDelete() { - return shortcutsById(IdeActions.ACTION_DELETE); - } - - @NotNull - private static CustomShortcutSet shortcutsById(String actionId) { - Application application = ApplicationManager.getApplication(); - KeymapManager keymapManager = application == null ? null : application.getComponent(KeymapManager.class); - if (keymapManager == null) { - return new CustomShortcutSet(Shortcut.EMPTY_ARRAY); - } - return new CustomShortcutSet(keymapManager.getActiveKeymap().getShortcuts(actionId)); + return getActiveKeymapShortcuts(IdeActions.ACTION_DELETE); } } diff --git a/platform/platform-api/src/com/intellij/openapi/keymap/KeymapUtil.java b/platform/platform-api/src/com/intellij/openapi/keymap/KeymapUtil.java index 1bd82c2496c5..2ef8edfb9a90 100644 --- a/platform/platform-api/src/com/intellij/openapi/keymap/KeymapUtil.java +++ b/platform/platform-api/src/com/intellij/openapi/keymap/KeymapUtil.java @@ -17,6 +17,8 @@ package com.intellij.openapi.keymap; import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.application.Application; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.SystemInfo; @@ -197,9 +199,19 @@ public class KeymapUtil { } } + @NotNull + public static ShortcutSet getActiveKeymapShortcuts(@NotNull String actionId) { + Application application = ApplicationManager.getApplication(); + KeymapManager keymapManager = application == null ? null : application.getComponent(KeymapManager.class); + if (keymapManager == null) { + return new CustomShortcutSet(Shortcut.EMPTY_ARRAY); + } + return new CustomShortcutSet(keymapManager.getActiveKeymap().getShortcuts(actionId)); + } + @NotNull public static String getFirstKeyboardShortcutText(@NotNull String actionId) { - Shortcut[] shortcuts = KeymapManager.getInstance().getActiveKeymap().getShortcuts(actionId); + Shortcut[] shortcuts = getActiveKeymapShortcuts(actionId).getShortcuts(); KeyboardShortcut shortcut = ContainerUtil.findInstance(shortcuts, KeyboardShortcut.class); return shortcut == null? "" : getShortcutText(shortcut); }