com.intellij.openapi.keymap.Keymap Java Examples

The following examples show how to use com.intellij.openapi.keymap.Keymap. 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: SystemShortcuts.java    From consulo with Apache License 2.0 6 votes vote down vote up
public
@Nullable
Map<KeyboardShortcut, String> calculateConflicts(@Nonnull Keymap keymap, @Nonnull String actionId) {
  if (myKeyStroke2SysShortcut.isEmpty()) return null;

  Map<KeyboardShortcut, String> result = null;
  final Shortcut[] actionShortcuts = computeOnEdt(() -> keymap.getShortcuts(actionId));
  for (Shortcut sc : actionShortcuts) {
    if (!(sc instanceof KeyboardShortcut)) {
      continue;
    }
    final KeyboardShortcut ksc = (KeyboardShortcut)sc;
    for (@Nonnull KeyStroke sks : myKeyStroke2SysShortcut.keySet()) {
      if (ksc.getFirstKeyStroke().equals(sks) || sks.equals(ksc.getSecondKeyStroke())) {
        if (result == null) result = new HashMap<>();
        result.put(ksc, getDescription(myKeyStroke2SysShortcut.get(sks)));
      }
    }
  }
  return result;
}
 
Example #2
Source File: ActionsTree.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void reset(final Keymap keymap, final QuickList[] allQuickLists, String filter, @Nullable KeyboardShortcut shortcut) {
  myKeymap = keymap;

  final PathsKeeper pathsKeeper = new PathsKeeper();
  pathsKeeper.storePaths();

  myRoot.removeAllChildren();

  ActionManager actionManager = ActionManager.getInstance();
  Project project = DataManager.getInstance().getDataContext(myComponent).getData(CommonDataKeys.PROJECT);
  Group mainGroup = ActionsTreeUtil.createMainGroup(project, myKeymap, allQuickLists, filter, true, filter != null && filter.length() > 0 ?
                                                                                                    ActionsTreeUtil.isActionFiltered(filter, true) :
                                                                                                    (shortcut != null ? ActionsTreeUtil.isActionFiltered(actionManager, myKeymap, shortcut) : null));
  if ((filter != null && filter.length() > 0 || shortcut != null) && mainGroup.initIds().isEmpty()){
    mainGroup = ActionsTreeUtil.createMainGroup(project, myKeymap, allQuickLists, filter, false, filter != null && filter.length() > 0 ?
                                                                                                 ActionsTreeUtil.isActionFiltered(filter, false) :
                                                                                                 ActionsTreeUtil.isActionFiltered(actionManager, myKeymap, shortcut));
  }
  myRoot = ActionsTreeUtil.createNode(mainGroup);
  myMainGroup = mainGroup;
  MyModel model = (MyModel)myTree.getModel();
  model.setRoot(myRoot);
  model.nodeStructureChanged(myRoot);

  pathsKeeper.restorePaths();
}
 
Example #3
Source File: ActivateToolWindowAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * @return mnemonic for action if it has Alt+digit/Meta+digit shortcut.
 * Otherwise the method returns <code>-1</code>. Meta mask is OK for
 * Mac OS X user, because Alt+digit types strange characters into the
 * editor.
 */
public static int getMnemonicForToolWindow(String id) {
  Keymap activeKeymap = KeymapManager.getInstance().getActiveKeymap();
  Shortcut[] shortcuts = activeKeymap.getShortcuts(getActionIdForToolWindow(id));
  for (Shortcut shortcut : shortcuts) {
    if (shortcut instanceof KeyboardShortcut) {
      KeyStroke keyStroke = ((KeyboardShortcut)shortcut).getFirstKeyStroke();
      int modifiers = keyStroke.getModifiers();
      if (modifiers == (InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK) ||
          modifiers == InputEvent.ALT_MASK ||
          modifiers == InputEvent.ALT_DOWN_MASK ||
          modifiers == (InputEvent.META_DOWN_MASK | InputEvent.META_MASK) ||
          modifiers == InputEvent.META_MASK ||
          modifiers == InputEvent.META_DOWN_MASK) {
        int keyCode = keyStroke.getKeyCode();
        if (KeyEvent.VK_0 <= keyCode && keyCode <= KeyEvent.VK_9) {
          char c = (char)('0' + keyCode - KeyEvent.VK_0);
          return (int)c;
        }
      }
    }
  }
  return -1;
}
 
