use of com.intellij.openapi.actionSystem.KeyboardShortcut in project intellij-community by JetBrains.
the class OverrideImplementUtil method registerHandlerForComplementaryAction.
private static void registerHandlerForComplementaryAction(final Project project, final Editor editor, final PsiElement aClass, final boolean toImplement, final MemberChooser<PsiMethodMember> chooser) {
final JComponent preferredFocusedComponent = chooser.getPreferredFocusedComponent();
final Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
@NonNls final String s = toImplement ? "OverrideMethods" : "ImplementMethods";
final Shortcut[] shortcuts = keymap.getShortcuts(s);
if (shortcuts.length > 0 && shortcuts[0] instanceof KeyboardShortcut) {
preferredFocusedComponent.getInputMap().put(((KeyboardShortcut) shortcuts[0]).getFirstKeyStroke(), s);
preferredFocusedComponent.getActionMap().put(s, new AbstractAction() {
@Override
public void actionPerformed(final ActionEvent e) {
chooser.close(DialogWrapper.CANCEL_EXIT_CODE);
// invoke later in order to close previous modal dialog
TransactionGuard.getInstance().submitTransactionLater(project, () -> {
CodeInsightActionHandler handler = toImplement ? new OverrideMethodsHandler() : new ImplementMethodsHandler();
handler.invoke(project, editor, aClass.getContainingFile());
});
}
});
}
}
use of com.intellij.openapi.actionSystem.KeyboardShortcut in project android by JetBrains.
the class EditorFixture method invokeAction.
/** Invokes {@code editorAction} via its (first) keyboard shortcut in the active keymap. */
public EditorFixture invokeAction(@NotNull EditorAction editorAction) {
AnAction anAction = ActionManager.getInstance().getAction(editorAction.id);
assertTrue(editorAction.id + " is not enabled", anAction.getTemplatePresentation().isEnabled());
Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
Shortcut shortcut = keymap.getShortcuts(editorAction.id)[0];
if (shortcut instanceof KeyboardShortcut) {
KeyboardShortcut cs = (KeyboardShortcut) shortcut;
KeyStroke firstKeyStroke = cs.getFirstKeyStroke();
Component component = getFocusedEditor();
if (component != null) {
ComponentDriver driver = new ComponentDriver(robot);
driver.pressAndReleaseKey(component, firstKeyStroke.getKeyCode(), new int[] { firstKeyStroke.getModifiers() });
KeyStroke secondKeyStroke = cs.getSecondKeyStroke();
if (secondKeyStroke != null) {
driver.pressAndReleaseKey(component, secondKeyStroke.getKeyCode(), new int[] { secondKeyStroke.getModifiers() });
}
} else {
fail("Editor not focused for action");
}
} else {
fail("Unsupported shortcut type " + shortcut.getClass().getName());
}
return this;
}
use of com.intellij.openapi.actionSystem.KeyboardShortcut in project intellij-community by JetBrains.
the class JBTerminalSystemSettingsProviderBase method getKeyStrokesByActionId.
private KeyStroke[] getKeyStrokesByActionId(String actionId) {
java.util.List<KeyStroke> keyStrokes = new ArrayList<>();
Shortcut[] shortcuts = KeymapManager.getInstance().getActiveKeymap().getShortcuts(actionId);
for (Shortcut sc : shortcuts) {
if (sc instanceof KeyboardShortcut) {
KeyStroke ks = ((KeyboardShortcut) sc).getFirstKeyStroke();
keyStrokes.add(ks);
}
}
return keyStrokes.toArray(new KeyStroke[keyStrokes.size()]);
}
use of com.intellij.openapi.actionSystem.KeyboardShortcut in project intellij-community by JetBrains.
the class ToolWindowManagerImpl method getActivateToolWindowVKs.
@NotNull
private static Set<Integer> getActivateToolWindowVKs() {
if (ApplicationManager.getApplication() == null)
return new HashSet<>();
Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
Shortcut[] baseShortcut = keymap.getShortcuts("ActivateProjectToolWindow");
int baseModifiers = SystemInfo.isMac ? InputEvent.META_MASK : InputEvent.ALT_MASK;
for (Shortcut each : baseShortcut) {
if (each instanceof KeyboardShortcut) {
KeyStroke keyStroke = ((KeyboardShortcut) each).getFirstKeyStroke();
baseModifiers = keyStroke.getModifiers();
if (baseModifiers > 0) {
break;
}
}
}
return getModifiersVKs(baseModifiers);
}
use of com.intellij.openapi.actionSystem.KeyboardShortcut in project intellij-community by JetBrains.
the class GuiTestUtil method invokeAction.
public static void invokeAction(@NotNull Robot robot, @NotNull String actionId) {
KeyboardShortcut keyboardShortcut = ActionManager.getInstance().getKeyboardShortcut(actionId);
assert keyboardShortcut != null;
KeyStroke keyStroke = keyboardShortcut.getFirstKeyStroke();
LOG.info("Invoking action \"" + actionId + "\" via shortcut " + keyboardShortcut.toString());
robot.pressAndReleaseKey(keyStroke.getKeyCode(), new int[] { keyStroke.getModifiers() });
}
Aggregations