private static void updateShortcuts(StringBuffer text) {
   int lastIndex = 0;
   while (true) {
     lastIndex = text.indexOf(SHORTCUT_ENTITY, lastIndex);
     if (lastIndex < 0) return;
     final int actionIdStart = lastIndex + SHORTCUT_ENTITY.length();
     int actionIdEnd = text.indexOf(";", actionIdStart);
     if (actionIdEnd < 0) {
       return;
     }
     final String actionId = text.substring(actionIdStart, actionIdEnd);
     String shortcutText =
         getShortcutText(actionId, KeymapManager.getInstance().getActiveKeymap());
     if (shortcutText == null) {
       Keymap defKeymap =
           KeymapManager.getInstance()
               .getKeymap(DefaultKeymap.getInstance().getDefaultKeymapName());
       if (defKeymap != null) {
         shortcutText = getShortcutText(actionId, defKeymap);
         if (shortcutText != null) {
           shortcutText += " in default keymap";
         }
       }
     }
     if (shortcutText == null) {
       shortcutText = "<no shortcut for action " + actionId + ">";
     }
     text.replace(lastIndex, actionIdEnd + 1, shortcutText);
     lastIndex += shortcutText.length();
   }
 }
Esempio n. 2
0
 private void registerShortcuts() {
   ActionManager actionManager = ActionManager.getInstance();
   actionManager
       .getAction(XDebuggerActions.SET_VALUE)
       .registerCustomShortcutSet(
           new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0)), this);
   actionManager
       .getAction(XDebuggerActions.COPY_VALUE)
       .registerCustomShortcutSet(CommonShortcuts.getCopy(), this);
   actionManager
       .getAction(XDebuggerActions.JUMP_TO_SOURCE)
       .registerCustomShortcutSet(CommonShortcuts.getEditSource(), this);
   Shortcut[] editTypeShortcuts =
       KeymapManager.getInstance()
           .getActiveKeymap()
           .getShortcuts(XDebuggerActions.EDIT_TYPE_SOURCE);
   actionManager
       .getAction(XDebuggerActions.JUMP_TO_TYPE_SOURCE)
       .registerCustomShortcutSet(new CustomShortcutSet(editTypeShortcuts), this);
   actionManager
       .getAction(XDebuggerActions.MARK_OBJECT)
       .registerCustomShortcutSet(
           new CustomShortcutSet(
               KeymapManager.getInstance().getActiveKeymap().getShortcuts("ToggleBookmark")),
           this);
 }
  public static InputEvent getInputEvent(String actionName) {
    final Shortcut[] shortcuts =
        KeymapManager.getInstance().getActiveKeymap().getShortcuts(actionName);
    KeyStroke keyStroke = null;
    for (Shortcut each : shortcuts) {
      if (each instanceof KeyboardShortcut) {
        keyStroke = ((KeyboardShortcut) each).getFirstKeyStroke();
        if (keyStroke != null) break;
      }
    }

    if (keyStroke != null) {
      return new KeyEvent(
          JOptionPane.getRootFrame(),
          KeyEvent.KEY_PRESSED,
          System.currentTimeMillis(),
          keyStroke.getModifiers(),
          keyStroke.getKeyCode(),
          keyStroke.getKeyChar(),
          KeyEvent.KEY_LOCATION_STANDARD);
    } else {
      return new MouseEvent(
          JOptionPane.getRootFrame(),
          MouseEvent.MOUSE_PRESSED,
          0,
          0,
          0,
          0,
          1,
          false,
          MouseEvent.BUTTON1);
    }
  }
  @SuppressWarnings("HardCodedStringLiteral")
  private boolean togglePopup(KeyEvent e) {
    final KeyStroke stroke = KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers());
    final Object action = ((InputMap) UIManager.get("ComboBox.ancestorInputMap")).get(stroke);
    if ("selectNext".equals(action)) {
      if (!isPopupShowing()) {
        return true;
      } else {
        return false;
      }
    } else if ("togglePopup".equals(action)) {
      if (isPopupShowing()) {
        closePopup();
      } else {
        suggestCompletion(true, true);
      }
      return true;
    } else {
      final Keymap active = KeymapManager.getInstance().getActiveKeymap();
      final String[] ids = active.getActionIds(stroke);
      if (ids.length > 0 && IdeActions.ACTION_CODE_COMPLETION.equals(ids[0])) {
        suggestCompletion(true, true);
      }
    }

    return false;
  }
  EditorsSplitters(
      final FileEditorManagerImpl manager,
      DockManager dockManager,
      boolean createOwnDockableContainer) {
    super(new BorderLayout());
    myManager = manager;
    myFocusWatcher = new MyFocusWatcher();
    setFocusTraversalPolicy(new MyFocusTraversalPolicy());
    clear();

    if (createOwnDockableContainer) {
      DockableEditorTabbedContainer dockable =
          new DockableEditorTabbedContainer(myManager.getProject(), this, false);
      Disposer.register(manager.getProject(), dockable);
      dockManager.register(dockable);
    }
    KeymapManagerListener keymapListener =
        new KeymapManagerListener() {
          @Override
          public void activeKeymapChanged(Keymap keymap) {
            invalidate();
            repaint();
          }
        };
    KeymapManager.getInstance().addKeymapManagerListener(keymapListener, this);
  }
  protected JLabel createActionLabel(
      final AnAction anAction,
      final String anActionName,
      final Color fg,
      final Color bg,
      final Icon icon) {
    final LayeredIcon layeredIcon = new LayeredIcon(2);
    layeredIcon.setIcon(EMPTY_ICON, 0);
    if (icon != null
        && icon.getIconWidth() <= EMPTY_ICON.getIconWidth()
        && icon.getIconHeight() <= EMPTY_ICON.getIconHeight()) {
      layeredIcon.setIcon(
          icon,
          1,
          (-icon.getIconWidth() + EMPTY_ICON.getIconWidth()) / 2,
          (EMPTY_ICON.getIconHeight() - icon.getIconHeight()) / 2);
    }

    final Shortcut[] shortcutSet =
        KeymapManager.getInstance().getActiveKeymap().getShortcuts(getActionId(anAction));
    final String actionName =
        anActionName
            + (shortcutSet != null && shortcutSet.length > 0
                ? " (" + KeymapUtil.getShortcutText(shortcutSet[0]) + ")"
                : "");
    final JLabel actionLabel = new JLabel(actionName, layeredIcon, SwingConstants.LEFT);
    actionLabel.setBackground(bg);
    actionLabel.setForeground(fg);
    return actionLabel;
  }
  @Override
  protected JComponent createCenterPanel() {
    JPanel panel = new JPanel(new BorderLayout());

    // Toolbar

    DefaultActionGroup group = new DefaultActionGroup();

    fillToolbarActions(group);

    group.addSeparator();

    ExpandAllAction expandAllAction = new ExpandAllAction();
    expandAllAction.registerCustomShortcutSet(
        new CustomShortcutSet(
            KeymapManager.getInstance()
                .getActiveKeymap()
                .getShortcuts(IdeActions.ACTION_EXPAND_ALL)),
        myTree);
    group.add(expandAllAction);

    CollapseAllAction collapseAllAction = new CollapseAllAction();
    collapseAllAction.registerCustomShortcutSet(
        new CustomShortcutSet(
            KeymapManager.getInstance()
                .getActiveKeymap()
                .getShortcuts(IdeActions.ACTION_COLLAPSE_ALL)),
        myTree);
    group.add(collapseAllAction);

    panel.add(
        ActionManager.getInstance()
            .createActionToolbar(ActionPlaces.UNKNOWN, group, true)
            .getComponent(),
        BorderLayout.NORTH);

    // Tree
    expandFirst();
    defaultExpandTree();
    installSpeedSearch();

    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree);
    scrollPane.setPreferredSize(new Dimension(350, 450));
    panel.add(scrollPane, BorderLayout.CENTER);

    return panel;
  }
  public void initComponent() {
    myModifiersValue = Registry.get("actionSystem.quickAccessModifiers");
    myModifiersValue.addListener(
        new RegistryValueListener.Adapter() {
          public void afterValueChanged(RegistryValue value) {
            applyModifiersFromRegistry();
          }
        },
        this);

    KeymapManager kmMgr = KeymapManager.getInstance();
    kmMgr.addKeymapManagerListener(this);

    activeKeymapChanged(kmMgr.getActiveKeymap());

    applyModifiersFromRegistry();
  }