Example #4
Source File: ChooseActionsDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
public ChooseActionsDialog(Component parent, Keymap keymap, QuickList[] quicklists) {
  super(parent, true);
  myKeymap = keymap;
  myQuicklists = quicklists;

  myActionsTree = new ActionsTree();
  myActionsTree.reset(keymap, quicklists);
  myActionsTree.getTree().getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);

  new DoubleClickListener() {
    @Override
    protected boolean onDoubleClick(MouseEvent e) {
      doOKAction();
      return true;
    }
  }.installOn(myActionsTree.getTree());


  myTreeExpansionMonitor = TreeExpansionMonitor.install(myActionsTree.getTree());

  setTitle("Add Actions to Quick List");
  init();
}
 
Example #5
Source File: ActionsTreeUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static Condition<AnAction> isActionFiltered(final ActionManager actionManager,
                                                   final Keymap keymap,
                                                   final KeyboardShortcut keyboardShortcut) {
  return new Condition<AnAction>() {
    public boolean value(final AnAction action) {
      if (keyboardShortcut == null) return true;
      if (action == null) return false;
      final Shortcut[] actionShortcuts =
        keymap.getShortcuts(action instanceof ActionStub ? ((ActionStub)action).getId() : actionManager.getId(action));
      for (Shortcut shortcut : actionShortcuts) {
        if (shortcut instanceof KeyboardShortcut) {
          final KeyboardShortcut keyboardActionShortcut = (KeyboardShortcut)shortcut;
          if (Comparing.equal(keyboardActionShortcut, keyboardShortcut)) {
            return true;
          }
        }
      }
      return false;
    }
  };
}
 
Example #6
Source File: ActionsTreeUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private static Condition<AnAction> wrapFilter(@Nullable final Condition<AnAction> filter, final Keymap keymap, final ActionManager actionManager) {
  if (Registry.is("keymap.show.alias.actions")) return filter;

  return new Condition<AnAction>() {
    @Override
    public boolean value(final AnAction action) {
      if (action == null) return false;
      final String id = action instanceof ActionStub ? ((ActionStub)action).getId() : actionManager.getId(action);
      if (id != null) {
        boolean actionBound = isActionBound(keymap, id);
        return filter == null ? !actionBound : !actionBound && filter.value(action);
      }

      return filter == null ? true : filter.value(action);
    }
  };
}
 
Example #7
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 #8
Source File: SystemShortcuts.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void onUserPressedShortcut(@Nonnull Keymap keymap, @Nonnull String[] actionIds, @Nonnull KeyboardShortcut ksc) {
  if (actionIds.length == 0) return;

  KeyStroke ks = ksc.getFirstKeyStroke();
  AWTKeyStroke sysKs = myKeyStroke2SysShortcut.get(ks);
  if (sysKs == null && ksc.getSecondKeyStroke() != null) sysKs = myKeyStroke2SysShortcut.get(ks = ksc.getSecondKeyStroke());
  if (sysKs == null) return;

  String unmutedActId = null;
  for (String actId : actionIds) {
    if (myNotifiedActions.contains(actId)) {
      continue;
    }
    if (!myMutedConflicts.isMutedAction(actId)) {
      unmutedActId = actId;
      break;
    }
  }
  if (unmutedActId == null) return;

  final @Nullable String macOsShortcutAction = getDescription(sysKs);
  //System.out.println(actionId + " shortcut '" + sysKS + "' "
  //                   + Arrays.toString(actionShortcuts) + " conflicts with macOS shortcut"
  //                   + (macOsShortcutAction == null ? "." : " '" + macOsShortcutAction + "'."));
  doNotify(keymap, unmutedActId, ks, macOsShortcutAction, ksc);
}
 
