Search in sources :

Example 6 with Keymap

use of com.intellij.openapi.keymap.Keymap in project ideavim by JetBrains.

the class KeyGroup method getKeymapActions.

@NotNull
private static List<AnAction> getKeymapActions(@NotNull KeyStroke keyStroke) {
    final List<AnAction> results = new ArrayList<AnAction>();
    final Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
    for (String id : keymap.getActionIds(keyStroke)) {
        final AnAction action = ActionManager.getInstance().getAction(id);
        if (action != null) {
            results.add(action);
        }
    }
    return results;
}
Also used : Keymap(com.intellij.openapi.keymap.Keymap) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with Keymap

use of com.intellij.openapi.keymap.Keymap in project ideavim by JetBrains.

the class KeyGroup method getKeymapConflicts.

@NotNull
public List<AnAction> getKeymapConflicts(@NotNull KeyStroke keyStroke) {
    final KeymapManagerEx keymapManager = KeymapManagerEx.getInstanceEx();
    final Keymap keymap = keymapManager.getActiveKeymap();
    final KeyboardShortcut shortcut = new KeyboardShortcut(keyStroke, null);
    final Map<String, ? extends List<KeyboardShortcut>> conflicts = keymap.getConflicts("", shortcut);
    final List<AnAction> actions = new ArrayList<AnAction>();
    for (String actionId : conflicts.keySet()) {
        final AnAction action = ActionManagerEx.getInstanceEx().getAction(actionId);
        if (action != null) {
            actions.add(action);
        }
    }
    return actions;
}
Also used : KeymapManagerEx(com.intellij.openapi.keymap.ex.KeymapManagerEx) Keymap(com.intellij.openapi.keymap.Keymap) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with Keymap

use of com.intellij.openapi.keymap.Keymap in project ideavim by JetBrains.

the class VimPlugin method updateState.

private void updateState() {
    if (isEnabled() && !ApplicationManager.getApplication().isUnitTestMode()) {
        if (SystemInfo.isMac) {
            final MacKeyRepeat keyRepeat = MacKeyRepeat.getInstance();
            final Boolean enabled = keyRepeat.isEnabled();
            final Boolean isKeyRepeat = editor.isKeyRepeat();
            if ((enabled == null || !enabled) && (isKeyRepeat == null || isKeyRepeat)) {
                if (Messages.showYesNoDialog("Do you want to enable repeating keys in Mac OS X on press and hold?\n\n" + "(You can do it manually by running 'defaults write -g " + "ApplePressAndHoldEnabled 0' in the console).", IDEAVIM_NOTIFICATION_TITLE, Messages.getQuestionIcon()) == Messages.YES) {
                    editor.setKeyRepeat(true);
                    keyRepeat.setEnabled(true);
                } else {
                    editor.setKeyRepeat(false);
                }
            }
        }
        if (previousStateVersion > 0 && previousStateVersion < 3) {
            final KeymapManagerEx manager = KeymapManagerEx.getInstanceEx();
            Keymap keymap = null;
            if (previousKeyMap != null) {
                keymap = manager.getKeymap(previousKeyMap);
            }
            if (keymap == null) {
                keymap = manager.getKeymap(DefaultKeymap.getInstance().getDefaultKeymapName());
            }
            assert keymap != null : "Default keymap not found";
            new Notification(VimPlugin.IDEAVIM_STICKY_NOTIFICATION_ID, VimPlugin.IDEAVIM_NOTIFICATION_TITLE, String.format("IdeaVim plugin doesn't use the special \"Vim\" keymap any longer. " + "Switching to \"%s\" keymap.<br/><br/>" + "Now it is possible to set up:<br/>" + "<ul>" + "<li>Vim keys in your ~/.ideavimrc file using key mapping commands</li>" + "<li>IDE action shortcuts in \"File | Settings | Keymap\"</li>" + "<li>Vim or IDE handlers for conflicting shortcuts in <a href='#settings'>Vim Emulation</a> settings</li>" + "</ul>", keymap.getPresentableName()), NotificationType.INFORMATION, new NotificationListener.Adapter() {

                @Override
                protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
                    ShowSettingsUtil.getInstance().editConfigurable((Project) null, new VimEmulationConfigurable());
                }
            }).notify(null);
            manager.setActiveKeymap(keymap);
        }
        if (previousStateVersion > 0 && previousStateVersion < 4) {
            new Notification(VimPlugin.IDEAVIM_STICKY_NOTIFICATION_ID, VimPlugin.IDEAVIM_NOTIFICATION_TITLE, "The ~/.vimrc file is no longer read by default, use ~/.ideavimrc instead. You can read it from your " + "~/.ideavimrc using this command:<br/><br/>" + "<code>source ~/.vimrc</code>", NotificationType.INFORMATION).notify(null);
        }
    }
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) MacKeyRepeat(com.maddyhome.idea.vim.helper.MacKeyRepeat) KeymapManagerEx(com.intellij.openapi.keymap.ex.KeymapManagerEx) EditorFactoryAdapter(com.intellij.openapi.editor.event.EditorFactoryAdapter) ProjectManagerAdapter(com.intellij.openapi.project.ProjectManagerAdapter) VimEmulationConfigurable(com.maddyhome.idea.vim.ui.VimEmulationConfigurable) NotNull(org.jetbrains.annotations.NotNull) Keymap(com.intellij.openapi.keymap.Keymap) DefaultKeymap(com.intellij.openapi.keymap.impl.DefaultKeymap)

