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

The following examples show how to use com.intellij.openapi.keymap.KeymapUtil#getFirstKeyboardShortcutText() . 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: ParameterInfoComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void setShortcutLabel() {
  if (myShortcutLabel != null) remove(myShortcutLabel);

  String upShortcut = KeymapUtil.getFirstKeyboardShortcutText(IdeActions.ACTION_METHOD_OVERLOAD_SWITCH_UP);
  String downShortcut = KeymapUtil.getFirstKeyboardShortcutText(IdeActions.ACTION_METHOD_OVERLOAD_SWITCH_DOWN);
  if (!myAllowSwitchLabel || myObjects.length <= 1 || !myHandler.supportsOverloadSwitching() || upShortcut.isEmpty() && downShortcut.isEmpty()) {
    myShortcutLabel = null;
  }
  else {
    myShortcutLabel = new JLabel(upShortcut.isEmpty() || downShortcut.isEmpty()
                                 ? CodeInsightBundle.message("parameter.info.switch.overload.shortcuts.single", upShortcut.isEmpty() ? downShortcut : upShortcut)
                                 : CodeInsightBundle.message("parameter.info.switch.overload.shortcuts", upShortcut, downShortcut));
    myShortcutLabel.setForeground(CONTEXT_HELP_FOREGROUND);
    Font labelFont = UIUtil.getLabelFont();
    myShortcutLabel.setFont(labelFont.deriveFont(labelFont.getSize2D() - (SystemInfo.isWindows ? 1 : 2)));
    myShortcutLabel.setBorder(JBUI.Borders.empty(6, 10, 0, 10));
    add(myShortcutLabel, BorderLayout.SOUTH);
  }
}
 
Example 2
Source File: TextFieldWithPopupHandlerUI.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public String getTooltip() {
  String prefix = null;
  if (UIUtil.getClientProperty(getComponent(), INPLACE_HISTORY) != null) prefix = "Recent Search";
  if (getActionOnClick() != null) prefix = "Search History";
  return (prefix == null) ? null : prefix + " (" + KeymapUtil.getFirstKeyboardShortcutText("ShowSearchHistory") + ")";
}
 
Example 3
Source File: FileTextFieldImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public String getAdText(CompletionResult result) {
  if (result.myCompletionBase == null) return null;
  if (result.myCompletionBase.length() == result.myFieldText.length()) return null;

  String strokeText = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction("EditorChooseLookupItemReplace"));
  return IdeBundle.message("file.chooser.completion.ad.text", strokeText);
}
 
Example 4
Source File: BreakpointEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void createUIComponents() {
  AnAction action = ActionManager.getInstance().getAction(XDebuggerActions.VIEW_BREAKPOINTS);
  String shortcutText = action != null ? KeymapUtil.getFirstKeyboardShortcutText(action) : null;
  String text = shortcutText != null ? "More (" + shortcutText + ")" : "More";
  myShowMoreOptionsLink = new LinkLabel(text, null, new LinkListener() {
    @Override
    public void linkSelected(LinkLabel aSource, Object aLinkData) {
      if (myDelegate != null) {
        myDelegate.more();
      }
    }
  });
}
 
Example 5
Source File: PositionPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public String getTooltipText() {
  final String shortcut = KeymapUtil.getFirstKeyboardShortcutText("GotoLine");
  if (!shortcut.isEmpty()) {
    return UIBundle.message("go.to.line.command.name") + " (" + shortcut + ")";
  }
  return UIBundle.message("go.to.line.command.name");
}
 
Example 6
Source File: ShowAutoImportPass.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static String getMessage(final boolean multiple, @Nonnull String name) {
  final String messageKey = multiple ? "import.popup.multiple" : "import.popup.text";
  String hintText = DaemonBundle.message(messageKey, name);
  hintText += " " + KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_SHOW_INTENTION_ACTIONS));
  return hintText;
}
 
