use of com.intellij.openapi.actionSystem.Shortcut in project intellij-community by JetBrains.
the class GrInplaceVariableIntroducer method getAdvertisementText.
@Nullable
private static String getAdvertisementText() {
final Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
final Shortcut[] shortcuts = keymap.getShortcuts("PreviousTemplateVariable");
if (shortcuts.length > 0) {
return "Press " + KeymapUtil.getShortcutText(shortcuts[0]) + " to change type";
}
return null;
}
use of com.intellij.openapi.actionSystem.Shortcut in project intellij-community by JetBrains.
the class KeymapsTestCase method checkLinuxKeymap.
private static void checkLinuxKeymap(final Keymap keymap) {
for (String actionId : keymap.getActionIdList()) {
for (Shortcut shortcut : keymap.getShortcuts(actionId)) {
if (shortcut instanceof KeyboardShortcut) {
checkCtrlAltFn(keymap, shortcut, ((KeyboardShortcut) shortcut).getFirstKeyStroke());
checkCtrlAltFn(keymap, shortcut, ((KeyboardShortcut) shortcut).getSecondKeyStroke());
}
}
}
}
use of com.intellij.openapi.actionSystem.Shortcut in project intellij-community by JetBrains.
the class KeymapsTestCase method testIdsListIsConsistent.
@SuppressWarnings({ "HardCodedStringLiteral" })
public void testIdsListIsConsistent() {
Map<String, Map<String, List<String>>> duplicates = getKnownDuplicates();
Set<String> allMaps = new THashSet<>(ContainerUtil.map(KeymapManagerEx.getInstanceEx().getAllKeymaps(), keymap -> keymap.getName()));
assertThat(ContainerUtil.subtract(allMaps, duplicates.keySet())).overridingErrorMessage("Modify 'known duplicates list' test data. Keymaps were added: %s", ContainerUtil.subtract(allMaps, duplicates.keySet())).isEmpty();
assertThat(ContainerUtil.subtract(duplicates.keySet(), allMaps)).overridingErrorMessage("Modify 'known duplicates list' test data. Keymaps were removed: %s", ContainerUtil.subtract(duplicates.keySet(), allMaps)).isEmpty();
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection") Map<Keymap, List<Shortcut>> reassignedShortcuts = new FactoryMap<Keymap, List<Shortcut>>() {
@Override
protected Map<Keymap, List<Shortcut>> createMap() {
return new LinkedHashMap<>();
}
@Nullable
@Override
protected List<Shortcut> create(Keymap key) {
return new ArrayList<>();
}
};
for (String name : duplicates.keySet()) {
Keymap keymap = KeymapManagerEx.getInstanceEx().getKeymap(name);
assertThat(keymap).overridingErrorMessage("KeyMap %s not found", name).isNotNull();
Map<String, List<String>> duplicateIdsList = duplicates.get(name);
Set<String> mentionedShortcuts = new THashSet<>();
for (Map.Entry<String, List<String>> shortcutMappings : duplicateIdsList.entrySet()) {
String shortcutString = shortcutMappings.getKey();
if (!mentionedShortcuts.add(shortcutString)) {
TestCase.fail("Shortcut '" + shortcutString + "' duplicate in keymap '" + keymap + "'. Please modify 'known duplicates list'");
}
Shortcut shortcut = parse(shortcutString);
String[] ids = keymap.getActionIds(shortcut);
Set<String> actualSc = new HashSet<>(Arrays.asList(ids));
removeBoundActionIds(actualSc);
Set<String> expectedSc = new HashSet<>(shortcutMappings.getValue());
for (String s : actualSc) {
if (!expectedSc.contains(s)) {
reassignedShortcuts.get(keymap).add(shortcut);
}
}
for (String s : expectedSc) {
if (!actualSc.contains(s)) {
System.out.println("Expected action '" + s + "' does not reassign shortcut " + getText(shortcut) + " in keymap " + keymap + " or is not registered");
}
}
}
}
if (!reassignedShortcuts.isEmpty()) {
StringBuilder message = new StringBuilder();
for (Map.Entry<Keymap, List<Shortcut>> keymapToShortcuts : reassignedShortcuts.entrySet()) {
Keymap keymap = keymapToShortcuts.getKey();
message.append("The following shortcuts was reassigned in keymap ").append(keymap.getName()).append(". Please modify known duplicates list:\n");
for (Shortcut eachShortcut : keymapToShortcuts.getValue()) {
message.append(" { ").append(StringUtil.wrapWithDoubleQuote(getText(eachShortcut))).append(",\t").append(StringUtil.join(keymap.getActionIds(eachShortcut), s -> StringUtil.wrapWithDoubleQuote(s), ", ")).append("},\n");
}
}
TestCase.fail("\n" + message.toString());
}
}
use of com.intellij.openapi.actionSystem.Shortcut in project intellij-community by JetBrains.
the class AntTargetNodeDescriptor method addShortcutText.
public static boolean addShortcutText(String actionId, CompositeAppearance appearance) {
Keymap activeKeymap = KeymapManager.getInstance().getActiveKeymap();
Shortcut[] shortcuts = activeKeymap.getShortcuts(actionId);
if (shortcuts != null && shortcuts.length > 0) {
appearance.getEnding().addText(" (" + KeymapUtil.getShortcutText(shortcuts[0]) + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
return true;
} else
return false;
}
use of com.intellij.openapi.actionSystem.Shortcut 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());
});
}
});
}
}
Aggregations