Move "CommonShortcuts.shortcutsById()" to "KeymapUtil" and rename

This commit is contained in:
Konstantin Kolosovsky
2017-04-25 16:19:56 +03:00
parent 8cb03871c9
commit b9096dc991
2 changed files with 36 additions and 36 deletions
@@ -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);
}
}
@@ -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);
}