public CloseOnESCAction(EditorSearchComponent editorSearchComponent, JComponent textField) { super(editorSearchComponent); ArrayList<Shortcut> shortcuts = new ArrayList<Shortcut>(); if (KeymapUtil.isEmacsKeymap()) { shortcuts.add(new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.CTRL_MASK), null)); textField.registerKeyboardAction(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { CloseOnESCAction.this.actionPerformed(null); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_FOCUSED); } else { shortcuts.add(new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), null)); } registerCustomShortcutSet(new CustomShortcutSet(shortcuts.toArray(new Shortcut[shortcuts.size()])), textField); }
private static boolean skipAction(KeyEvent e, List<AnAction> actionsToSkip) { if(actionsToSkip != null) { final KeyboardShortcut eventShortcut = new KeyboardShortcut(KeyStroke.getKeyStrokeForEvent(e), null); for(AnAction action : actionsToSkip) { for(Shortcut sc : action.getShortcutSet().getShortcuts()) { if(sc.isKeyboard() && sc.startsWith(eventShortcut)) { return true; } } } } return false; }
@NotNull private InplaceButton createSettingsButton(@NotNull final FindUsagesHandler handler, @NotNull final RelativePoint popupPosition, final Editor editor, final int maxUsages, @NotNull final Runnable cancelAction) { String shortcutText = ""; KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut(); if (shortcut != null) { shortcutText = "(" + KeymapUtil.getShortcutText(shortcut) + ")"; } return new InplaceButton("Settings..." + shortcutText, AllIcons.General.Settings, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { showDialogAndFindUsages(handler, popupPosition, editor, maxUsages); } }); cancelAction.run(); } } ); }
public static Set<Integer> getActivateToolWindowVKs() { if (ApplicationManager.getApplication() == null) return new HashSet<>(); Keymap keymap = KeymapManager.getInstance().getActiveKeymap(); Shortcut[] baseShortcut = keymap.getShortcuts("ActivateProjectToolWindow"); int baseModifiers = 0; for (Shortcut each : baseShortcut) { if (each instanceof KeyboardShortcut) { KeyStroke keyStroke = ((KeyboardShortcut)each).getFirstKeyStroke(); baseModifiers = keyStroke.getModifiers(); if (baseModifiers > 0) { break; } } } return getModifiersVKs(baseModifiers); }
@NotNull private InplaceButton createSettingsButton(@NotNull final FindUsagesHandler handler, @NotNull final RelativePoint popupPosition, final Editor editor, final int maxUsages, @NotNull final Runnable cancelAction) { String shortcutText = ""; KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut(); if (shortcut != null) { shortcutText = "(" + KeymapUtil.getShortcutText(shortcut) + ")"; } return new InplaceButton("Settings..." + shortcutText, AllIcons.General.Settings, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { showDialogAndFindUsages(handler, popupPosition, editor, maxUsages); } }); cancelAction.run(); } }); }
@Override protected void subInit() { super.subInit(); this.myMessageTextField = new EditorTextField(""); this.myKindUpDownHint = new JLabel(); this.myKindUpDownHint.setIcon(PlatformIcons.UP_DOWN_ARROWS); this.myKindUpDownHint.setToolTipText(PhpBundle.message("actions.new.php.base.arrows.kind.tooltip")); this.myKindComboBox = new ComboBox<String>(); this.myKindComboBox.setMinimumAndPreferredWidth(400); this.myKindComboBox.setRenderer(new ListCellRendererWrapper<Trinity>() { public void customize(JList list, Trinity value, int index, boolean selected, boolean hasFocus) { this.setText((String)value.first); this.setIcon((Icon)value.second); } }); ComboboxSpeedSearch var10001 = new ComboboxSpeedSearch(this.myKindComboBox) { protected String getElementText(Object element) { return (String)((Trinity)element).first; } }; KeyboardShortcut up = new KeyboardShortcut(KeyStroke.getKeyStroke(38, 0), (KeyStroke)null); KeyboardShortcut down = new KeyboardShortcut(KeyStroke.getKeyStroke(40, 0), (KeyStroke)null); AnAction kindArrow = PhpNewFileDialog.getCbArrowAction(this.myKindComboBox); kindArrow.registerCustomShortcutSet(new CustomShortcutSet(new Shortcut[]{up, down}), this.myNameTextField); List<Trinity> exceptionTypes = this.getExceptionTypes(); for(Trinity type : exceptionTypes) { this.myKindComboBox.addItem(type); } }
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 ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { final CodeInsightActionHandler handler = toImplement ? new OverrideMethodsHandler(): new ImplementMethodsHandler(); handler.invoke(project, editor, aClass.getContainingFile()); } }); } } ); } }
@NotNull private static String createOptionsHtml(@NonNls UsageTarget[] searchFor) { KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut(searchFor); String shortcutText = ""; if (shortcut != null) { shortcutText = " (" + KeymapUtil.getShortcutText(shortcut) + ")"; } return "<a href='" + FIND_OPTIONS_HREF_TARGET + "'>Find Options...</a>" + shortcutText; }
private void removeShortcuts(String actionId) { Shortcut[] shortcuts = getKeymap().getShortcuts(actionId); for (Shortcut each : shortcuts) { if (each instanceof KeyboardShortcut) { getKeymap().removeShortcut(actionId, each); } } }
private static String getText(Shortcut shortcut) { if (shortcut instanceof KeyboardShortcut) { KeyStroke fst = ((KeyboardShortcut)shortcut).getFirstKeyStroke(); String s = KeymapImpl.getKeyShortcutString(fst); KeyStroke snd = ((KeyboardShortcut)shortcut).getSecondKeyStroke(); if (snd != null) { s += "," + KeymapImpl.getKeyShortcutString(snd); } return s; } return KeymapUtil.getShortcutText(shortcut); }
private static void checkLinuxKeymap(final Keymap keymap) { for (String actionId : keymap.getActionIds()) { for (Shortcut shortcut : keymap.getShortcuts(actionId)) { if (shortcut instanceof KeyboardShortcut) { checkCtrlAltFn(keymap, shortcut, ((KeyboardShortcut)shortcut).getFirstKeyStroke()); checkCtrlAltFn(keymap, shortcut, ((KeyboardShortcut)shortcut).getSecondKeyStroke()); } } } }
public void setData(Keymap keymap, KeyboardShortcut shortcut) { myKeymap = keymap; myEnableSecondKeystroke.setSelected(false); if (shortcut != null) { myFirstStrokePanel.getShortcutTextField().setKeyStroke(shortcut.getFirstKeyStroke()); if (shortcut.getSecondKeyStroke() != null) { myEnableSecondKeystroke.setSelected(true); mySecondStrokePanel.getShortcutTextField().setKeyStroke(shortcut.getSecondKeyStroke()); } } handleSecondKey(); updateCurrentKeyStrokeInfo(); }
public static Shortcut convertShortcutFromParent(Shortcut parentShortcut) { if (parentShortcut instanceof MouseShortcut) { return convertMouseShortcut((MouseShortcut)parentShortcut); } KeyboardShortcut key = (KeyboardShortcut)parentShortcut; return new KeyboardShortcut(convertKeyStroke(key.getFirstKeyStroke()), convertKeyStroke(key.getSecondKeyStroke())); }
private boolean printConflict(GridBagConstraints c, int actionKey, String actionId) { boolean hasConflicts = false; int mask = myQuickAccessSettings.getModifierMask(myModifiers); KeyboardShortcut sc = new KeyboardShortcut(KeyStroke.getKeyStroke(actionKey, mask), null); Map<String,ArrayList<KeyboardShortcut>> conflictMap = myQuickAccessSettings.getKeymap().getConflicts(actionId, sc); if (conflictMap.size() > 0) { hasConflicts = true; JLabel scText = new JLabel(sc.toString()); c.gridy++; c.gridx = 0; myConflicts.add(scText, c); Iterator<String> actions = conflictMap.keySet().iterator(); while (actions.hasNext()) { String each = actions.next(); AnAction eachAnAction = ActionManager.getInstance().getAction(each); if (eachAnAction != null) { String text = eachAnAction.getTemplatePresentation().getText(); JLabel eachAction = new JLabel(text != null && text.length() > 0 ? text : each); c.gridx = 1; myConflicts.add(eachAction, c); c.gridy++; } } } c.gridx = 0; c.gridwidth = 2; c.gridy++; myConflicts.add(new SeparatorWithText(), c); c.gridwidth = 1; return hasConflicts; }
@Nullable private static String getShortcutText(String actionId, Keymap keymap) { for (final Shortcut shortcut : keymap.getShortcuts(actionId)) { if (shortcut instanceof KeyboardShortcut) { return KeymapUtil.getShortcutText(shortcut); } } return null; }
public ShowHistoryAction(boolean search) { super((search ? "Search" : "Replace") + " History", (search ? "Search" : "Replace") + " history", IconLoader.findIcon("/com/intellij/ide/ui/laf/icons/search.png", DarculaTextFieldUI.class, true)); myShowSearchHistory = search; KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_H, InputEvent.CTRL_DOWN_MASK); registerCustomShortcutSet(new CustomShortcutSet(new KeyboardShortcut(stroke, null)), myTextArea); }
@Override protected void advertiseActions(@NotNull JComponent splitters, @NotNull UIUtil.TextPainter painter) { String shortcut = KeymapUtil.getShortcutText(new KeyboardShortcut(KeyStroke.getKeyStroke(StudyNextWindowAction.SHORTCUT2), null)); appendAction(painter, "Navigate to the next answer placeholder", shortcut); appendAction(painter, "Navigate between answer placeholders", getActionShortcutText(StudyPrevWindowAction.ACTION_ID) + separator + getActionShortcutText(StudyNextWindowAction.ACTION_ID)); appendAction(painter, "Navigate between tasks", getActionShortcutText(StudyPreviousStudyTaskAction.ACTION_ID) + separator + getActionShortcutText(StudyNextStudyTaskAction.ACTION_ID)); appendAction(painter, "Reset current task file", getActionShortcutText(StudyRefreshTaskFileAction.ACTION_ID)); appendAction(painter, "Check task", getActionShortcutText(StudyCheckAction.ACTION_ID)); appendAction(painter, "Get hint for the answer placeholder", getActionShortcutText(StudyShowHintAction.ACTION_ID)); appendLine(painter,"To see your progress open the '" + StudyProgressToolWindowFactory.ID + "' panel"); }
private void invokeActionViaKeystroke(@NotNull String actionId) { AnAction action = ActionManager.getInstance().getAction(actionId); assertNotNull(actionId, action); assertTrue(actionId + " is not enabled", action.getTemplatePresentation().isEnabled()); Keymap keymap = KeymapManager.getInstance().getActiveKeymap(); Shortcut[] shortcuts = keymap.getShortcuts(actionId); assertNotNull(shortcuts); assertThat(shortcuts).isNotEmpty(); Shortcut shortcut = shortcuts[0]; if (shortcut instanceof KeyboardShortcut) { KeyboardShortcut cs = (KeyboardShortcut)shortcut; KeyStroke firstKeyStroke = cs.getFirstKeyStroke(); Component component = getFocusedEditor(); if (component != null) { ComponentDriver driver = new ComponentDriver(robot); System.out.println("Invoking editor action " + actionId + " via shortcut " + KeyEvent.getKeyModifiersText(firstKeyStroke.getModifiers()) + KeyEvent.getKeyText(firstKeyStroke.getKeyCode())); driver.pressAndReleaseKey(component, firstKeyStroke.getKeyCode(), new int[]{firstKeyStroke.getModifiers()}); KeyStroke secondKeyStroke = cs.getSecondKeyStroke(); if (secondKeyStroke != null) { System.out.println(" and " + KeyEvent.getKeyModifiersText(secondKeyStroke.getModifiers()) + KeyEvent.getKeyText(secondKeyStroke.getKeyCode())); driver.pressAndReleaseKey(component, secondKeyStroke.getKeyCode(), new int[]{secondKeyStroke.getModifiers()}); } } else { fail("Editor not focused for action"); } } else { fail("Unsupported shortcut type " + shortcut.getClass().getName()); } }
@Nullable private static KeyboardShortcut removeFirstKeyboardShortcut(Keymap keymap, String actionId) { Shortcut[] shortcuts = keymap.getShortcuts(actionId); for (Shortcut each : shortcuts) { if (each instanceof KeyboardShortcut) { keymap.removeShortcut(actionId, each); return (KeyboardShortcut)each; } } return null; }
public static void registerUpDownHint(JComponent component, final GrTypeComboBox combo) { final AnAction arrow = new AnAction() { @Override public void actionPerformed(AnActionEvent e) { if (e.getInputEvent() instanceof KeyEvent) { final int code = ((KeyEvent)e.getInputEvent()).getKeyCode(); scrollBy(code == KeyEvent.VK_DOWN ? 1 : code == KeyEvent.VK_UP ? -1 : 0, combo); } } }; final KeyboardShortcut up = new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.ALT_DOWN_MASK), null); final KeyboardShortcut down = new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.ALT_DOWN_MASK), null); arrow.registerCustomShortcutSet(new CustomShortcutSet(up, down), component); }
private KeyStroke[] getKeyStrokesByActionId(String actionId) { List<KeyStroke> keyStrokes = new ArrayList<KeyStroke>(); 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()]); }
@NotNull private static String createOptionsHtml() { String shortcutText = ""; KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut(); if (shortcut != null) { shortcutText = " (" + KeymapUtil.getShortcutText(shortcut) + ")"; } return "<a href='" + FIND_OPTIONS_HREF_TARGET + "'>Find Options...</a>" + shortcutText; }
private void removeShortcuts(String actionId) { Shortcut[] shortcuts = myKeymap.getShortcuts(actionId); for (Shortcut each : shortcuts) { if (each instanceof KeyboardShortcut) { myKeymap.removeShortcut(actionId, each); } } }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); if (myCurrentWindow == null || myCurrentWindow.getFiles().length == 0) { g.setColor(UIUtil.isUnderDarcula()? UIUtil.getBorderColor() : new Color(0, 0, 0, 50)); g.drawLine(0, 0, getWidth(), 0); } if (showEmptyText()) { UIUtil.applyRenderingHints(g); g.setColor(new JBColor(Gray._100, Gray._160)); g.setFont(UIUtil.getLabelFont().deriveFont(UIUtil.isUnderDarcula() ? 24f : 18f)); final UIUtil.TextPainter painter = new UIUtil.TextPainter().withShadow(true).withLineSpacing(1.4f); painter.appendLine("No files are open").underlined(new JBColor(Gray._150, Gray._100)); if (!isProjectViewVisible()) { painter.appendLine("Open Project View with " + KeymapUtil.getShortcutText(new KeyboardShortcut( KeyStroke.getKeyStroke((SystemInfo.isMac ? "meta" : "alt") + " 1"), null))).smaller().withBullet(); } painter.appendLine("Open a file by name with " + getActionShortcutText("GotoFile")).smaller().withBullet() .appendLine("Open Recent files with " + getActionShortcutText(IdeActions.ACTION_RECENT_FILES)).smaller().withBullet() .appendLine("Open Navigation Bar with " + getActionShortcutText("ShowNavBar")).smaller().withBullet() .appendLine("Drag'n'Drop file(s) here from " + ShowFilePathAction.getFileManagerName()).smaller().withBullet() .draw(g, new PairFunction<Integer, Integer, Pair<Integer, Integer>>() { @Override public Pair<Integer, Integer> fun(Integer width, Integer height) { final Dimension s = getSize(); return Pair.create((s.width - width) / 2, (s.height - height) / 2); } }); } }
private static String getActionShortcutText(final String actionId) { final Shortcut[] shortcuts = KeymapManager.getInstance().getActiveKeymap().getShortcuts(actionId); String shortcutText = ""; for (final Shortcut shortcut : shortcuts) { if (shortcut instanceof KeyboardShortcut) { shortcutText = KeymapUtil.getShortcutText(shortcut); break; } } return shortcutText; }
public KeyboardShortcut getKeyboardShortcut() { KeyStroke firstStroke = myFirstStrokePanel.getKeyStroke(); if (firstStroke == null) { return null; } KeyStroke secondStroke = myEnableSecondKeystroke.isSelected() ? mySecondStrokePanel.getKeyStroke() : null; return new KeyboardShortcut(firstStroke, secondStroke); }
private boolean printConflict(GridBagConstraints c, int actionKey, String actionId) { boolean hasConflicts = false; int mask = myQuickAccessSettings.getModiferMask(myModifiers); KeyboardShortcut sc = new KeyboardShortcut(KeyStroke.getKeyStroke(actionKey, mask), null); Map<String,ArrayList<KeyboardShortcut>> conflictMap = myQuickAccessSettings.getKeymap().getConflicts(actionId, sc); if (conflictMap.size() > 0) { hasConflicts = true; JLabel scText = new JLabel(sc.toString()); c.gridy++; c.gridx = 0; myConflicts.add(scText, c); Iterator<String> actions = conflictMap.keySet().iterator(); while (actions.hasNext()) { String each = actions.next(); AnAction eachAnAction = ActionManager.getInstance().getAction(each); if (eachAnAction != null) { String text = eachAnAction.getTemplatePresentation().getText(); JLabel eachAction = new JLabel(text != null && text.length() > 0 ? text : each); c.gridx = 1; myConflicts.add(eachAction, c); c.gridy++; } } } c.gridx = 0; c.gridwidth = 2; c.gridy++; myConflicts.add(new SeparatorWithText(), c); c.gridwidth = 1; return hasConflicts; }
public ReplaceOnEnterAction(EditorSearchComponent editorSearchComponent, JComponent textField) { super(editorSearchComponent); ArrayList<Shortcut> shortcuts = new ArrayList<Shortcut>(); shortcuts.add(new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), null)); registerCustomShortcutSet(new CustomShortcutSet(shortcuts.toArray(new Shortcut[shortcuts.size()])), textField); }
private KeyStroke[] getKeyStrokesByActionId(String actionId) { List<KeyStroke> keyStrokes = new ArrayList<KeyStroke>(); 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()]); }
@NotNull private static String getLabel() { Shortcut[] shortcuts = KeymapManager.getInstance().getActiveKeymap().getShortcuts("EditSource"); if (shortcuts.length > 0) { Shortcut shortcut = shortcuts[0]; if (shortcut.isKeyboard()) { KeyboardShortcut key = (KeyboardShortcut) shortcut; String s = KeyStrokeAdapter.toString(key.getFirstKeyStroke()); if (s != null) { return "Jump To Source [" + s.toUpperCase() + "]"; } } } return "Jump To Source"; }
@Nonnull private static String createOptionsHtml(@NonNls UsageTarget[] searchFor) { KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut(searchFor); String shortcutText = ""; if (shortcut != null) { shortcutText = " (" + KeymapUtil.getShortcutText(shortcut) + ")"; } return "<a href='" + FIND_OPTIONS_HREF_TARGET + "'>Find Options...</a>" + shortcutText; }