Java Code Examples for com.intellij.openapi.keymap.KeymapManager#getInstance()

The following examples show how to use com.intellij.openapi.keymap.KeymapManager#getInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DesktopEditorImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean isMouseActionEvent(@Nonnull MouseEvent e, String actionId) {
  KeymapManager keymapManager = KeymapManager.getInstance();
  if (keymapManager == null) return false;
  Keymap keymap = keymapManager.getActiveKeymap();
  MouseShortcut mouseShortcut = KeymapUtil.createMouseShortcut(e);
  String[] mappedActions = keymap.getActionIds(mouseShortcut);
  if (!ArrayUtil.contains(actionId, mappedActions)) return false;
  if (mappedActions.length < 2 || e.getID() == MouseEvent.MOUSE_DRAGGED /* 'normal' actions are not invoked on mouse drag */) return true;
  ActionManager actionManager = ActionManager.getInstance();
  for (String mappedActionId : mappedActions) {
    if (actionId.equals(mappedActionId)) continue;
    AnAction action = actionManager.getAction(mappedActionId);
    AnActionEvent actionEvent = AnActionEvent.createFromAnAction(action, e, ActionPlaces.MAIN_MENU, DataManager.getInstance().getDataContext(e.getComponent()));
    if (ActionUtil.lastUpdateAndCheckDumb(action, actionEvent, false)) return false;
  }
  return true;
}
 
Example 2
Source File: MacGestureSupportForEditor.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void fillActionsList(MouseShortcut mouseShortcut, boolean isModalContext) {
  myActions.clear();

  // 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);
        }
      }
    }
  }
}
 
Example 3
Source File: SetShortcutAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  Project project = e.getProject();
  JBPopup seDialog = project == null ? null : project.getUserData(SearchEverywhereManager.SEARCH_EVERYWHERE_POPUP);
  if (seDialog == null) {
    return;
  }

  KeymapManager km = KeymapManager.getInstance();
  Keymap activeKeymap = km != null ? km.getActiveKeymap() : null;
  if (activeKeymap == null) {
    return;
  }

  AnAction action = e.getData(SELECTED_ACTION);
  Component component = e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
  if (action == null || component == null) {
    return;
  }

  seDialog.cancel();
  String id = ActionManager.getInstance().getId(action);
  KeymapPanel.addKeyboardShortcut(id, ActionShortcutRestrictions.getInstance().getForActionId(id), activeKeymap, component);
}
 
Example 4
Source File: SetShortcutAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void update(@Nonnull AnActionEvent e) {
  Presentation presentation = e.getPresentation();

  Project project = e.getProject();
  JBPopup seDialog = project == null ? null : project.getUserData(SearchEverywhereManager.SEARCH_EVERYWHERE_POPUP);
  if (seDialog == null) {
    presentation.setEnabled(false);
    return;
  }

  KeymapManager km = KeymapManager.getInstance();
  Keymap activeKeymap = km != null ? km.getActiveKeymap() : null;
  if (activeKeymap == null) {
    presentation.setEnabled(false);
    return;
  }

  AnAction action = e.getData(SELECTED_ACTION);
  Component component = e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
  presentation.setEnabled(action != null && component != null);
}
 
Example 5
Source File: QuickChangeKeymapAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void fillActions(Project project, @Nonnull DefaultActionGroup group, @Nonnull DataContext dataContext) {
  KeymapManagerEx manager = (KeymapManagerEx) KeymapManager.getInstance();
  Keymap current = manager.getActiveKeymap();
  for (Keymap keymap : manager.getAllKeymaps()) {
    addKeymapAction(group, manager, current, keymap, false);
  }
}
 
Example 6
Source File: DaemonTooltipWithActionRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
private String getKeymap(String key) {
  KeymapManager keymapManager = KeymapManager.getInstance();
  if (keymapManager != null) {
    Keymap keymap = keymapManager.getActiveKeymap();

    return KeymapUtil.getShortcutsText(keymap.getShortcuts(key));
  }

  return "";
}
 
Example 7
Source File: ShadowAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
private static KeymapManager getKeymapManager() {
  if (ApplicationManager.getApplication().isDisposed()) return null;
  return KeymapManager.getInstance();
}
 
Example 8
Source File: FindPopupPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void updateControls() {
  FindModel myModel = myHelper.getModel();
  if (myCbRegularExpressions.isSelected()) {
    myCbWholeWordsOnly.makeUnselectable(false);
  }
  else {
    myCbWholeWordsOnly.makeSelectable();
  }
  if (myModel.isReplaceState()) {
    if (myCbRegularExpressions.isSelected() || myCbCaseSensitive.isSelected()) {
      myCbPreserveCase.makeUnselectable(false);
    }
    else {
      myCbPreserveCase.makeSelectable();
    }

    if (myCbPreserveCase.isSelected()) {
      myCbRegularExpressions.makeUnselectable(false);
      myCbCaseSensitive.makeUnselectable(false);
    }
    else {
      myCbRegularExpressions.makeSelectable();
      myCbCaseSensitive.makeSelectable();
    }
  }
  myReplaceAllButton.setVisible(myHelper.isReplaceState());
  myReplaceSelectedButton.setVisible(myHelper.isReplaceState());
  myNavigationHintLabel.setVisible(mySearchComponent.getText().contains("\n"));
  if (myNavigationHintLabel.isVisible()) {
    myNavigationHintLabel.setText("");
    KeymapManager keymapManager = KeymapManager.getInstance();
    Keymap activeKeymap = keymapManager != null ? keymapManager.getActiveKeymap() : null;
    if (activeKeymap != null) {
      String findNextText = KeymapUtil.getFirstKeyboardShortcutText("FindNext");
      String findPreviousText = KeymapUtil.getFirstKeyboardShortcutText("FindPrevious");
      if (!StringUtil.isEmpty(findNextText) && !StringUtil.isEmpty(findPreviousText)) {
        myNavigationHintLabel.setText("Use " + findNextText + " and " + findPreviousText + " to select usages");
      }
    }
  }
}