Esempio n. 9
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);
 }
  private static void doWithAltClickShortcut(ThrowableRunnable runnable) throws Throwable {
    Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
    MouseShortcut shortcut = new MouseShortcut(1, InputEvent.ALT_DOWN_MASK, 1);
    try {
      keymap.addShortcut(IdeActions.ACTION_EDITOR_ADD_OR_REMOVE_CARET, shortcut);

      runnable.run();
    } finally {
      keymap.removeShortcut(IdeActions.ACTION_EDITOR_ADD_OR_REMOVE_CARET, shortcut);
    }
  }
  private void fillActionsList(
      Component component, MouseShortcut mouseShortcut, boolean isModalContext) {
    myActions.clear();

    // here we try to find "local" shortcuts
    if (component instanceof JComponent) {
      for (AnAction action : ActionUtil.getActions((JComponent) component)) {
        for (Shortcut shortcut : action.getShortcutSet().getShortcuts()) {
          if (mouseShortcut.equals(shortcut) && !myActions.contains(action)) {
            myActions.add(action);
          }
        }
      }
      // once we've found a proper local shortcut(s), we exit
      if (!myActions.isEmpty()) {
        return;
      }
    }

    // search in main keymap
    if (KeymapManagerImpl.ourKeymapManagerInitialized) {
      final KeymapManager keymapManager = KeymapManager.getInstance();
      if (keymapManager != null) {
        final Keymap keymap = keymapManager.getActiveKeymap();
        final String[] actionIds = keymap.getActionIds(mouseShortcut);

        ActionManager actionManager = ActionManager.getInstance();
        for (String actionId : actionIds) {
          AnAction action = actionManager.getAction(actionId);

          if (action == null) continue;

          if (isModalContext && !action.isEnabledInModalContext()) continue;

          if (!myActions.contains(action)) {
            myActions.add(action);
          }
        }
      }
    }
  }
    protected AbstractAddGroup(String text, Icon icon) {
      super(text, true);

      final Presentation presentation = getTemplatePresentation();
      presentation.setIcon(icon);

      final Keymap active = KeymapManager.getInstance().getActiveKeymap();
      if (active != null) {
        final Shortcut[] shortcuts = active.getShortcuts("NewElement");
        setShortcutSet(new CustomShortcutSet(shortcuts));
      }
    }
  private KeyStroke[] getKeyStrokesByActionId(String actionId) {
    List<KeyStroke> keyStrokes = new ArrayList<KeyStroke>();
    Shortcut[] shortcuts = KeymapManager.getInstance().getActiveKeymap().getShortcuts(actionId);
    for (Shortcut sc : shortcuts) {
      if (sc instanceof KeyboardShortcut) {
        KeyStroke ks = ((KeyboardShortcut) sc).getFirstKeyStroke();
        keyStrokes.add(ks);
      }
    }

    return keyStrokes.toArray(new KeyStroke[keyStrokes.size()]);
  }
