1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-08-18 10:31:44 +02:00

Compare commits

..

9 Commits
0.27 ... 0.28

Author SHA1 Message Date
Andrey Vlasovskikh
0241b58777 Updated change notes 2013-04-06 22:29:58 +04:00
Andrey Vlasovskikh
97a2c73efe Updated changelog 2013-04-06 22:19:50 +04:00
Andrey Vlasovskikh
5f1e46ca82 Merge branch 'vim-479' 2013-04-06 21:59:50 +04:00
Andrey Vlasovskikh
805779144e Fixed copying second keystrokes in Reconfigure Vim keymap 2013-04-06 21:50:12 +04:00
Andrey Vlasovskikh
c65e21708c VIM-478 Fixed bug in reconfiguring Vim keymap based on user-defined keymaps 2013-04-06 21:21:22 +04:00
Andrey Vlasovskikh
08e546b677 Fixed NPE in VimKeyMapUtil.installKeyBoardBindings 2013-04-06 19:57:27 +04:00
Andrey Vlasovskikh
11cf8454ad VIM-479 Don't try to put read-only editors into insert mode 2013-04-06 19:53:57 +04:00
Andrey Vlasovskikh
c3494803dc Removed unused code 2013-04-06 18:39:56 +04:00
Andrey Vlasovskikh
c84496b942 Suggest reconfiguring keymap during update only for Macs 2013-04-06 18:12:15 +04:00
6 changed files with 68 additions and 45 deletions

View File

@@ -4,6 +4,17 @@ The Changelog
History of changes in IdeaVim for the IntelliJ platform.
0.28, 2013-04-06
----------------
A bugfix release.
Bug fixes:
* VIM-478 Fixed reconfigure Vim keymap for user-defined base keymaps
* VIM-479 Don't try to activate insert mode for diff view
0.27, 2013-04-03
----------------

View File

@@ -1,4 +1,4 @@
version-id:0.27
version-id:0.28
platform-version:110.0
idea.download.url=http://download.jetbrains.com/idea/ideaIU-12.0.zip
idea.download.url=http://download.jetbrains.com/idea/ideaIU-12.1.zip
build.number=x

View File

