use of com.intellij.openapi.actionSystem.Shortcut in project intellij-community by JetBrains.
the class PopupListElementRenderer method customizeComponent.
@Override
protected void customizeComponent(JList<? extends E> list, E value, boolean isSelected) {
ListPopupStep<Object> step = myPopup.getListStep();
boolean isSelectable = step.isSelectable(value);
myTextLabel.setEnabled(isSelectable);
if (!isSelected && step instanceof BaseListPopupStep) {
Color bg = ((BaseListPopupStep) step).getBackgroundFor(value);
Color fg = ((BaseListPopupStep) step).getForegroundFor(value);
if (fg != null)
myTextLabel.setForeground(fg);
if (bg != null)
UIUtil.setBackgroundRecursively(myComponent, bg);
}
if (step.isMnemonicsNavigationEnabled()) {
final int pos = step.getMnemonicNavigationFilter().getMnemonicPos(value);
if (pos != -1) {
String text = myTextLabel.getText();
text = text.substring(0, pos) + text.substring(pos + 1);
myTextLabel.setText(text);
myTextLabel.setDisplayedMnemonicIndex(pos);
}
} else {
myTextLabel.setDisplayedMnemonicIndex(-1);
}
if (step.hasSubstep(value) && isSelectable) {
myNextStepLabel.setVisible(true);
final boolean isDark = ColorUtil.isDark(UIUtil.getListSelectionBackground());
myNextStepLabel.setIcon(isSelected ? isDark ? AllIcons.Icons.Ide.NextStepInverted : AllIcons.Icons.Ide.NextStep : AllIcons.Icons.Ide.NextStepGrayed);
} else {
myNextStepLabel.setVisible(false);
//myNextStepLabel.setIcon(PopupIcons.EMPTY_ICON);
}
setSelected(myNextStepLabel, isSelected);
if (myShortcutLabel != null) {
myShortcutLabel.setText("");
if (value instanceof ShortcutProvider) {
ShortcutSet set = ((ShortcutProvider) value).getShortcut();
if (set != null) {
Shortcut shortcut = ArrayUtil.getFirstElement(set.getShortcuts());
if (shortcut != null) {
myShortcutLabel.setText(" " + KeymapUtil.getShortcutText(shortcut));
}
}
}
setSelected(myShortcutLabel, isSelected);
myShortcutLabel.setForeground(isSelected ? UIManager.getColor("MenuItem.acceleratorSelectionForeground") : UIManager.getColor("MenuItem.acceleratorForeground"));
}
}
use of com.intellij.openapi.actionSystem.Shortcut 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.Shortcut 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.Shortcut in project intellij-community by JetBrains.
the class JavaVariableInplaceIntroducer method getAdvertisementText.
@Nullable
private static String getAdvertisementText(final PsiDeclarationStatement declaration, final PsiType type, final boolean hasTypeSuggestion) {
final VariablesProcessor processor = ReassignVariableUtil.findVariablesOfType(declaration, type);
final Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
if (processor.size() > 0) {
final Shortcut[] shortcuts = keymap.getShortcuts("IntroduceVariable");
if (shortcuts.length > 0) {
return "Press " + KeymapUtil.getShortcutText(shortcuts[0]) + " to reassign existing variable";
}
}
if (hasTypeSuggestion) {
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 InplaceRefactoring method showDialogAdvertisement.
protected void showDialogAdvertisement(final String actionId) {
final Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
final Shortcut[] shortcuts = keymap.getShortcuts(actionId);
if (shortcuts.length > 0) {
setAdvertisementText("Press " + KeymapUtil.getShortcutText(shortcuts[0]) + " to show dialog with more options");
}
}
Aggregations