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

The following examples show how to use com.intellij.openapi.keymap.KeymapUtil#getKeystrokeText() . 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: AbstractGotoSEContributor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void update(@Nonnull AnActionEvent e) {
  ScopeDescriptor selection = getSelectedScope();
  String name = StringUtil.trimMiddle(selection.getDisplayName(), 30);
  String text = StringUtil.escapeMnemonics(name).replaceFirst("(?i)([" + TOGGLE + CHOOSE + "])", "_$1");
  e.getPresentation().setText(text);
  e.getPresentation().setIcon(OffsetIcon.getOriginalIcon(selection.getIcon()));
  String shortcutText = KeymapUtil.getKeystrokeText(KeyStroke.getKeyStroke(CHOOSE, MnemonicHelper.getFocusAcceleratorKeyMask(), true));
  String shortcutText2 = KeymapUtil.getKeystrokeText(KeyStroke.getKeyStroke(TOGGLE, MnemonicHelper.getFocusAcceleratorKeyMask(), true));
  e.getPresentation().setDescription("Choose scope (" + shortcutText + ")\n" + "Toggle scope (" + shortcutText2 + ")");
  JComponent button = e.getPresentation().getClientProperty(CustomComponentAction.COMPONENT_KEY);
  if (button != null) {
    button.setBackground(selection.getColor());
  }
}
 
Example 2
Source File: ChooseByNamePopup.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected ChooseByNamePopup(@Nullable final Project project,
                            @Nonnull ChooseByNameModel model,
                            @Nonnull ChooseByNameItemProvider provider,
                            @Nullable ChooseByNamePopup oldPopup,
                            @Nullable final String predefinedText,
                            boolean mayRequestOpenInCurrentWindow,
                            int initialIndex) {
  super(project, model, provider, oldPopup != null ? oldPopup.getEnteredText() : predefinedText, initialIndex);
  myOldPopup = oldPopup;
  if (oldPopup != null) { //inherit old focus owner
    myOldFocusOwner = oldPopup.myPreviouslyFocusedComponent;
  }
  myMayRequestCurrentWindow = mayRequestOpenInCurrentWindow;
  myAdText = myMayRequestCurrentWindow ? "Press " + KeymapUtil.getKeystrokeText(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_MASK)) + " to open in current window" : null;
}
 
Example 3
Source File: ExtendableTextField.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Temporary solution to support icons in the text component for different L&F.
 * This method replaces non-supported UI with Darcula UI.
 *
 * @param ui an object to paint this text component
 */
//@Override
//@Deprecated
//public void setUI(TextUI ui) {
//  TextUI suggested = ui;
//  try {
//    if (ui == null || !Class.forName("com.intellij.ide.ui.laf.darcula.ui.TextFieldWithPopupHandlerUI_New").isAssignableFrom(ui.getClass())) {
//      ui = (TextUI)Class.forName("com.intellij.ide.ui.laf.darcula.ui.DarculaTextFieldUI_New").getDeclaredMethod("createUI", JComponent.class).invoke(null, this);
//    }
//  }
//  catch (Exception ignore) {
//  }
//
//  super.setUI(ui);
//  if (ui != suggested) {
//    try {
//      setBorder((Border)Class.forName("com.intellij.ide.ui.laf.darcula.ui.DarculaTextBorder_New").newInstance());
//    }
//    catch (Exception ignore) {
//    }
//  }
//}

public ExtendableTextField addBrowseExtension(@Nonnull Runnable action, @Nullable Disposable parentDisposable) {
  KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_DOWN_MASK);
  String tooltip = UIBundle.message("component.with.browse.button.browse.button.tooltip.text") + " (" + KeymapUtil.getKeystrokeText(keyStroke) + ")";

  ExtendableTextComponent.Extension browseExtension = ExtendableTextComponent.Extension.create(AllIcons.Nodes.TreeOpen, AllIcons.Nodes.TreeOpen, tooltip, action);

  new DumbAwareAction() {
    @Override
    public void actionPerformed(@Nonnull AnActionEvent e) {
      action.run();
    }
  }.registerCustomShortcutSet(new CustomShortcutSet(keyStroke), this, parentDisposable);
  addExtension(browseExtension);

  return this;
}
 
Example 4
Source File: KeyboardModifierGestureShortcut.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
  String s = getType() == KeyboardGestureAction.ModifierType.dblClick ? "Press, release and hold " : "Hold ";
  s += KeymapUtil.getKeystrokeText(this.getStroke());
  return s;
}
 
Example 5
Source File: KeyboardShortcutDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
static String getTextByKeyStroke(KeyStroke keyStroke) {
  if(keyStroke == null) {
    return "";
  }
  return KeymapUtil.getKeystrokeText(keyStroke);
}