use of com.intellij.openapi.actionSystem.KeyboardShortcut in project intellij-community by JetBrains.
the class KeymapsTestCase method checkDuplicatesInKeymap.
@NotNull
@SuppressWarnings({ "HardCodedStringLiteral" })
private static String checkDuplicatesInKeymap(@NotNull KeymapImpl keymap, @NotNull Map<String, Map<String, List<String>>> allKnownDuplicates) {
Set<String> aids = keymap.getActionIdList();
removeBoundActionIds(aids);
Set<Shortcut> shortcuts = new THashSet<>();
nextId: for (String id : aids) {
Map<String, List<String>> knownDuplicates = allKnownDuplicates.get(keymap.getName());
if (knownDuplicates != null) {
for (List<String> actionsMapping : knownDuplicates.values()) {
if (actionsMapping.contains(id)) {
continue nextId;
}
}
}
for (Shortcut shortcut : keymap.getShortcuts(id)) {
if (shortcut instanceof KeyboardShortcut) {
shortcuts.add(shortcut);
}
}
}
List<Shortcut> sorted = new ArrayList<>(shortcuts);
Collections.sort(sorted, Comparator.comparing(KeymapsTestCase::getText));
if (OUTPUT_TEST_DATA) {
System.out.println("put(\"" + keymap.getName() + "\", new String[][] {");
} else {
System.out.println(keymap.getName());
}
StringBuilder failMessage = new StringBuilder();
for (Shortcut shortcut : sorted) {
if (!(shortcut instanceof KeyboardShortcut)) {
continue;
}
Set<String> ids = new THashSet<>(Arrays.asList(keymap.getActionIds(shortcut)));
removeBoundActionIds(ids);
if (ids.size() == 1) {
continue;
}
Keymap parent = keymap.getParent();
if (parent != null) {
// ignore duplicates from default keymap
boolean differFromParent = false;
for (String id : ids) {
Shortcut[] here = keymap.getShortcuts(id);
Shortcut[] there = parent.getShortcuts(id);
if (keymap.getName().startsWith("Mac")) {
convertMac(there);
}
if (!new THashSet<>(Arrays.asList(here)).equals(new THashSet<>(Arrays.asList(there)))) {
differFromParent = true;
break;
}
}
if (!differFromParent)
continue;
}
String def = "{ " + "\"" + getText(shortcut) + "\"," + StringUtil.repeatSymbol(' ', 25 - getText(shortcut).length()) + StringUtil.join(ids, StringUtil.QUOTER, ", ") + "},";
if (OUTPUT_TEST_DATA) {
System.out.println(def);
} else {
if (failMessage.length() == 0) {
failMessage.append("Shortcut '").append(getText(shortcut)).append("' conflicts found in keymap '").append(keymap.getName()).append("':\n");
}
failMessage.append(def).append("\n");
}
}
if (OUTPUT_TEST_DATA) {
System.out.println("});");
}
return failMessage.toString();
}
use of com.intellij.openapi.actionSystem.KeyboardShortcut in project intellij-plugins by StepicOrg.
the class StudyProjectComponent method projectClosed.
@Override
public void projectClosed() {
if (!StepikProjectManager.isStepikProject(project)) {
return;
}
final ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(StudyToolWindowFactory.STUDY_TOOL_WINDOW);
if (toolWindow != null) {
toolWindow.getContentManager().removeAllContents(false);
}
KeymapManagerEx keymapManager = KeymapManagerEx.getInstanceEx();
for (Keymap keymap : keymapManager.getAllKeymaps()) {
List<Pair<String, String>> pairs = deletedShortcuts.get(keymap);
if (pairs != null && !pairs.isEmpty()) {
for (Pair<String, String> actionShortcut : pairs) {
keymap.addShortcut(actionShortcut.first, new KeyboardShortcut(KeyStroke.getKeyStroke(actionShortcut.second), null));
}
}
}
}
Aggregations