List of usage examples for com.intellij.openapi.keymap Keymap getShortcuts
Shortcut @NotNull [] getShortcuts(@Nullable String actionId);
From source file:be.janickreynders.shortcuttranslator.ShortcutTranslatorDialog.java
License:Open Source License
private Set<ShortcutDescription> translateShortcut(KeyStroke stroke, Keymap sourceKeymap, Keymap targetKeymap) { Set<ShortcutDescription> descriptions = new LinkedHashSet<ShortcutDescription>(); String[] actionIds = sourceKeymap.getActionIds(stroke); for (String actionId : actionIds) { Shortcut[] shortcuts = targetKeymap.getShortcuts(actionId); for (Shortcut shortcut : shortcuts) { descriptions.add(new ShortcutDescription(KeymapUtil.getShortcutText(shortcut), actionId, getAction(actionId))); }/*from w ww. ja v a 2 s . c om*/ } return descriptions; }
From source file:com.android.tools.idea.AndroidInitialConfigurator.java
License:Apache License
@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; }// ww w . j a v a 2s .c o m } return null; }
From source file:com.android.tools.idea.fd.actions.HotswapAction.java
License:Apache License
@Nullable private static String getShortcutText() { Keymap activeKeymap = KeymapManager.getInstance().getActiveKeymap(); Shortcut[] shortcuts = activeKeymap.getShortcuts("Android.HotswapChanges"); return shortcuts.length > 0 ? " (" + KeymapUtil.getShortcutText(shortcuts[0]) + ") " : ""; }
From source file:com.android.tools.idea.tests.gui.framework.fixture.EditorFixture.java
License:Apache License
/** 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() }); }//from ww w . j a v a 2 s. co m } else { fail("Editor not focused for action"); } } else { fail("Unsupported shortcut type " + shortcut.getClass().getName()); } return this; }
From source file:com.headwire.aem.tooling.intellij.explorer.AbstractSlingServerNodeDescriptor.java
License:Apache License
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// w ww . ja v a2 s .c o m return false; }
From source file:com.hp.alm.ali.idea.action.UndoAction.java
License:Apache License
public static void installUndoRedoSupport(JTextComponent textComponent) { final UndoManager undoManager = new UndoManager(); Keymap keymap = KeymapManager.getInstance().getActiveKeymap(); new UndoAction(undoManager).registerCustomShortcutSet(new CustomShortcutSet(keymap.getShortcuts("$Undo")), textComponent);/* w ww . j av a2 s.c o m*/ new RedoAction(undoManager).registerCustomShortcutSet(new CustomShortcutSet(keymap.getShortcuts("$Redo")), textComponent); textComponent.getDocument().addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent event) { undoManager.addEdit(event.getEdit()); } }); }
From source file:com.hp.alm.ali.idea.ui.editor.field.HTMLAreaField.java
License:Apache License
public static void enableCapability(final JTextPane desc, Project project, String value, boolean editable, boolean navigation) { value = removeSmallFont(value);/*from ww w. j a v a 2 s . c o m*/ HTMLEditorKit kit = new HTMLLetterWrappingEditorKit(); desc.setEditorKit(kit); desc.setDocument(kit.createDefaultDocument()); if (!editable && navigation) { value = NavigationDecorator.explodeHtml(project, value); } desc.setText(value); if (!editable) { desc.setCaret(new NonAdjustingCaret()); } desc.addCaretListener(new BodyLimitCaretListener(desc)); if (editable) { String element = checkElements(desc.getDocument().getDefaultRootElement()); if (element != null) { desc.setToolTipText("Found unsupported element '" + element + "', editing is disabled."); editable = false; } } desc.setEditable(editable); if (editable && SpellCheckerManager.isAvailable() && ApplicationManager.getApplication().getComponent(AliConfiguration.class).spellChecker) { desc.getDocument().addDocumentListener(new SpellCheckDocumentListener(project, desc)); } Font font = UIManager.getFont("Label.font"); String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }"; ((HTMLDocument) desc.getDocument()).getStyleSheet().addRule(bodyRule); // AGM uses plain "p" to create lines, we need to avoid excessive spacing this by default creates String paragraphRule = "p { margin-top: 0px; }"; ((HTMLDocument) desc.getDocument()).getStyleSheet().addRule(paragraphRule); Keymap keymap = KeymapManager.getInstance().getActiveKeymap(); new AnAction() { public void actionPerformed(AnActionEvent e) { // following is needed to make copy work in the IDE try { StringSelection selection = new StringSelection(desc.getText(desc.getSelectionStart(), desc.getSelectionEnd() - desc.getSelectionStart())); CopyPasteManager.getInstance().setContents(selection); } catch (Exception ex) { // no clipboard, so what } } }.registerCustomShortcutSet(new CustomShortcutSet(keymap.getShortcuts(IdeActions.ACTION_COPY)), desc); new AnAction() { public void actionPerformed(AnActionEvent e) { // avoid pasting non-supported HTML markup by always converting to plain text Transferable contents = CopyPasteManager.getInstance().getContents(); try { desc.getActionMap().get(DefaultEditorKit.cutAction).actionPerformed(null); desc.getDocument().insertString(desc.getSelectionStart(), (String) contents.getTransferData(DataFlavor.stringFlavor), null); } catch (Exception ex) { // no clipboard, so what } } }.registerCustomShortcutSet(new CustomShortcutSet(keymap.getShortcuts(IdeActions.ACTION_PASTE)), desc); installNavigationShortCuts(desc); }
From source file:com.hp.alm.ali.idea.ui.editor.field.HTMLAreaField.java
License:Apache License
public static void installNavigationShortCuts(final JTextPane desc) { Keymap keymap = KeymapManager.getInstance().getActiveKeymap(); new AnAction() { public void actionPerformed(AnActionEvent e) { // default action moves to the end of the document - override desc.getActionMap().get(DefaultEditorKit.endLineAction).actionPerformed(null); }//from w w w. ja v a 2s . c o m }.registerCustomShortcutSet( new CustomShortcutSet(keymap.getShortcuts(IdeActions.ACTION_EDITOR_MOVE_LINE_END)), desc); new AnAction() { public void actionPerformed(AnActionEvent e) { // default action moves to the beginning of the document - override desc.getActionMap().get(DefaultEditorKit.beginLineAction).actionPerformed(null); } }.registerCustomShortcutSet( new CustomShortcutSet(keymap.getShortcuts(IdeActions.ACTION_EDITOR_MOVE_LINE_START)), desc); new AnAction() { public void actionPerformed(AnActionEvent e) { // default action moves to the end of the document - override desc.getActionMap().get(DefaultEditorKit.selectionEndLineAction).actionPerformed(null); } }.registerCustomShortcutSet( new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_END, InputEvent.SHIFT_MASK)), desc); new AnAction() { public void actionPerformed(AnActionEvent e) { // default action moves to the beginning of the document - override desc.getActionMap().get(DefaultEditorKit.selectionBeginLineAction).actionPerformed(null); } }.registerCustomShortcutSet( new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_HOME, InputEvent.SHIFT_MASK)), desc); new AnAction() { public void actionPerformed(AnActionEvent e) { // when editing html insert hard break new InsertHardBreakAction().actionPerformed(null); } }.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)), desc); }
From source file:com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.java
License:Apache License
public LocalInspectionsPass(@NotNull PsiFile file, @Nullable Document document, int startOffset, int endOffset, @NotNull TextRange priorityRange, boolean ignoreSuppressed, @NotNull HighlightInfoProcessor highlightInfoProcessor) { super(file.getProject(), document, PRESENTABLE_NAME, file, null, new TextRange(startOffset, endOffset), true, highlightInfoProcessor); myStartOffset = startOffset;/*from w w w . ja v a 2 s. c o m*/ myEndOffset = endOffset; myPriorityRange = priorityRange; myIgnoreSuppressed = ignoreSuppressed; setId(Pass.LOCAL_INSPECTIONS); final KeymapManager keymapManager = KeymapManager.getInstance(); if (keymapManager != null) { final Keymap keymap = keymapManager.getActiveKeymap(); myShortcutText = keymap == null ? "" : "(" + KeymapUtil .getShortcutsText(keymap.getShortcuts(IdeActions.ACTION_SHOW_ERROR_DESCRIPTION)) + ")"; } else { myShortcutText = ""; } InspectionProfileWrapper profileToUse = InspectionProjectProfileManagerImpl.getInstanceImpl(myProject) .getProfileWrapper(); Function<InspectionProfileWrapper, InspectionProfileWrapper> custom = file .getUserData(InspectionProfileWrapper.CUSTOMIZATION_KEY); if (custom != null) { profileToUse = custom.fun(profileToUse); } myProfileWrapper = profileToUse; assert myProfileWrapper != null; mySeverityRegistrar = ((SeverityProvider) myProfileWrapper.getInspectionProfile().getProfileManager()) .getSeverityRegistrar(); // initial guess setProgressLimit(300 * 2); }
From source file:com.intellij.codeInsight.generation.OverrideImplementUtil.java
License:Apache License
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/* w ww . j a v a 2 s. co m*/ 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()); } }); } }); } }