Example #9
Source File: FileEditorManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean isOpenInNewWindow() {
  if (!Platform.current().isDesktop()) {
    return false;
  }
  AWTEvent event = IdeEventQueue.getInstance().getTrueCurrentEvent();

  // Shift was used while clicking
  if (event instanceof MouseEvent &&
      ((MouseEvent)event).isShiftDown() &&
      (event.getID() == MouseEvent.MOUSE_CLICKED || event.getID() == MouseEvent.MOUSE_PRESSED || event.getID() == MouseEvent.MOUSE_RELEASED)) {
    return true;
  }

  if (event instanceof KeyEvent) {
    KeyEvent ke = (KeyEvent)event;
    Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
    String[] ids = keymap.getActionIds(KeyStroke.getKeyStroke(ke.getKeyCode(), ke.getModifiers()));
    return Arrays.asList(ids).contains("OpenElementInNewWindow");
  }

  return false;
}
 
Example #10
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 #11
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 #12
Source File: ActionSearchEverywhereContributor.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void showAssignShortcutDialog(@Nonnull GotoActionModel.MatchedValue value) {
  AnAction action = getAction(value);
  if (action == null) return;

  String id = ActionManager.getInstance().getId(action);

  Keymap activeKeymap = Optional.ofNullable(KeymapManager.getInstance()).map(KeymapManager::getActiveKeymap).orElse(null);
  if (activeKeymap == null) return;

  ApplicationManager.getApplication().invokeLater(() -> {
    Window window = myProject != null ? TargetAWT.to(WindowManager.getInstance().suggestParentWindow(myProject)) : KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
    if (window == null) return;

    KeymapPanel.addKeyboardShortcut(id, ActionShortcutRestrictions.getInstance().getForActionId(id), activeKeymap, window);
  });
}
 
Example #13
Source File: KeymapManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void removeAllKeymapsExceptUnmodifiable() {
  List<Keymap> schemes = mySchemesManager.getAllSchemes();
  for (int i = schemes.size() - 1; i >= 0; i--) {
    Keymap keymap = schemes.get(i);
    if (keymap.canModify()) {
      mySchemesManager.removeScheme(keymap);
    }
  }

  mySchemesManager.setCurrentSchemeName(null);

  Collection<Keymap> keymaps = mySchemesManager.getAllSchemes();
  if (!keymaps.isEmpty()) {
    mySchemesManager.setCurrentSchemeName(keymaps.iterator().next().getName());
  }
}
 
Example #14
Source File: DesktopToolWindowManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static Set<Integer> getActivateToolWindowVKs() {
  if (ApplicationManager.getApplication() == null) return new HashSet<>();

  Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
  Shortcut[] baseShortcut = keymap.getShortcuts("ActivateProjectToolWindow");
  int baseModifiers = 0;
  for (Shortcut each : baseShortcut) {
    if (each instanceof KeyboardShortcut) {
      KeyStroke keyStroke = ((KeyboardShortcut)each).getFirstKeyStroke();
      baseModifiers = keyStroke.getModifiers();
      if (baseModifiers > 0) {
        break;
      }
    }
  }
  return getModifiersVKs(baseModifiers);
}
 
Example #15
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 #16
Source File: BaseStructureConfigurable.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected AbstractAddGroup(String text, Image 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));
  }
}
 
Example #17
Source File: CtrlMouseHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static BrowseMode getBrowseMode(@JdkConstants.InputEventMask int modifiers) {
  if (modifiers != 0) {
    final Keymap activeKeymap = KeymapManager.getInstance().getActiveKeymap();
    if (KeymapUtil.matchActionMouseShortcutsModifiers(activeKeymap, modifiers, IdeActions.ACTION_GOTO_DECLARATION)) return BrowseMode.Declaration;
    if (KeymapUtil.matchActionMouseShortcutsModifiers(activeKeymap, modifiers, IdeActions.ACTION_GOTO_TYPE_DECLARATION)) return BrowseMode.TypeDeclaration;
    if (KeymapUtil.matchActionMouseShortcutsModifiers(activeKeymap, modifiers, IdeActions.ACTION_GOTO_IMPLEMENTATION)) return BrowseMode.Implementation;
  }
  return BrowseMode.None;
}
 