Example 7
Source File: IntentionHintComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void onMouseEnter(final boolean small) {
  myIconLabel.setIcon(myHighlightedIcon);
  myPanel.setBorder(small ? createActiveBorderSmall() : createActiveBorder());

  String acceleratorsText = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_SHOW_INTENTION_ACTIONS));
  if (!acceleratorsText.isEmpty()) {
    myIconLabel.setToolTipText(CodeInsightBundle.message("lightbulb.tooltip", acceleratorsText));
  }
}
 
Example 8
Source File: CompletionUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * @return String representation of action shortcut. Useful while advertising something
 * @see #advertise(CompletionParameters)
 */
@Nonnull
public static String getActionShortcut(@NonNls @Nonnull final String actionId) {
  return KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(actionId));
}
 
Example 9
Source File: CopyFilesOrDirectoriesDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected JComponent createNorthPanel() {
  myInformationLabel = JBLabelDecorator.createJBLabelDecorator().setBold(true);
  final FormBuilder formBuilder = FormBuilder.createFormBuilder().addComponent(myInformationLabel).addVerticalGap(
    UIUtil.LARGE_VGAP - UIUtil.DEFAULT_VGAP);
  DocumentListener documentListener = new DocumentAdapter() {
    @Override
    public void textChanged(DocumentEvent event) {
      validateOKButton();
    }
  };

  if (myShowNewNameField) {
    myNewNameField = new JTextField();
    myNewNameField.getDocument().addDocumentListener(documentListener);
    formBuilder.addLabeledComponent(RefactoringBundle.message("copy.files.new.name.label"), myNewNameField);
  }

  if (myShowDirectoryField) {
    myTargetDirectoryField = new TextFieldWithHistoryWithBrowseButton();
    myTargetDirectoryField.setTextFieldPreferredWidth(MAX_PATH_LENGTH);
    final List<String> recentEntries = RecentsManager.getInstance(myProject).getRecentEntries(RECENT_KEYS);
    if (recentEntries != null) {
      myTargetDirectoryField.getChildComponent().setHistory(recentEntries);
    }
    final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    myTargetDirectoryField.addBrowseFolderListener(RefactoringBundle.message("select.target.directory"),
                                                   RefactoringBundle.message("the.file.will.be.copied.to.this.directory"),
                                                   myProject, descriptor,
                                                   TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT);
    myTargetDirectoryField.getChildComponent().addDocumentListener(new DocumentAdapter() {
      @Override
      protected void textChanged(DocumentEvent e) {
        validateOKButton();
      }
    });
    formBuilder.addLabeledComponent(RefactoringBundle.message("copy.files.to.directory.label"), myTargetDirectoryField);

    String shortcutText =
      KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_CODE_COMPLETION));
    formBuilder.addTooltip(RefactoringBundle.message("path.completion.shortcut", shortcutText));
  }

  final JPanel wrapper = new JPanel(new BorderLayout());
  wrapper.add(myOpenFilesInEditor, BorderLayout.EAST);
  formBuilder.addComponent(wrapper);
  return formBuilder.getPanel();
}
 
