com.intellij.openapi.keymap.KeymapManager Java Examples

The following examples show how to use com.intellij.openapi.keymap.KeymapManager. 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: 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 #2
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 #3
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 #4
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 #5
Source File: ActionMenuItem.java    From consulo with Apache License 2.0 6 votes vote down vote up
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) {
    Shortcut[] shortcuts = KeymapManager.getInstance().getActiveKeymap().getShortcuts(id);
    setAcceleratorFromShortcuts(shortcuts);
  }
  else {
    final ShortcutSet shortcutSet = action.getShortcutSet();
    if (shortcutSet != null) {
      setAcceleratorFromShortcuts(shortcutSet.getShortcuts());
    }
  }
}
 
Example #6
Source File: ActionCommand.java    From consulo with Apache License 2.0 6 votes vote down vote up
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);
  }


}
 
Example #7
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 #8
Source File: QuickListPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void includeSelectedAction() {
  final ChooseActionsDialog dlg = new ChooseActionsDialog(myActionsList, KeymapManager.getInstance().getActiveKeymap(), myAllQuickLists);
  if (dlg.showAndGet()) {
    String[] ids = dlg.getTreeSelectedActionIds();
    for (String id : ids) {
      includeActionId(id);
    }
    DefaultListModel listModel = (DefaultListModel)myActionsList.getModel();
    int size = listModel.getSize();
    ListSelectionModel selectionModel = myActionsList.getSelectionModel();
    if (size > 0) {
      selectionModel.removeIndexInterval(0, size - 1);
    }
    for (String id1 : ids) {
      int idx = listModel.lastIndexOf(id1);
      if (idx >= 0) {
        selectionModel.addSelectionInterval(idx, idx);
      }
    }
  }
}
 
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: DesktopStripeButton.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void init() {
  setFocusable(false);
  setBackground(ourBackgroundColor);
  final Border border = JBUI.Borders.empty(5, 5, 0, 5);
  setBorder(border);
  updatePresentation();
  apply(myDecorator.getWindowInfo());
  addActionListener(this);
  addMouseListener(new MyPopupHandler());
  setRolloverEnabled(true);
  setOpaque(false);

  enableEvents(AWTEvent.MOUSE_EVENT_MASK);

  addMouseMotionListener(new MouseMotionAdapter() {
    @Override
    public void mouseDragged(final MouseEvent e) {
      processDrag(e);
    }
  });
  KeymapManager.getInstance().addKeymapManagerListener(myKeymapListener, this);
}
 
Example #11
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 #12
Source File: ShadowAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void rebound() {
  final KeymapManager mgr = getKeymapManager();
  if (mgr == null) return;

  myActionId = ActionManager.getInstance().getId(myCopyFromAction);
  if (myPresentation == null) {
    myAction.copyFrom(myCopyFromAction);
  } else {
    myAction.getTemplatePresentation().copyFrom(myPresentation);
    myAction.copyShortcutFrom(myCopyFromAction);
  }

  unregisterAll();

  myKeymap = mgr.getActiveKeymap();
  myKeymap.addShortcutChangeListener(myKeymapListener);

  if (myActionId == null) return;

  final Shortcut[] shortcuts = myKeymap.getShortcuts(myActionId);
  myShortcutSet = new CustomShortcutSet(shortcuts);
  myAction.registerCustomShortcutSet(myShortcutSet, myComponent);
}
 
Example #13
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 #14
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 #15
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 #16
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 #17
Source File: CommittedChangesTreeBrowser.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ActionToolbar createGroupFilterToolbar(final Project project,
                                              final ActionGroup leadGroup,
                                              @javax.annotation.Nullable final ActionGroup tailGroup,
                                              final List<AnAction> extra) {
  DefaultActionGroup toolbarGroup = new DefaultActionGroup();
  toolbarGroup.add(leadGroup);
  toolbarGroup.addSeparator();
  toolbarGroup.add(new SelectFilteringAction(project, this));
  toolbarGroup.add(new SelectGroupingAction(project, this));
  final ExpandAllAction expandAllAction = new ExpandAllAction(myChangesTree);
  final CollapseAllAction collapseAllAction = new CollapseAllAction(myChangesTree);
  expandAllAction.registerCustomShortcutSet(new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_EXPAND_ALL)),
                                            myChangesTree);
  collapseAllAction
          .registerCustomShortcutSet(new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_COLLAPSE_ALL)),
                                     myChangesTree);
  toolbarGroup.add(expandAllAction);
  toolbarGroup.add(collapseAllAction);
  toolbarGroup.add(ActionManager.getInstance().getAction(IdeActions.ACTION_COPY));
  toolbarGroup.add(new ContextHelpAction(myHelpId));
  if (tailGroup != null) {
    toolbarGroup.add(tailGroup);
  }
  for (AnAction anAction : extra) {
    toolbarGroup.add(anAction);
  }
  return ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, toolbarGroup, true);
}
 