Example #18
Source File: FileTextFieldImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #19
Source File: InplaceRefactoring.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void showDialogAdvertisement(final String actionId) {
  final Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
  final Shortcut[] shortcuts = keymap.getShortcuts(actionId);
  if (shortcuts.length > 0) {
    setAdvertisementText("Press " + KeymapUtil.getShortcutText(shortcuts[0]) + " to show dialog with more options");
  }
}
 
Example #20
Source File: GotoTestOrCodeHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
protected String getAdText(PsiElement source, int length) {
  if (length > 0 && !TestFinderHelper.isTest(source)) {
    final Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
    final Shortcut[] shortcuts = keymap.getShortcuts(DefaultRunExecutor.getRunExecutorInstance().getContextActionId());
    if (shortcuts.length > 0) {
      return ("Press " + KeymapUtil.getShortcutText(shortcuts[0]) + " to run selected tests");
    }
  }
  return null;
}
 
Example #21
Source File: TipUIUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void updateShortcuts(StringBuilder 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();
  }
}
 
Example #22
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 #23
Source File: QuickChangeKeymapAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void addKeymapAction(final DefaultActionGroup group, final KeymapManagerEx manager, final Keymap current, final Keymap keymap, final boolean addScheme) {
  group.add(new AnAction(keymap.getPresentableName(), "", keymap == current ? ourCurrentAction : ourNotCurrentAction) {
    @Override
    public void actionPerformed(AnActionEvent e) {
      if (addScheme) {
        manager.getSchemesManager().addNewScheme(keymap, false);
      }
      manager.setActiveKeymap(keymap);
    }
  });
}
 
Example #24
Source File: ActionManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void processRemoveAndReplace(@Nonnull SimpleXmlElement element, String actionId, @Nonnull Keymap keymap, @Nonnull Shortcut shortcut) {
  boolean remove = Boolean.parseBoolean(element.getAttributeValue(REMOVE_SHORTCUT_ATTR_NAME));
  boolean replace = Boolean.parseBoolean(element.getAttributeValue(REPLACE_SHORTCUT_ATTR_NAME));
  if (remove) {
    keymap.removeShortcut(actionId, shortcut);
  }
  if (replace) {
    keymap.removeAllActionShortcuts(actionId);
  }
  if (!remove) {
    keymap.addShortcut(actionId, shortcut);
  }
}
 
Example #25
Source File: ActionManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void processKeyboardShortcutNode(SimpleXmlElement element, String actionId, PluginId pluginId, @Nonnull KeymapManagerEx keymapManager) {
  String firstStrokeString = element.getAttributeValue(FIRST_KEYSTROKE_ATTR_NAME);
  if (firstStrokeString == null) {
    reportActionError(pluginId, "\"first-keystroke\" attribute must be specified for action with id=" + actionId);
    return;
  }
  KeyStroke firstKeyStroke = getKeyStroke(firstStrokeString);
  if (firstKeyStroke == null) {
    reportActionError(pluginId, "\"first-keystroke\" attribute has invalid value for action with id=" + actionId);
    return;
  }

  KeyStroke secondKeyStroke = null;
  String secondStrokeString = element.getAttributeValue(SECOND_KEYSTROKE_ATTR_NAME);
  if (secondStrokeString != null) {
    secondKeyStroke = getKeyStroke(secondStrokeString);
    if (secondKeyStroke == null) {
      reportActionError(pluginId, "\"second-keystroke\" attribute has invalid value for action with id=" + actionId);
      return;
    }
  }

  String keymapName = element.getAttributeValue(KEYMAP_ATTR_NAME);
  if (keymapName == null || keymapName.trim().isEmpty()) {
    reportActionError(pluginId, "attribute \"keymap\" should be defined");
    return;
  }
  Keymap keymap = keymapManager.getKeymap(keymapName);
  if (keymap == null) {
    reportKeymapNotFoundWarning(pluginId, keymapName);
    return;
  }
  final KeyboardShortcut shortcut = new KeyboardShortcut(firstKeyStroke, secondKeyStroke);
  processRemoveAndReplace(element, actionId, keymap, shortcut);
}
 
