use of com.intellij.openapi.actionSystem.Shortcut in project intellij-community by JetBrains.
the class ActionMacroConfigurationPanel method apply.
public void apply() {
if (myRenamingList != null) {
for (Couple<String> pair : myRenamingList) {
Keymap[] allKeymaps = KeymapManagerEx.getInstanceEx().getAllKeymaps();
for (Keymap keymap : allKeymaps) {
keymap.removeAllActionShortcuts(ActionMacro.MACRO_ACTION_PREFIX + pair.getSecond());
for (Shortcut shortcut : keymap.getShortcuts(ActionMacro.MACRO_ACTION_PREFIX + pair.getFirst())) {
keymap.addShortcut(ActionMacro.MACRO_ACTION_PREFIX + pair.getSecond(), shortcut);
}
keymap.removeAllActionShortcuts(ActionMacro.MACRO_ACTION_PREFIX + pair.getFirst());
}
}
}
final ActionMacroManager manager = ActionMacroManager.getInstance();
ActionMacro[] macros = manager.getAllMacros();
HashSet<String> removedIds = new HashSet<>();
for (ActionMacro macro1 : macros) {
removedIds.add(macro1.getActionId());
}
manager.removeAllMacros();
final Enumeration newMacros = myMacrosModel.elements();
while (newMacros.hasMoreElements()) {
ActionMacro macro = (ActionMacro) newMacros.nextElement();
manager.addMacro(macro);
removedIds.remove(macro.getActionId());
}
manager.registerActions();
for (String id : removedIds) {
Keymap[] allKeymaps = KeymapManagerEx.getInstanceEx().getAllKeymaps();
for (Keymap keymap : allKeymaps) {
keymap.removeAllActionShortcuts(id);
}
}
}
use of com.intellij.openapi.actionSystem.Shortcut in project intellij-community by JetBrains.
the class KeymapGenerator method main.
@Override
public void main(String[] args) {
ActionManager actionManager = ActionManager.getInstance();
StringBuilder xml = new StringBuilder();
xml.append("<Keymaps>\n");
for (Keymap keymap : KeymapManagerEx.getInstanceEx().getAllKeymaps()) {
xml.append(" <Keymap name=\"").append(keymap.getPresentableName()).append("\">\n");
for (String id : keymap.getActionIdList()) {
String shortcuts = KeymapUtil.getShortcutsText(keymap.getShortcuts(id));
if (!StringUtil.isEmpty(shortcuts)) {
AnAction action = actionManager.getAction(id);
xml.append(" <Action id=\"").append(id).append("\">\n");
Set<String> addedShortcuts = new THashSet<>();
for (Shortcut shortcut : keymap.getShortcuts(id)) {
// Different shortcuts may have equal display strings (e.g. shift+minus and shift+subtract)
// We don't want them do be duplicated for users
String shortcutText = KeymapUtil.getShortcutText(shortcut);
if (addedShortcuts.add(shortcutText)) {
xml.append(" <Shortcut>").append(shortcutText).append("</Shortcut>\n");
}
}
if (action != null) {
String text = action.getTemplatePresentation().getText();
if (text != null) {
xml.append(" <Text>").append(StringUtil.escapeXml(text)).append("</Text>\n");
}
}
xml.append(" </Action>\n");
}
}
xml.append(" </Keymap>\n");
}
xml.append("</Keymaps>");
final String path = args.length == 2 ? args[1] : PathManager.getHomePath() + File.separator + "AllKeymaps.xml";
File out = new File(path);
try {
FileUtil.writeToFile(out, xml.toString());
System.out.println("Saved to: " + out.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
System.exit(0);
}
use of com.intellij.openapi.actionSystem.Shortcut in project intellij-community by JetBrains.
the class ShortcutDialog method showAndGet.
T showAndGet(String id, Keymap keymap, QuickList... lists) {
myActionId = id;
myKeymap = keymap;
myGroup = ActionsTreeUtil.createMainGroup(myProject, keymap, lists, null, false, null);
fill(myAction, id, getActionPath(id));
T firstShortcut = null;
for (Shortcut shortcut : keymap.getShortcuts(id)) {
firstShortcut = toShortcut(shortcut);
if (firstShortcut != null)
break;
}
setShortcut(firstShortcut);
return showAndGet() ? myShortcutPanel.getShortcut() : null;
}
use of com.intellij.openapi.actionSystem.Shortcut in project intellij-community by JetBrains.
the class MarkerType method composeText.
@NotNull
private static String composeText(@NotNull PsiElement[] methods, @NotNull String start, @NotNull String pattern, @NotNull String actionId) {
Shortcut[] shortcuts = ActionManager.getInstance().getAction(actionId).getShortcutSet().getShortcuts();
Shortcut shortcut = ArrayUtil.getFirstElement(shortcuts);
String postfix = "<br><div style='margin-top: 5px'><font size='2'>Click";
if (shortcut != null)
postfix += " or press " + KeymapUtil.getShortcutText(shortcut);
postfix += " to navigate</font></div>";
return GutterIconTooltipHelper.composeText(Arrays.asList(methods), start, pattern, postfix);
}
use of com.intellij.openapi.actionSystem.Shortcut 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;
}
Aggregations