Esempio n. 14
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 String getActionShortcutText(final String actionId) {
    final Shortcut[] shortcuts =
        KeymapManager.getInstance().getActiveKeymap().getShortcuts(actionId);
    String shortcutText = "";
    for (final Shortcut shortcut : shortcuts) {
      if (shortcut instanceof KeyboardShortcut) {
        shortcutText = KeymapUtil.getShortcutText(shortcut);
        break;
      }
    }

    return shortcutText;
  }
Esempio n. 16
0
 private static BrowseMode getBrowseMode(final int modifiers) {
   if (modifiers != 0) {
     final Keymap activeKeymap = KeymapManager.getInstance().getActiveKeymap();
     if (matchMouseShortcut(activeKeymap, modifiers, IdeActions.ACTION_GOTO_DECLARATION))
       return BrowseMode.Declaration;
     if (matchMouseShortcut(activeKeymap, modifiers, IdeActions.ACTION_GOTO_TYPE_DECLARATION))
       return BrowseMode.TypeDeclaration;
     if (matchMouseShortcut(activeKeymap, modifiers, IdeActions.ACTION_GOTO_IMPLEMENTATION))
       return BrowseMode.Implementation;
     if (modifiers == InputEvent.CTRL_MASK) return BrowseMode.Declaration;
   }
   return BrowseMode.None;
 }