Example #18
Source File: BaseStructureConfigurableNoDaemon.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 #19
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 #20
Source File: ContentTabLabel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public String getTooltip() {
  String text = KeymapUtil.getShortcutsText(KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_CLOSE_ACTIVE_TAB));

  return text.isEmpty() || !isSelected() ? ACTION_NAME : ACTION_NAME + " (" + text + ")";
}
 
Example #21
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 #22
Source File: ActionTracer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void afterActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) {
  StringBuffer out = new StringBuffer();
  final ActionManager actionManager = ActionManager.getInstance();
  final String id = actionManager.getId(action);
  out.append("id=" + id);
  if (id != null) {
    out.append(" shortcuts:");
    final Shortcut[] shortcuts = KeymapManager.getInstance().getActiveKeymap().getShortcuts(id);
    for (int i = 0; i < shortcuts.length; i++) {
      Shortcut shortcut = shortcuts[i];
      out.append(shortcut);
      if (i < shortcuts.length - 1) {
        out.append(",");
      }
    }
  }
  out.append("\n");
  final Document doc = myText.getDocument();
  try {
    doc.insertString(doc.getLength(), out.toString(), null);
    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        final int y = (int)myText.getBounds().getMaxY();
        myText.scrollRectToVisible(new Rectangle(0, y, myText.getBounds().width, 0));
      }
    });
  }
  catch (BadLocationException e) {
    LOG.error(e);
  }
}
 
Example #23
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 #24
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 #25
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 #26
Source File: MemberChooser.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #27
Source File: SearchEverywhereAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static String getShortcut() {
  String shortcutText;
  final Shortcut[] shortcuts = KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_SEARCH_EVERYWHERE);
  if (shortcuts.length == 0) {
    shortcutText = "Double " + (SystemInfo.isMac ? MacKeymapUtil.SHIFT : "Shift");
  }
  else {
    shortcutText = KeymapUtil.getShortcutsText(shortcuts);
  }
  return shortcutText;
}
 
Example #28
Source File: AbstractSlingServerNodeDescriptor.java    From aem-ide-tooling-4-intellij with Apache License 2.0 5 votes vote down vote up
public static boolean addShortcutText(String actionId, CompositeAppearance appearance) {
    Keymap activeKeymap = KeymapManager.getInstance().getActiveKeymap();
    Shortcut[] shortcuts = activeKeymap.getShortcuts(actionId);
    if (shortcuts != null && shortcuts.length > 0) {
        appearance.getEnding().addText(" (" + KeymapUtil.getShortcutText(shortcuts[0]) + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
        return true;
    } else return false;
}
 
Example #29
Source File: SarosComponent.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
public SarosComponent() {
  loadLoggers();

  Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
  keymap.addShortcut(
      "ActivateSarosToolWindow",
      new KeyboardShortcut(
          KeyStroke.getKeyStroke(KeyEvent.VK_F11, java.awt.event.InputEvent.ALT_DOWN_MASK),
          null));

  try {
    InputStream sarosProperties =
        SarosComponent.class.getClassLoader().getResourceAsStream("saros.properties");

    if (sarosProperties == null) {
      LogLog.warn(
          "could not initialize Saros properties because "
              + "the 'saros.properties' file could not be found on the "
              + "current JAVA class path");
    } else {
      System.getProperties().load(sarosProperties);
      sarosProperties.close();
    }
  } catch (Exception e) {
    LogLog.error("could not load saros property file 'saros.properties'", e);
  }

  IntellijApplicationLifecycle.getInstance().start();
}
 
Example #30
Source File: JumpToSourceAction.java    From MavenHelper with Apache License 2.0 5 votes vote down vote up
@NotNull
private static String getLabel() {
	Shortcut[] shortcuts = KeymapManager.getInstance().getActiveKeymap().getShortcuts("EditSource");
	if (shortcuts.length > 0) {
		Shortcut shortcut = shortcuts[0];
		if (shortcut.isKeyboard()) {
			KeyboardShortcut key = (KeyboardShortcut) shortcut;
			String s = KeyStrokeAdapter.toString(key.getFirstKeyStroke());
			if (s != null) {
				return "Jump To Source [" + s.toUpperCase() + "]";
			}
		}
	}
	return "Jump To Source";
}