@@ -3,6 +3,10 @@
<id>IdeaVIM</id>
<change-notes>
<![CDATA[
<p>0.28:</p>
<ul>
<li>Fixed reconfigure Vim keymap for user-defined base keymaps</li>
</ul>
<p>0.27:</p>
<ul>
<li>Better Vim keymaps for Mac OS X</li>

View File

@@ -6,24 +6,19 @@ import com.google.common.io.Resources;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.actionSystem.Shortcut;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ApplicationNamesInfo;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.application.ex.ApplicationEx;
import com.intellij.openapi.application.ex.ApplicationManagerEx;
import com.intellij.openapi.components.impl.stores.StorageUtil;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.keymap.Keymap;
import com.intellij.openapi.keymap.KeymapManager;
import com.intellij.openapi.keymap.impl.KeymapImpl;
import com.intellij.openapi.keymap.impl.KeymapManagerImpl;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.maddyhome.idea.vim.ui.VimKeymapDialog;
import org.jdom.Document;
import org.jdom.Element;
@@ -31,6 +26,9 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.*;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import static com.google.common.io.ByteStreams.toByteArray;
@@ -67,9 +65,11 @@ public class VimKeyMapUtil {
final byte[] bytes = toByteArray(retrieveSourceKeymapStream());
Files.write(bytes, new File(INSTALLED_VIM_KEYMAP_PATH));
final Document document = StorageUtil.loadDocument(bytes);
if (!ApplicationManager.getApplication().isUnitTestMode()) {
if (document != null && !ApplicationManager.getApplication().isUnitTestMode()) {
// Prompt user to select the parent for the Vim keyboard
configureVimParentKeymap(INSTALLED_VIM_KEYMAP_PATH, document, true);
if (!configureVimParentKeymap(INSTALLED_VIM_KEYMAP_PATH, document, true)) {
return false;
}
}
installKeymap(document);
} catch (IOException e) {
@@ -97,48 +97,53 @@ public class VimKeyMapUtil {
keymapManager.addKeymap(vimKeyMap);
}
private static void requestRestartOrShutdown(final Project project) {
final ApplicationEx app = ApplicationManagerEx.getApplicationEx();
if (app.isRestartCapable()) {
if (Messages.showDialog(project, "Restart " + ApplicationNamesInfo.getInstance().getProductName() + " to activate changes?",
VimPlugin.IDEAVIM_NOTIFICATION_TITLE, new String[]{"&Restart", "&Postpone"}, 0,
Messages.getQuestionIcon()) == 0) {
app.restart();
}
} else {
if (Messages.showDialog(project, "Shut down " + ApplicationNamesInfo.getInstance().getProductName() + " to activate changes?",
VimPlugin.IDEAVIM_NOTIFICATION_TITLE, new String[]{"&Shut Down", "&Postpone"}, 0,
Messages.getQuestionIcon()) == 0) {
app.exit(true);
}
}
}
/**
* Changes parent keymap for the Vim
*
* @return true if document was changed successfully
*/
private static boolean configureVimParentKeymap(final String path, @NotNull final Document document, final boolean showNotification) throws IOException {
private static boolean configureVimParentKeymap(final String path, @NotNull final Document document,
final boolean showNotification)
throws IOException, InvalidDataException {
final Element rootElement = document.getRootElement();
final String parentKeymap = rootElement.getAttributeValue("parent");
final VimKeymapDialog vimKeymapDialog = new VimKeymapDialog(parentKeymap);
final String parentKeymapName = rootElement.getAttributeValue("parent");
final VimKeymapDialog vimKeymapDialog = new VimKeymapDialog(parentKeymapName);
vimKeymapDialog.show();
if (vimKeymapDialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
return false;
}
rootElement.removeAttribute("parent");
final Keymap selectedKeymap = vimKeymapDialog.getSelectedKeymap();
final String keymapName = selectedKeymap.getName();
rootElement.setAttribute("parent", keymapName);
final Keymap parentKeymap = vimKeymapDialog.getSelectedKeymap();
final String keymapName = parentKeymap.getName();
VimKeymapConflictResolveUtil.resolveConflicts(rootElement, parentKeymap);
// We cannot set a user-defined modifiable keymap as the parent of our Vim keymap so we have to copy its shortcuts
if (parentKeymap.canModify()) {
final KeymapImpl vimKeyMap = new KeymapImpl();
final KeymapManager keymapManager = KeymapManager.getInstance();
final KeymapManagerImpl keymapManagerImpl = (KeymapManagerImpl)keymapManager;
final Keymap[] allKeymaps = keymapManagerImpl.getAllKeymaps();
vimKeyMap.readExternal(rootElement, allKeymaps);
final HashSet<String> ownActions = new HashSet<String>(Arrays.asList(vimKeyMap.getOwnActionIds()));
final KeymapImpl parentKeymapImpl = (KeymapImpl)parentKeymap;
for (String parentAction : parentKeymapImpl.getOwnActionIds()) {
if (!ownActions.contains(parentAction)) {
final List<Shortcut> shortcuts = Arrays.asList(parentKeymap.getShortcuts(parentAction));
rootElement.addContent(VimKeymapConflictResolveUtil.createActionElement(parentAction, shortcuts));
}
}
final Keymap grandParentKeymap = parentKeymap.getParent();
rootElement.setAttribute("parent", grandParentKeymap.getName());
}
else {
rootElement.setAttribute("parent", keymapName);
}
VimPlugin.getInstance().setPreviousKeyMap(keymapName);
VimKeymapConflictResolveUtil.resolveConflicts(rootElement, selectedKeymap);
// Save modified keymap to the file
JDOMUtil.writeDocument(document, path, "\n");
if (showNotification) {
Notifications.Bus.notify(new Notification(VimPlugin.IDEAVIM_NOTIFICATION_ID, VimPlugin.IDEAVIM_NOTIFICATION_TITLE,
"Successfully configured vim keymap to be based on " +
selectedKeymap.getPresentableName(),
parentKeymap.getPresentableName(),
NotificationType.INFORMATION));
}
@@ -214,9 +219,4 @@ public class VimKeyMapUtil {
Notifications.Bus.notify(new Notification(VimPlugin.IDEAVIM_NOTIFICATION_ID, VimPlugin.IDEAVIM_NOTIFICATION_TITLE,
message + String.valueOf(e), NotificationType.ERROR));
}
@Nullable
public static VirtualFile getVimKeymapFile() {
return LocalFileSystem.getInstance().refreshAndFindFileByPath(INSTALLED_VIM_KEYMAP_PATH);
}
}

View File

@@ -160,14 +160,21 @@ public class VimKeymapConflictResolveUtil {
}
}
private static Element createActionElement(String actionName, List<Shortcut> shortcuts) {
public static Element createActionElement(String actionName, List<Shortcut> shortcuts) {
final Element overridesAction = new Element(ACTION_TAG);
overridesAction.setAttribute(ID_ATTRIBUTE, actionName);
for (Shortcut shortcut : shortcuts) {
if (shortcut instanceof KeyboardShortcut) {
KeyboardShortcut keyboardShortcut = (KeyboardShortcut)shortcut;
overridesAction
.addContent(createShortcutElement(KEYBOARD_SHORTCUT_TAG, FIRST_KEYSTROKE_ATTRIBUTE, KeymapImpl.getKeyShortcutString(keyboardShortcut.getFirstKeyStroke())));
final String firstShortcutString = KeymapImpl.getKeyShortcutString(keyboardShortcut.getFirstKeyStroke());
final Element shortcutElement = createShortcutElement(KEYBOARD_SHORTCUT_TAG, FIRST_KEYSTROKE_ATTRIBUTE,
firstShortcutString);
overridesAction.addContent(shortcutElement);
final KeyStroke secondKeyStroke = keyboardShortcut.getSecondKeyStroke();
if (secondKeyStroke != null) {
final String secondShortcutString = KeymapImpl.getKeyShortcutString(secondKeyStroke);
shortcutElement.setAttribute(SECOND_KEYSTROKE_ATTRIBUTE, secondShortcutString);
}
}
else if (shortcut instanceof MouseShortcut) {
overridesAction.addContent(createShortcutElement(MOUSE_SHORTCUT_TAG, KEYSTROKE_ATTRIBUTE, getMouseShortcutString((MouseShortcut)shortcut)));

View File

@@ -167,7 +167,7 @@ public class VimPlugin implements ApplicationComponent, PersistentStateComponent
private void updateState() {
if (isEnabled() && !ApplicationManager.getApplication().isUnitTestMode()) {
boolean requiresRestart = false;
if (previousStateVersion < 1 && VimKeyMapUtil.isVimKeymapInstalled()) {
if (previousStateVersion < 1 && SystemInfo.isMac && VimKeyMapUtil.isVimKeymapInstalled()) {
if (Messages.showYesNoDialog("Vim keymap generator has been updated to create keymaps more compatible " +
"with base keymaps.\n\nDo you want to reconfigure your Vim keymap?\n\n" +
"Warning: Any custom shortcuts will be lost!\n\n" +
@@ -250,7 +250,8 @@ public class VimPlugin implements ApplicationComponent, PersistentStateComponent
if (VimPlugin.isEnabled()) {
// Turn on insert mode if editor doesn't have any file
if (!EditorData.isFileEditor(editor) && !CommandState.inInsertMode(editor)) {
if (!EditorData.isFileEditor(editor) && editor.getDocument().isWritable() &&
!CommandState.inInsertMode(editor)) {
KeyHandler.getInstance().handleKey(editor, KeyStroke.getKeyStroke('i'), new EditorDataContext(editor));
}
editor.getSettings().setBlockCursor(!CommandState.inInsertMode(editor));