Esempio n. 17
0
  public void testCustomShortcut() throws Exception {
    Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
    MouseShortcut shortcut = new MouseShortcut(1, InputEvent.ALT_DOWN_MASK, 1);
    try {
      keymap.addShortcut(IdeActions.ACTION_EDITOR_ADD_OR_REMOVE_CARET, shortcut);

      init("<caret>text", TestFileType.TEXT);
      mouse().alt().clickAt(0, 2);
      checkResultByText("<caret>te<caret>xt");
    } finally {
      keymap.removeShortcut(IdeActions.ACTION_EDITOR_ADD_OR_REMOVE_CARET, shortcut);
    }
  }
 private static void addShortcut(
     @NotNull final String shortcutString,
     @NotNull final String actionIdString,
     boolean isAdditional) {
   Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
   Shortcut[] shortcuts = keymap.getShortcuts(actionIdString);
   if (shortcuts.length > 0 && !isAdditional) {
     return;
   }
   Shortcut studyActionShortcut =
       new KeyboardShortcut(KeyStroke.getKeyStroke(shortcutString), null);
   String[] actionsIds = keymap.getActionIds(studyActionShortcut);
   for (String actionId : actionsIds) {
     myDeletedShortcuts.put(actionId, shortcutString);
     keymap.removeShortcut(actionId, studyActionShortcut);
   }
   keymap.addShortcut(actionIdString, studyActionShortcut);
 }