Example 10
Source File: MoveFilesOrDirectoriesDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected JComponent createNorthPanel() {
  myNameLabel = JBLabelDecorator.createJBLabelDecorator().setBold(true);

  myTargetDirectoryField = new TextFieldWithHistoryWithBrowseButton();
  final List<String> recentEntries = RecentsManager.getInstance(myProject).getRecentEntries(RECENT_KEYS);
  if (recentEntries != null) {
    myTargetDirectoryField.getChildComponent().setHistory(recentEntries);
  }
  final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
  myTargetDirectoryField.addBrowseFolderListener(RefactoringBundle.message("select.target.directory"),
                                                 RefactoringBundle.message("the.file.will.be.moved.to.this.directory"),
                                                 myProject,
                                                 descriptor,
                                                 TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT);
  final JTextField textField = myTargetDirectoryField.getChildComponent().getTextEditor();
  FileChooserFactory.getInstance().installFileCompletion(textField, descriptor, true, getDisposable());
  textField.getDocument().addDocumentListener(new DocumentAdapter() {
    @Override
    protected void textChanged(DocumentEvent e) {
      validateOKButton();
    }
  });
  myTargetDirectoryField.setTextFieldPreferredWidth(CopyFilesOrDirectoriesDialog.MAX_PATH_LENGTH);
  Disposer.register(getDisposable(), myTargetDirectoryField);

  String shortcutText = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_CODE_COMPLETION));

  myCbSearchForReferences = new NonFocusableCheckBox(RefactoringBundle.message("search.for.references"));
  myCbSearchForReferences.setSelected(RefactoringSettings.getInstance().MOVE_SEARCH_FOR_REFERENCES_FOR_FILE);

  myOpenInEditorCb = new NonFocusableCheckBox("Open moved files in editor");
  myOpenInEditorCb.setSelected(isOpenInEditor());

  return FormBuilder.createFormBuilder().addComponent(myNameLabel)
          .addLabeledComponent(RefactoringBundle.message("move.files.to.directory.label"), myTargetDirectoryField, UIUtil.LARGE_VGAP)
          .addTooltip(RefactoringBundle.message("path.completion.shortcut", shortcutText))
          .addComponentToRightColumn(myCbSearchForReferences, UIUtil.LARGE_VGAP)
          .addComponentToRightColumn(myOpenInEditorCb, UIUtil.LARGE_VGAP)
          .getPanel();
}
 
Example 11
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");
      }
    }
  }
}
 
Example 12
Source File: FileInEditorProcessor.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private String prepareMessage() {
  StringBuilder builder = new StringBuilder("<html>");
  LayoutCodeInfoCollector notifications = myProcessor.getInfoCollector();
  LOG.assertTrue(notifications != null);

  if (notifications.isEmpty() && !myNoChangesDetected) {
    if (myProcessChangesTextOnly) {
      builder.append("No lines changed: changes since last revision are already properly formatted").append("<br>");
    }
    else {
      builder.append("No lines changed: code is already properly formatted").append("<br>");
    }
  }
  else {
    if (notifications.hasReformatOrRearrangeNotification()) {
      String reformatInfo = notifications.getReformatCodeNotification();
      String rearrangeInfo = notifications.getRearrangeCodeNotification();

      builder.append(joinWithCommaAndCapitalize(reformatInfo, rearrangeInfo));

      if (myProcessChangesTextOnly) {
        builder.append(" in changes since last revision");
      }

      builder.append("<br>");
    }
    else if (myNoChangesDetected) {
      builder.append("No lines changed: no changes since last revision").append("<br>");
    }

    String optimizeImportsNotification = notifications.getOptimizeImportsNotification();
    if (optimizeImportsNotification != null) {
      builder.append(StringUtil.capitalize(optimizeImportsNotification)).append("<br>");
    }
  }

  String shortcutText = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction("ShowReformatFileDialog"));
  String color = ColorUtil.toHex(JBColor.gray);

  builder.append("<span style='color:#").append(color).append("'>")
          .append("<a href=''>Show</a> reformat dialog: ").append(shortcutText).append("</span>")
          .append("</html>");

  return builder.toString();
}
 
Example 13
Source File: CompletionAdvertiser.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected static String getShortcut(final String id) {
  return KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(id));
}
 
Example 14
Source File: ActionMenuItem.java    From consulo with Apache License 2.0 4 votes vote down vote up
public String getFirstShortcutText() {
  return KeymapUtil.getFirstKeyboardShortcutText(myAction.getAction());
}
 
Example 15
Source File: ActionButton.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
protected String getShortcutText() {
  return KeymapUtil.getFirstKeyboardShortcutText(myAction);
}
 
Example 16
Source File: EditorEmptyTextPainter.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
protected String getActionShortcutText(@Nonnull String actionId) {
  return KeymapUtil.getFirstKeyboardShortcutText(actionId);
}
 
Example 17
Source File: CompletionContributor.java    From consulo with Apache License 2.0 2 votes vote down vote up
/**
 * @param actionId
 * @return String representation of action shortcut. Useful while advertising something
 * @see #advertise(CompletionParameters)
 */
public static String getActionShortcut(@NonNls final String actionId) {
  return KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(actionId));
}