Example #26
Source File: ActionManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void processMouseShortcutNode(SimpleXmlElement element, String actionId, PluginId pluginId, @Nonnull KeymapManager keymapManager) {
  String keystrokeString = element.getAttributeValue(KEYSTROKE_ATTR_NAME);
  if (keystrokeString == null || keystrokeString.trim().isEmpty()) {
    reportActionError(pluginId, "\"keystroke\" attribute must be specified for action with id=" + actionId);
    return;
  }
  MouseShortcut shortcut;
  try {
    shortcut = KeymapUtil.parseMouseShortcut(keystrokeString);
  }
  catch (Exception ex) {
    reportActionError(pluginId, "\"keystroke\" attribute has invalid value for action with id=" + actionId);
    return;
  }

  String keymapName = element.getAttributeValue(KEYMAP_ATTR_NAME);
  if (keymapName == null || keymapName.isEmpty()) {
    reportActionError(pluginId, "attribute \"keymap\" should be defined");
    return;
  }
  Keymap keymap = keymapManager.getKeymap(keymapName);
  if (keymap == null) {
    reportKeymapNotFoundWarning(pluginId, keymapName);
    return;
  }
  processRemoveAndReplace(element, actionId, keymap, shortcut);
}
 
Example #27
Source File: DiffSideView.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean isEventHandled(MouseEvent e) {
  Keymap activeKeymap = KeymapManager.getInstance().getActiveKeymap();
  Shortcut[] shortcuts = activeKeymap.getShortcuts(IdeActions.ACTION_GOTO_DECLARATION);
  for (Shortcut shortcut : shortcuts) {
    if (shortcut instanceof MouseShortcut) {
      return ((MouseShortcut)shortcut).getButton() == e.getButton() && ((MouseShortcut)shortcut).getModifiers() == e.getModifiersEx();
    }
  }
  return false;
}
 
Example #28
Source File: DefaultKeymap.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void loadKeymapsFromElement(final Element element) throws InvalidDataException {
  final List<Element> children = element.getChildren();
  for (Element child : children) {
    if (KEY_MAP.equals(child.getName())) {
      String keymapName = child.getAttributeValue(NAME_ATTRIBUTE);
      DefaultKeymapImpl keymap = keymapName.startsWith(KeymapManager.MAC_OS_X_KEYMAP) ? new MacOSDefaultKeymap() : new DefaultKeymapImpl();
      keymap.readExternal(child, myKeymaps.toArray(new Keymap[myKeymaps.size()]));
      keymap.setName(keymapName);
      myKeymaps.add(keymap);
    }
  }
}
 
Example #29
Source File: DefaultKeymapImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void readExternal(Element keymapElement, Keymap[] existingKeymaps) throws InvalidDataException {
  super.readExternal(keymapElement, existingKeymaps);

  if (KeymapManager.DEFAULT_IDEA_KEYMAP.equals(getName()) && !SystemInfo.isXWindow) {
    addShortcut(IdeActions.ACTION_GOTO_DECLARATION, new MouseShortcut(MouseEvent.BUTTON2, 0, 1));
  }
}
 
Example #30
Source File: SystemShortcuts.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void updateKeymapConflicts(@Nullable Keymap keymap) {
  myKeymap = keymap;
  myKeymapConflicts.clear();

  if (myKeyStroke2SysShortcut.isEmpty()) return;

  for (@Nonnull KeyStroke sysKS : myKeyStroke2SysShortcut.keySet()) {
    final String[] actIds = computeOnEdt(() -> keymap.getActionIds(sysKS));
    if (actIds == null || actIds.length == 0) continue;

    @Nonnull AWTKeyStroke shk = myKeyStroke2SysShortcut.get(sysKS);
    myKeymapConflicts.put(shk, new ConflictItem(sysKS, getDescription(shk), actIds));
  }
}