Esempio n. 19
0
  /** @return true if keymap was switched successfully, false otherwise */
  public static boolean switchKeymapBindings(final boolean enableVimKeymap) {
    LOG.debug("Enabling keymap");

    // In case if Vim keymap is already in use or we don't need it, we have nothing to do
    if (isVimKeymapUsed() == enableVimKeymap) {
      return false;
    }

    final KeymapManagerImpl manager = (KeymapManagerImpl) KeymapManager.getInstance();
    // Get keymap to enable
    final String keymapName2Enable =
        enableVimKeymap ? VIM_KEYMAP_NAME : VimPlugin.getInstance().getPreviousKeyMap();
    if (keymapName2Enable.isEmpty()) {
      return false;
    }
    if (keymapName2Enable.equals(manager.getActiveKeymap().getName())) {
      return false;
    }

    LOG.debug("Enabling keymap:" + keymapName2Enable);
    final Keymap keymap = manager.getKeymap(keymapName2Enable);
    if (keymap == null) {
      reportError("Failed to enable keymap: " + keymapName2Enable);
      return false;
    }

    // Save previous keymap to enable after VIM emulation is turned off
    if (enableVimKeymap) {
      VimPlugin.getInstance().setPreviousKeyMap(manager.getActiveKeymap().getName());
    }

    manager.setActiveKeymap(keymap);

    final String keyMapPresentableName = keymap.getPresentableName();
    Notifications.Bus.notify(
        new Notification(
            VimPlugin.IDEAVIM_NOTIFICATION_ID,
            VimPlugin.IDEAVIM_NOTIFICATION_TITLE,
            keyMapPresentableName + " keymap was successfully enabled",
            NotificationType.INFORMATION));
    LOG.debug(keyMapPresentableName + " keymap was successfully enabled");
    return true;
  }
 @Override
 public void projectClosed() {
   //noinspection AssignmentToStaticFieldFromInstanceMethod
   StudyCondition.VALUE = false;
   if (myCourse != null) {
     ToolWindowManager.getInstance(myProject)
         .getToolWindow(StudyToolWindowFactory.STUDY_TOOL_WINDOW)
         .getContentManager()
         .removeAllContents(false);
     if (!myDeletedShortcuts.isEmpty()) {
       for (Map.Entry<String, String> shortcut : myDeletedShortcuts.entrySet()) {
         final Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
         final Shortcut actionShortcut =
             new KeyboardShortcut(KeyStroke.getKeyStroke(shortcut.getValue()), null);
         keymap.addShortcut(shortcut.getKey(), actionShortcut);
       }
     }
   }
 }
  private void init() {
    setVisible(myPresentation.isVisible());
    setEnabled(myPresentation.isEnabled());
    setMnemonic(myEnableMnemonics ? myPresentation.getMnemonic() : 0);
    setText(myPresentation.getText());
    final int mnemonicIndex = myEnableMnemonics ? myPresentation.getDisplayedMnemonicIndex() : -1;

    if (getText() != null && mnemonicIndex >= 0 && mnemonicIndex < getText().length()) {
      setDisplayedMnemonicIndex(mnemonicIndex);
    }

    AnAction action = myAction.getAction();
    updateIcon(action);
    String id = ActionManager.getInstance().getId(action);
    if (id != null) {
      setAcceleratorFromShortcuts(KeymapManager.getInstance().getActiveKeymap().getShortcuts(id));
    } else {
      final ShortcutSet shortcutSet = action.getShortcutSet();
      if (shortcutSet != null) {
        setAcceleratorFromShortcuts(shortcutSet.getShortcuts());
      }
    }
  }