Example 9 with Keymap

use of com.intellij.openapi.keymap.Keymap in project kotlin by JetBrains.

the class AndroidLintExternalAnnotator method getShowMoreShortCut.

private String getShowMoreShortCut() {
    if (myShortcutText == null) {
        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 = "";
        }
    }
    return myShortcutText;
}
Also used : KeymapManager(com.intellij.openapi.keymap.KeymapManager) Keymap(com.intellij.openapi.keymap.Keymap)

Example 10 with Keymap

use of com.intellij.openapi.keymap.Keymap in project intellij-community by JetBrains.

the class GotoActionAction method createPopup.

@Nullable
private static ChooseByNamePopup createPopup(@Nullable Project project, @NotNull final GotoActionModel model, String initialText, int initialIndex, final Component component, final AnActionEvent e) {
    ChooseByNamePopup oldPopup = project == null ? null : project.getUserData(ChooseByNamePopup.CHOOSE_BY_NAME_POPUP_IN_PROJECT_KEY);
    if (oldPopup != null) {
        oldPopup.close(false);
    }
    final Disposable disposable = Disposer.newDisposable();
    final ChooseByNamePopup popup = new ChooseByNamePopup(project, model, new GotoActionItemProvider(model), oldPopup, initialText, false, initialIndex) {

        private boolean myPaintInternalInfo;

        @Override
        protected void initUI(Callback callback, ModalityState modalityState, boolean allowMultipleSelection) {
            super.initUI(callback, modalityState, allowMultipleSelection);
            myList.addListSelectionListener(new ListSelectionListener() {

                @Override
                public void valueChanged(ListSelectionEvent e) {
                    Object value = myList.getSelectedValue();
                    String text = getText(value);
                    if (text != null && myDropdownPopup != null) {
                        myDropdownPopup.setAdText(text, SwingConstants.LEFT);
                    }
                    String description = getValueDescription(value);
                    ActionMenu.showDescriptionInStatusBar(true, myList, description);
                }

                @Nullable
                private String getText(@Nullable Object o) {
                    if (o instanceof GotoActionModel.MatchedValue) {
                        GotoActionModel.MatchedValue mv = (GotoActionModel.MatchedValue) o;
                        if (myPaintInternalInfo) {
                            if (mv.value instanceof GotoActionModel.ActionWrapper) {
                                AnAction action = ((GotoActionModel.ActionWrapper) mv.value).getAction();
                                String actionId = ActionManager.getInstance().getId(action);
                                return StringUtil.notNullize(actionId, "class: " + action.getClass().getName());
                            }
                        }
                        if (mv.value instanceof BooleanOptionDescription || mv.value instanceof GotoActionModel.ActionWrapper && ((GotoActionModel.ActionWrapper) mv.value).getAction() instanceof ToggleAction) {
                            return "Press " + KeymapUtil.getKeystrokeText(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)) + " to toggle option";
                        }
                    }
                    return getAdText();
                }
            });
            myList.addMouseMotionListener(new MouseMotionAdapter() {

                @Override
                public void mouseMoved(MouseEvent e) {
                    int index = myList.locationToIndex(e.getPoint());
                    if (index == -1)
                        return;
                    Object value = myList.getModel().getElementAt(index);
                    String description = getValueDescription(value);
                    ActionMenu.showDescriptionInStatusBar(true, myList, description);
                }
            });
            if (Registry.is("show.configurables.ids.in.settings")) {
                new HeldDownKeyListener() {

                    @Override
                    protected void heldKeyTriggered(JComponent component, boolean pressed) {
                        myPaintInternalInfo = pressed;
                        // an easy way to repaint the AdText
                        ListSelectionEvent event = new ListSelectionEvent(this, -1, -1, false);
                        for (ListSelectionListener listener : myList.getListSelectionListeners()) {
                            listener.valueChanged(event);
                        }
                    }
                }.installOn(myTextField);
            }
        }

        @Nullable
        private String getValueDescription(@Nullable Object value) {
            if (value instanceof GotoActionModel.MatchedValue) {
                GotoActionModel.MatchedValue mv = (GotoActionModel.MatchedValue) value;
                if (mv.value instanceof GotoActionModel.ActionWrapper) {
                    AnAction action = ((GotoActionModel.ActionWrapper) mv.value).getAction();
                    return action.getTemplatePresentation().getDescription();
                }
            }
            return null;
        }

        @NotNull
        @Override
        protected Set<Object> filter(@NotNull Set<Object> elements) {
            return super.filter(model.sortItems(elements));
        }

        @Override
        protected boolean closeForbidden(boolean ok) {
            if (!ok)
                return false;
            Object element = getChosenElement();
            return element instanceof GotoActionModel.MatchedValue && processOptionInplace(((GotoActionModel.MatchedValue) element).value, this, component, e) || super.closeForbidden(true);
        }

        @Override
        public void setDisposed(boolean disposedFlag) {
            super.setDisposed(disposedFlag);
            Disposer.dispose(disposable);
            ActionMenu.showDescriptionInStatusBar(true, myList, null);
            for (ListSelectionListener listener : myList.getListSelectionListeners()) {
                myList.removeListSelectionListener(listener);
            }
            UIUtil.dispose(myList);
        }
    };
    ApplicationManager.getApplication().getMessageBus().connect(disposable).subscribe(ProgressWindow.TOPIC, new ProgressWindow.Listener() {

        @Override
        public void progressWindowCreated(ProgressWindow pw) {
            Disposer.register(pw, new Disposable() {

                @Override
                public void dispose() {
                    if (!popup.checkDisposed()) {
                        popup.repaintList();
                    }
                }
            });
        }
    });
    if (project != null) {
        project.putUserData(ChooseByNamePopup.CHOOSE_BY_NAME_POPUP_IN_PROJECT_KEY, popup);
    }
    popup.addMouseClickListener(new MouseAdapter() {

        @Override
        public void mouseClicked(@NotNull MouseEvent me) {
            Object element = popup.getSelectionByPoint(me.getPoint());
            if (element instanceof GotoActionModel.MatchedValue) {
                if (processOptionInplace(((GotoActionModel.MatchedValue) element).value, popup, component, e)) {
                    me.consume();
                }
            }
        }
    });
    CustomShortcutSet shortcutSet = new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_SHOW_INTENTION_ACTIONS));
    new DumbAwareAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            Object o = popup.getChosenElement();
            if (o instanceof GotoActionModel.MatchedValue) {
                Comparable value = ((GotoActionModel.MatchedValue) o).value;
                if (value instanceof GotoActionModel.ActionWrapper) {
                    GotoActionModel.ActionWrapper aw = (GotoActionModel.ActionWrapper) value;
                    boolean available = aw.isAvailable();
                    if (available) {
                        AnAction action = aw.getAction();
                        String id = ActionManager.getInstance().getId(action);
                        KeymapManagerImpl km = ((KeymapManagerImpl) KeymapManager.getInstance());
                        Keymap k = km.getActiveKeymap();
                        if (!k.canModify())
                            return;
                        KeymapPanel.addKeyboardShortcut(id, ActionShortcutRestrictions.getInstance().getForActionId(id), k, component);
                        popup.repaintListImmediate();
                    }
                }
            }
        }
    }.registerCustomShortcutSet(shortcutSet, popup.getTextField(), disposable);
    return popup;
}
Also used : Set(java.util.Set) ListSelectionEvent(javax.swing.event.ListSelectionEvent) NotNull(org.jetbrains.annotations.NotNull) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) GotoActionItemProvider(com.intellij.ide.util.gotoByName.GotoActionItemProvider) ChooseByNamePopup(com.intellij.ide.util.gotoByName.ChooseByNamePopup) Disposable(com.intellij.openapi.Disposable) GotoActionModel(com.intellij.ide.util.gotoByName.GotoActionModel) HeldDownKeyListener(com.intellij.ui.HeldDownKeyListener) ListSelectionListener(javax.swing.event.ListSelectionListener) ProgressWindow(com.intellij.openapi.progress.util.ProgressWindow) BooleanOptionDescription(com.intellij.ide.ui.search.BooleanOptionDescription) ModalityState(com.intellij.openapi.application.ModalityState) Nullable(org.jetbrains.annotations.Nullable) KeymapManagerImpl(com.intellij.openapi.keymap.impl.KeymapManagerImpl) Keymap(com.intellij.openapi.keymap.Keymap) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Keymap (com.intellij.openapi.keymap.Keymap)47 Shortcut (com.intellij.openapi.actionSystem.Shortcut)14 KeymapManagerEx (com.intellij.openapi.keymap.ex.KeymapManagerEx)10 NotNull (org.jetbrains.annotations.NotNull)10 KeyboardShortcut (com.intellij.openapi.actionSystem.KeyboardShortcut)7 Nullable (org.jetbrains.annotations.Nullable)7 AnAction (com.intellij.openapi.actionSystem.AnAction)6 KeymapManager (com.intellij.openapi.keymap.KeymapManager)5 ActionManager (com.intellij.openapi.actionSystem.ActionManager)4 MacOSDefaultKeymap (com.intellij.openapi.keymap.impl.MacOSDefaultKeymap)4 Pair (com.intellij.openapi.util.Pair)4 FactoryMap (com.intellij.util.containers.FactoryMap)4 THashMap (gnu.trove.THashMap)4 THashSet (gnu.trove.THashSet)4 DefaultKeymap (com.intellij.openapi.keymap.impl.DefaultKeymap)2 KeymapImpl (com.intellij.openapi.keymap.impl.KeymapImpl)2 KeymapManagerImpl (com.intellij.openapi.keymap.impl.KeymapManagerImpl)2 ToolWindow (com.intellij.openapi.wm.ToolWindow)2 KeyEvent (java.awt.event.KeyEvent)2 NonNls (org.jetbrains.annotations.NonNls)2