Search in sources :

Example 1 with VimEmulationConfigurable

use of com.maddyhome.idea.vim.ui.VimEmulationConfigurable 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 2 with VimEmulationConfigurable

use of com.maddyhome.idea.vim.ui.VimEmulationConfigurable in project ideavim by JetBrains.

the class VimShortcutKeyAction method notifyAboutShortcutConflict.

private void notifyAboutShortcutConflict(@NotNull final KeyStroke keyStroke) {
    VimPlugin.getKey().getSavedShortcutConflicts().put(keyStroke, ShortcutOwner.VIM);
    final String message = String.format("Using the <b>%s</b> shortcut for Vim emulation.<br/>" + "You can redefine it as an <a href='#ide'>IDE shortcut</a> or " + "configure its handler in <a href='#settings'>Vim Emulation</a> settings.", KeymapUtil.getShortcutText(new KeyboardShortcut(keyStroke, null)));
    final NotificationListener listener = new NotificationListener.Adapter() {

        @Override
        protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
            final String description = e.getDescription();
            if ("#ide".equals(description)) {
                VimPlugin.getKey().getSavedShortcutConflicts().put(keyStroke, ShortcutOwner.IDE);
                notification.expire();
            } else if ("#settings".equals(description)) {
                ShowSettingsUtil.getInstance().editConfigurable((Project) null, new VimEmulationConfigurable());
            }
        }
    };
    final Notification notification = new Notification(VimPlugin.IDEAVIM_NOTIFICATION_ID, VimPlugin.IDEAVIM_NOTIFICATION_TITLE, message, NotificationType.INFORMATION, listener);
    notification.notify(null);
}
Also used : Project(com.intellij.openapi.project.Project) HyperlinkEvent(javax.swing.event.HyperlinkEvent) VimEmulationConfigurable(com.maddyhome.idea.vim.ui.VimEmulationConfigurable) NotNull(org.jetbrains.annotations.NotNull) Notification(com.intellij.notification.Notification) NotificationListener(com.intellij.notification.NotificationListener)

Aggregations

VimEmulationConfigurable (com.maddyhome.idea.vim.ui.VimEmulationConfigurable)2 HyperlinkEvent (javax.swing.event.HyperlinkEvent)2 NotNull (org.jetbrains.annotations.NotNull)2 Notification (com.intellij.notification.Notification)1 NotificationListener (com.intellij.notification.NotificationListener)1 EditorFactoryAdapter (com.intellij.openapi.editor.event.EditorFactoryAdapter)1 Keymap (com.intellij.openapi.keymap.Keymap)1 KeymapManagerEx (com.intellij.openapi.keymap.ex.KeymapManagerEx)1 DefaultKeymap (com.intellij.openapi.keymap.impl.DefaultKeymap)1 Project (com.intellij.openapi.project.Project)1 ProjectManagerAdapter (com.intellij.openapi.project.ProjectManagerAdapter)1 MacKeyRepeat (com.maddyhome.idea.vim.helper.MacKeyRepeat)1