Java Code Examples for com.intellij.openapi.keymap.KeymapUtil#getShortcutText()

The following examples show how to use com.intellij.openapi.keymap.KeymapUtil#getShortcutText() . 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: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 6 votes vote down vote up
@NotNull
private InplaceButton createSettingsButton(@NotNull final FindUsagesHandler handler,
    @NotNull final RelativePoint popupPosition, final Editor editor, final int maxUsages,
    @NotNull final Runnable cancelAction) {
  String shortcutText = "";
  KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut();
  if (shortcut != null) {
    shortcutText = "(" + KeymapUtil.getShortcutText(shortcut) + ")";
  }
  return new InplaceButton("Settings..." + shortcutText, AllIcons.General.Settings,
      new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
          SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
              showDialogAndFindUsages(handler, popupPosition, editor, maxUsages);
            }
          });
          cancelAction.run();
        }
      }
  );
}
 
Example 2
Source File: ShowUsagesAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private InplaceButton createSettingsButton(@Nonnull final FindUsagesHandler handler,
                                           @Nonnull final RelativePoint popupPosition,
                                           final Editor editor,
                                           final int maxUsages,
                                           @Nonnull final Runnable cancelAction) {
  String shortcutText = "";
  KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut();
  if (shortcut != null) {
    shortcutText = "(" + KeymapUtil.getShortcutText(shortcut) + ")";
  }
  return new InplaceButton("Settings..." + shortcutText, AllIcons.General.Settings, e -> {
    ApplicationManager.getApplication().invokeLater(() -> showDialogAndFindUsages(handler, popupPosition, editor, maxUsages));
    cancelAction.run();
  });
}
 
Example 3
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 6 votes vote down vote up
@NotNull
private InplaceButton createSettingsButton(@NotNull final FindUsagesHandler handler,
    @NotNull final RelativePoint popupPosition,
    final Editor editor,
    final int maxUsages,
    @NotNull final Runnable cancelAction) {
  String shortcutText = "";
  KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut();
  if (shortcut != null) {
    shortcutText = "(" + KeymapUtil.getShortcutText(shortcut) + ")";
  }
  return new InplaceButton("Settings..." + shortcutText, AllIcons.General.Settings, new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
          showDialogAndFindUsages(handler, popupPosition, editor, maxUsages);
        }
      });
      cancelAction.run();
    }
  });
}
 
Example 4
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
@Nullable
private static String getSecondInvocationTitle(@NotNull FindUsagesOptions options,
    @NotNull FindUsagesHandler handler) {
  if (getShowUsagesShortcut() != null) {
    GlobalSearchScope maximalScope = FindUsagesManager.getMaximalScope(handler);
    if (!notNullizeScope(options, handler.getProject()).equals(maximalScope)) {
      return "Press "
          + KeymapUtil.getShortcutText(getShowUsagesShortcut())
          + " again to search in "
          + maximalScope.getDisplayName();
    }
  }
  return null;
}
 
Example 5
Source File: SearchForUsagesRunnable.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static String createOptionsHtml(@NonNls UsageTarget[] searchFor) {
  KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut(searchFor);
  String shortcutText = "";
  if (shortcut != null) {
    shortcutText = " (" + KeymapUtil.getShortcutText(shortcut) + ")";
  }
  return "<a href='" + FIND_OPTIONS_HREF_TARGET + "'>Find Options...</a>" + shortcutText;
}
 
Example 6
Source File: TipUIUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static String getShortcutText(String actionId, Keymap keymap) {
  for (final Shortcut shortcut : keymap.getShortcuts(actionId)) {
    if (shortcut instanceof KeyboardShortcut) {
      return KeymapUtil.getShortcutText(shortcut);
    }
  }
  return null;
}
 
Example 7
Source File: HighlightUsagesHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static String getShortcutText() {
  final Shortcut[] shortcuts = ActionManager.getInstance()
          .getAction(IdeActions.ACTION_HIGHLIGHT_USAGES_IN_FILE)
          .getShortcutSet()
          .getShortcuts();
  if (shortcuts.length == 0) {
    return "<no key assigned>";
  }
  return KeymapUtil.getShortcutText(shortcuts[0]);
}
 
Example 8
Source File: ShowUsagesAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static String getSecondInvocationTitle(@Nonnull FindUsagesOptions options, @Nonnull FindUsagesHandler handler) {
  if (getShowUsagesShortcut() != null) {
    GlobalSearchScope maximalScope = FindUsagesManager.getMaximalScope(handler);
    if (!options.searchScope.equals(maximalScope)) {
      return "Press " + KeymapUtil.getShortcutText(getShowUsagesShortcut()) + " again to search in " + maximalScope.getDisplayName();
    }
  }
  return null;
}
 
Example 9
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 10
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 5 votes vote down vote up
@Nullable
private static String getSecondInvocationTitle(@NotNull FindUsagesOptions options, @NotNull FindUsagesHandler handler) {
  if (getShowUsagesShortcut() != null) {
    GlobalSearchScope maximalScope = FindUsagesManager.getMaximalScope(handler);
    if (!notNullizeScope(options, handler.getProject()).equals(maximalScope)) {
      return "Press " + KeymapUtil.getShortcutText(getShowUsagesShortcut()) + " again to search in " + maximalScope.getDisplayName();
    }
  }
  return null;
}
 
Example 11
Source File: FileStructurePopup.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void addCheckbox(JPanel panel, TreeAction action) {
  String text = action instanceof FileStructureFilter
                ? ((FileStructureFilter)action).getCheckBoxText()
                : action instanceof FileStructureNodeProvider ? ((FileStructureNodeProvider)action).getCheckBoxText() : null;

  if (text == null) return;

  Shortcut[] shortcuts = extractShortcutFor(action);


  JBCheckBox checkBox = new JBCheckBox();
  checkBox.setOpaque(false);
  UIUtil.applyStyle(UIUtil.ComponentStyle.SMALL, checkBox);

  boolean selected = getDefaultValue(action);
  checkBox.setSelected(selected);
  boolean isRevertedStructureFilter = action instanceof FileStructureFilter && ((FileStructureFilter)action).isReverted();
  myTreeActionsOwner.setActionIncluded(action, isRevertedStructureFilter != selected);
  checkBox.addActionListener(__ -> {
    boolean state = checkBox.isSelected();
    if (!myAutoClicked.contains(checkBox)) {
      saveState(action, state);
    }
    myTreeActionsOwner.setActionIncluded(action, isRevertedStructureFilter != state);
    rebuild(false).onProcessed(ignore -> {
      if (mySpeedSearch.isPopupActive()) {
        mySpeedSearch.refreshSelection();
      }
    });
  });
  checkBox.setFocusable(false);

  if (shortcuts.length > 0) {
    text += " (" + KeymapUtil.getShortcutText(shortcuts[0]) + ")";
    DumbAwareAction.create(e -> checkBox.doClick()).registerCustomShortcutSet(new CustomShortcutSet(shortcuts), myTree);
  }
  checkBox.setText(StringUtil.capitalize(StringUtil.trimStart(text.trim(), "Show ")));
  panel.add(checkBox);

  myCheckBoxes.put(action.getClass(), checkBox);
}