Esempio n. 22
0
 public static boolean isVimKeymapInstalled() {
   return KeymapManager.getInstance().getKeymap(VIM_KEYMAP_NAME) != null;
 }
 public void disposeComponent() {
   KeymapManager.getInstance().removeKeymapManagerListener(this);
   Disposer.dispose(this);
 }
 public void activeKeymapChanged(Keymap keymap) {
   KeymapManager mgr = KeymapManager.getInstance();
   myKeymap = mgr.getActiveKeymap();
 }
  protected ActionCallback _execute(final PlaybackContext context) {
    final String actionName = getText().substring(PREFIX.length()).trim();

    final ActionManager am = ActionManager.getInstance();
    final AnAction targetAction = am.getAction(actionName);
    if (targetAction == null) {
      dumpError(context, "Unknown action: " + actionName);
      return new ActionCallback.Rejected();
    }

    if (!context.isUseDirectActionCall()) {
      final Shortcut[] sc = KeymapManager.getInstance().getActiveKeymap().getShortcuts(actionName);
      KeyStroke stroke = null;
      for (Shortcut each : sc) {
        if (each instanceof KeyboardShortcut) {
          final KeyboardShortcut ks = (KeyboardShortcut) each;
          final KeyStroke first = ks.getFirstKeyStroke();
          final KeyStroke second = ks.getSecondKeyStroke();
          if (first != null && second == null) {
            stroke = KeyStroke.getKeyStroke(first.getKeyCode(), first.getModifiers(), false);
            break;
          }
        }
      }

      if (stroke != null) {
        final ActionCallback result =
            new TimedOutCallback(
                Registry.intValue("actionSystem.commandProcessingTimeout"),
                "Timed out calling action id=" + actionName,
                new Throwable(),
                true) {
              @Override
              protected void dumpError() {
                context.error(getMessage(), getLine());
              }
            };
        context.message("Invoking action via shortcut: " + stroke.toString(), getLine());

        final KeyStroke finalStroke = stroke;

        IdeFocusManager.getGlobalInstance()
            .doWhenFocusSettlesDown(
                new Runnable() {
                  @Override
                  public void run() {
                    final Ref<AnActionListener> listener = new Ref<AnActionListener>();
                    listener.set(
                        new AnActionListener.Adapter() {

                          @Override
                          public void beforeActionPerformed(
                              final AnAction action, DataContext dataContext, AnActionEvent event) {
                            SwingUtilities.invokeLater(
                                new Runnable() {
                                  @Override
                                  public void run() {
                                    if (context.isDisposed()) {
                                      am.removeAnActionListener(listener.get());
                                      return;
                                    }

                                    if (targetAction.equals(action)) {
                                      context.message(
                                          "Performed action: " + actionName,
                                          context.getCurrentLine());
                                      am.removeAnActionListener(listener.get());
                                      result.setDone();
                                    }
                                  }
                                });
                          }
                        });
                    am.addAnActionListener(listener.get());

                    context.runPooledThread(
                        new Runnable() {
                          @Override
                          public void run() {
                            type(context.getRobot(), finalStroke);
                          }
                        });
                  }
                });

        return result;
      }
    }

    final InputEvent input = getInputEvent(actionName);

    final ActionCallback result = new ActionCallback();

    context.getRobot().delay(Registry.intValue("actionSystem.playback.delay"));
    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            am.tryToExecute(targetAction, input, null, null, false)
                .doWhenProcessed(result.createSetDoneRunnable());
          }
        });

    return result;
  }
  public void show(DiffRequest request) {
    Collection hints = request.getHints();
    boolean shouldOpenDialog = shouldOpenDialog(hints);
    if (shouldOpenDialog) {
      final DialogBuilder builder = new DialogBuilder(request.getProject());
      DiffPanelImpl diffPanel =
          createDiffPanelIfShouldShow(request, builder.getWindow(), builder, true);
      if (diffPanel == null) {
        Disposer.dispose(builder);
        return;
      }
      if (hints.contains(DiffTool.HINT_DIFF_IS_APPROXIMATE)) {
        diffPanel.setPatchAppliedApproximately(); // todo read only and not variants
      }
      final Runnable onOkRunnable = request.getOnOkRunnable();
      if (onOkRunnable != null) {
        builder.setOkOperation(
            new Runnable() {
              @Override
              public void run() {
                builder.getDialogWrapper().close(0);
                onOkRunnable.run();
              }
            });
      } else {
        builder.removeAllActions();
      }
      builder.setCenterPanel(diffPanel.getComponent());
      builder.setPreferredFocusComponent(diffPanel.getPreferredFocusedComponent());
      builder.setTitle(request.getWindowTitle());
      builder.setDimensionServiceKey(request.getGroupKey());

      new AnAction() {
        public void actionPerformed(final AnActionEvent e) {
          builder.getDialogWrapper().close(0);
        }
      }.registerCustomShortcutSet(
          new CustomShortcutSet(
              KeymapManager.getInstance().getActiveKeymap().getShortcuts("CloseContent")),
          diffPanel.getComponent());
      showDiffDialog(builder, hints);
    } else {
      final FrameWrapper frameWrapper =
          new FrameWrapper(request.getProject(), request.getGroupKey());
      DiffPanelImpl diffPanel =
          createDiffPanelIfShouldShow(request, frameWrapper.getFrame(), frameWrapper, true);
      if (diffPanel == null) {
        Disposer.dispose(frameWrapper);
        return;
      }
      if (hints.contains(DiffTool.HINT_DIFF_IS_APPROXIMATE)) {
        diffPanel.setPatchAppliedApproximately();
      }
      frameWrapper.setTitle(request.getWindowTitle());
      DiffUtil.initDiffFrame(
          diffPanel.getProject(), frameWrapper, diffPanel, diffPanel.getComponent());

      new AnAction() {
        public void actionPerformed(final AnActionEvent e) {
          frameWrapper.getFrame().dispose();
        }
      }.registerCustomShortcutSet(
          new CustomShortcutSet(
              KeymapManager.getInstance().getActiveKeymap().getShortcuts("CloseContent")),
          diffPanel.getComponent());

      frameWrapper.show();
    }
  }
  /**
   * This method fills <code>myActions</code> list.
   *
   * @return true if there is a shortcut with second stroke found.
   */
  public KeyProcessorContext updateCurrentContext(
      Component component, Shortcut sc, boolean isModalContext) {
    myContext.setFoundComponent(null);
    myContext.getActions().clear();

    if (isControlEnterOnDialog(component, sc)) return myContext;

    boolean hasSecondStroke = false;

    // here we try to find "local" shortcuts

    for (; component != null; component = component.getParent()) {
      if (!(component instanceof JComponent)) {
        continue;
      }
      ArrayList listOfActions =
          (ArrayList) ((JComponent) component).getClientProperty(AnAction.ourClientProperty);
      if (listOfActions == null) {
        continue;
      }
      for (Object listOfAction : listOfActions) {
        if (!(listOfAction instanceof AnAction)) {
          continue;
        }
        AnAction action = (AnAction) listOfAction;
        hasSecondStroke |= addAction(action, sc);
      }
      // once we've found a proper local shortcut(s), we continue with non-local shortcuts
      if (!myContext.getActions().isEmpty()) {
        myContext.setFoundComponent((JComponent) component);
        break;
      }
    }

    // search in main keymap

    Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
    String[] actionIds = keymap.getActionIds(sc);

    ActionManager actionManager = ActionManager.getInstance();
    for (String actionId : actionIds) {
      AnAction action = actionManager.getAction(actionId);
      if (action != null) {
        if (isModalContext && !action.isEnabledInModalContext()) {
          continue;
        }
        hasSecondStroke |= addAction(action, sc);
      }
    }

    if (!hasSecondStroke && sc instanceof KeyboardShortcut) {
      // little trick to invoke action which second stroke is a key w/o modifiers, but user still
      // holds the modifier key(s) of the first stroke

      final KeyboardShortcut keyboardShortcut = (KeyboardShortcut) sc;
      final KeyStroke firstKeyStroke = keyboardShortcut.getFirstKeyStroke();
      final KeyStroke secondKeyStroke = keyboardShortcut.getSecondKeyStroke();

      if (secondKeyStroke != null
          && secondKeyStroke.getModifiers() != 0
          && firstKeyStroke.getModifiers() != 0) {
        final KeyboardShortcut altShortCut =
            new KeyboardShortcut(
                firstKeyStroke, KeyStroke.getKeyStroke(secondKeyStroke.getKeyCode(), 0));
        final String[] additionalActions = keymap.getActionIds(altShortCut);

        for (final String actionId : additionalActions) {
          AnAction action = actionManager.getAction(actionId);
          if (action != null) {
            if (isModalContext && !action.isEnabledInModalContext()) {
              continue;
            }
            hasSecondStroke |= addAction(action, altShortCut);
          }
        }
      }
    }

    myContext.setHasSecondStroke(hasSecondStroke);

    Comparator<? super AnAction> comparator =
        PlatformDataKeys.ACTIONS_SORTER.getData(myContext.getDataContext());
    if (comparator != null) {
      Collections.sort(myContext.getActions(), comparator);
    }

    return myContext;
  }
 public void registerShortcut(final JComponent component) {
   registerCustomShortcutSet(
       new CustomShortcutSet(
           KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_RERUN)),
       component);
 }
Esempio n. 29
0
 public static boolean isVimKeymapUsed() {
   return KeymapManager.getInstance().getActiveKeymap().getName().equals(VIM_KEYMAP_NAME);
 }
 public Shortcut[] getShortcut() {
   return KeymapManager.getInstance().getActiveKeymap().getShortcuts("FileStructurePopup");
 }