示例#1
0
 private static void installKeymap(@Nullable Document document) throws InvalidDataException {
   if (document == null) {
     throw new InvalidDataException();
   }
   final KeymapImpl vimKeyMap = new KeymapImpl();
   final KeymapManagerImpl keymapManager = (KeymapManagerImpl) KeymapManager.getInstance();
   final Keymap[] allKeymaps = keymapManager.getAllKeymaps();
   vimKeyMap.readExternal(document.getRootElement(), allKeymaps);
   keymapManager.addKeymap(vimKeyMap);
 }
示例#2
0
  /**
   * 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, InvalidDataException {
    final Element rootElement = document.getRootElement();
    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 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);
    // 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 "
                  + parentKeymap.getPresentableName(),
              NotificationType.INFORMATION));
    }

    return true;
  }
  private static void patchKeymap() {
    Set<String> droppedActions =
        ContainerUtil.newHashSet(
            "AddToFavoritesPopup",
            "DatabaseView.ImportDataSources",
            "CompileDirty",
            "Compile",
            // hidden
            "AddNewFavoritesList",
            "EditFavorites",
            "RenameFavoritesList",
            "RemoveFavoritesList");
    KeymapManagerEx keymapManager = KeymapManagerEx.getInstanceEx();

    for (Keymap keymap : keymapManager.getAllKeymaps()) {
      if (keymap.canModify()) continue;

      KeymapImpl keymapImpl = (KeymapImpl) keymap;

      for (String id : keymapImpl.getOwnActionIds()) {
        if (droppedActions.contains(id)) keymapImpl.clearOwnActionsId(id);
      }
    }
  }