Example usage for com.intellij.openapi.keymap KeymapUtil getFirstKeyboardShortcutText

List of usage examples for com.intellij.openapi.keymap KeymapUtil getFirstKeyboardShortcutText

Introduction

In this page you can find the example usage for com.intellij.openapi.keymap KeymapUtil getFirstKeyboardShortcutText.

Prototype

@NotNull
    public static String getFirstKeyboardShortcutText(@NotNull ShortcutSet set) 

Source Link

Usage

From source file:browsewordatcaret.BWACEditorComponent.java

License:Apache License

@NotNull
private String getPerformAgainMessage(@NotNull final BWACHandlerBrowse.BrowseDirection browseDirection) {
    AnAction action = ActionManager.getInstance().getAction(
            browseDirection == BWACHandlerBrowse.BrowseDirection.NEXT ? "BrowseWordAtCaretPlugin.Next"
                    : "BrowseWordAtCaretPlugin.Previous");
    String shortcutsText = KeymapUtil.getFirstKeyboardShortcutText(action);
    String message;//  w w  w.j a v a2s  . c o  m
    if (shortcutsText.length() > 0) {
        if (browseDirection == BWACHandlerBrowse.BrowseDirection.NEXT) {
            message = "Not found, press " + shortcutsText + " to browse from the top";
        } else {
            message = "Not found, press " + shortcutsText + " to browse from the bottom";
        }
    } else {
        if (browseDirection == BWACHandlerBrowse.BrowseDirection.NEXT) {
            message = "Not found, perform \"Browse to next word\" again to browse from the top";
        } else {
            message = "Not found, perform \"Browse to previous word\" again to browse from the bottom";
        }
    }
    return JDOMUtil.escapeText(message, false, false);
}

From source file:com.intellij.application.options.CodeCompletionPanel.java

License:Apache License

public CodeCompletionPanel() {
    //noinspection unchecked
    myCaseSensitiveCombo.setModel(new DefaultComboBoxModel(CASE_VARIANTS));

    ActionManager actionManager = ActionManager.getInstance();
    String basicShortcut = KeymapUtil
            .getFirstKeyboardShortcutText(actionManager.getAction(IdeActions.ACTION_CODE_COMPLETION));
    String smartShortcut = KeymapUtil
            .getFirstKeyboardShortcutText(actionManager.getAction(IdeActions.ACTION_SMART_TYPE_COMPLETION));
    if (StringUtil.isNotEmpty(basicShortcut)) {
        myCbOnCodeCompletion.setText(myCbOnCodeCompletion.getText() + " ( " + basicShortcut + " )");
    }//from   w  w  w  .j a va  2s .co  m
    if (StringUtil.isNotEmpty(smartShortcut)) {
        myCbOnSmartTypeCompletion.setText(myCbOnSmartTypeCompletion.getText() + " ( " + smartShortcut + " )");
    }

    myCbAutocompletion.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            boolean selected = myCbAutocompletion.isSelected();
            myCbSelectByChars.setEnabled(selected);
        }
    });

    myCbAutopopupJavaDoc.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            myAutopopupJavaDocField.setEnabled(myCbAutopopupJavaDoc.isSelected());
        }
    });

    myCbParameterInfoPopup.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            myParameterInfoDelayField.setEnabled(myCbParameterInfoPopup.isSelected());
        }
    });

    reset();
}

From source file:com.intellij.codeInsight.completion.CompletionAdvertiser.java

License:Apache License

protected static String getShortcut(final String id) {
    return KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(id));
}

From source file:com.intellij.codeInsight.completion.CompletionContributor.java

License:Apache License

/**
 * @param actionId/*from  w  w  w .ja  v a 2s .  c  om*/
 * @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));
}

From source file:com.intellij.codeInsight.daemon.impl.ShowAutoImportPass.java

License:Apache License

public static String getMessage(final boolean multiple, final 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;
}

From source file:com.intellij.codeInsight.intention.impl.IntentionHintComponent.java

License:Apache License

private void onMouseEnter(final boolean small) {
    myIconLabel.setIcon(myHighlightedIcon);
    setBorder(small ? ACTIVE_BORDER_SMALL : ACTIVE_BORDER);

    String acceleratorsText = KeymapUtil.getFirstKeyboardShortcutText(
            ActionManager.getInstance().getAction(IdeActions.ACTION_SHOW_INTENTION_ACTIONS));
    if (!acceleratorsText.isEmpty()) {
        myIconLabel.setToolTipText(CodeInsightBundle.message("lightbulb.tooltip", acceleratorsText));
    }/* w  ww .java2 s. c  o  m*/
}

From source file:com.intellij.find.findUsages.FindUsagesManager.java

License:Apache License

private static String getSearchAgainMessage(PsiElement element, final FileSearchScope direction) {
    String message = getNoUsagesFoundMessage(element);
    if (direction == FileSearchScope.AFTER_CARET) {
        AnAction action = ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_NEXT);
        String shortcutsText = KeymapUtil.getFirstKeyboardShortcutText(action);
        if (shortcutsText.isEmpty()) {
            message = FindBundle.message("find.search.again.from.top.action.message", message);
        } else {/*from  w w  w .  jav a2  s  .  co m*/
            message = FindBundle.message("find.search.again.from.top.hotkey.message", message, shortcutsText);
        }
    } else {
        String shortcutsText = KeymapUtil.getFirstKeyboardShortcutText(
                ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_PREVIOUS));
        if (shortcutsText.isEmpty()) {
            message = FindBundle.message("find.search.again.from.bottom.action.message", message);
        } else {
            message = FindBundle.message("find.search.again.from.bottom.hotkey.message", message,
                    shortcutsText);
        }
    }
    return message;
}

From source file:com.intellij.find.FindUtil.java

License:Apache License

public static void processNotFound(final Editor editor, String stringToFind, FindModel model, Project project) {
    String message = FindBundle.message("find.search.string.not.found.message", stringToFind);

    short position = HintManager.UNDER;
    if (model.isGlobal()) {
        final FindModel newModel = (FindModel) model.clone();
        FindManager findManager = FindManager.getInstance(project);
        Document document = editor.getDocument();
        FindResult result = findManager.findString(document.getCharsSequence(),
                newModel.isForward() ? 0 : document.getTextLength(), model, getVirtualFile(editor));
        if (!result.isStringFound()) {
            result = null;//from www .java 2 s.com
        }

        FindModel modelForNextSearch = findManager.getFindNextModel(editor);
        if (modelForNextSearch == null) {
            modelForNextSearch = findManager.getFindInFileModel();
        }

        if (result != null) {
            if (newModel.isForward()) {
                AnAction action = ActionManager.getInstance()
                        .getAction(modelForNextSearch.isForward() ? IdeActions.ACTION_FIND_NEXT
                                : IdeActions.ACTION_FIND_PREVIOUS);
                String shortcutsText = KeymapUtil.getFirstKeyboardShortcutText(action);
                if (shortcutsText.length() > 0) {
                    message = FindBundle.message("find.search.again.from.top.hotkey.message", message,
                            shortcutsText);
                } else {
                    message = FindBundle.message("find.search.again.from.top.action.message", message);
                }
                editor.putUserData(KEY, Direction.DOWN);
            } else {
                AnAction action = ActionManager.getInstance()
                        .getAction(modelForNextSearch.isForward() ? IdeActions.ACTION_FIND_PREVIOUS
                                : IdeActions.ACTION_FIND_NEXT);
                String shortcutsText = KeymapUtil.getFirstKeyboardShortcutText(action);
                if (shortcutsText.length() > 0) {
                    message = FindBundle.message("find.search.again.from.bottom.hotkey.message", message,
                            shortcutsText);
                } else {
                    message = FindBundle.message("find.search.again.from.bottom.action.message", message);
                }
                editor.putUserData(KEY, Direction.UP);
                position = HintManager.ABOVE;
            }
        }
        CaretListener listener = new CaretAdapter() {
            @Override
            public void caretPositionChanged(CaretEvent e) {
                editor.putUserData(KEY, null);
                editor.getCaretModel().removeCaretListener(this);
            }
        };
        editor.getCaretModel().addCaretListener(listener);
    }
    JComponent component = HintUtil.createInformationLabel(JDOMUtil.escapeText(message, false, false));
    final LightweightHint hint = new LightweightHint(component);
    HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, position,
            HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING, 0,
            false);
}

From source file:com.intellij.find.impl.FindManagerImpl.java

License:Apache License

private static boolean highlightNextHighlighter(RangeHighlighter[] highlighters, Editor editor, int offset,
        boolean isForward, boolean secondPass) {
    RangeHighlighter highlighterToSelect = null;
    Object wasNotFound = editor.getUserData(HIGHLIGHTER_WAS_NOT_FOUND_KEY);
    for (RangeHighlighter highlighter : highlighters) {
        int start = highlighter.getStartOffset();
        int end = highlighter.getEndOffset();
        if (highlighter.isValid() && start < end) {
            if (isForward && (start > offset || start == offset && secondPass)) {
                if (highlighterToSelect == null || highlighterToSelect.getStartOffset() > start)
                    highlighterToSelect = highlighter;
            }/*from w w  w.j  a va 2s. co m*/
            if (!isForward && (end < offset || end == offset && secondPass)) {
                if (highlighterToSelect == null || highlighterToSelect.getEndOffset() < end)
                    highlighterToSelect = highlighter;
            }
        }
    }
    if (highlighterToSelect != null) {
        expandFoldRegionsIfNecessary(editor, highlighterToSelect.getStartOffset(),
                highlighterToSelect.getEndOffset());
        editor.getSelectionModel().setSelection(highlighterToSelect.getStartOffset(),
                highlighterToSelect.getEndOffset());
        editor.getCaretModel().moveToOffset(highlighterToSelect.getStartOffset());
        ScrollType scrollType;
        if (secondPass) {
            scrollType = isForward ? ScrollType.CENTER_UP : ScrollType.CENTER_DOWN;
        } else {
            scrollType = isForward ? ScrollType.CENTER_DOWN : ScrollType.CENTER_UP;
        }
        editor.getScrollingModel().scrollToCaret(scrollType);
        editor.putUserData(HIGHLIGHTER_WAS_NOT_FOUND_KEY, null);
        return true;
    }

    if (wasNotFound == null) {
        editor.putUserData(HIGHLIGHTER_WAS_NOT_FOUND_KEY, Boolean.TRUE);
        String message = FindBundle.message("find.highlight.no.more.highlights.found");
        if (isForward) {
            AnAction action = ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_NEXT);
            String shortcutsText = KeymapUtil.getFirstKeyboardShortcutText(action);
            if (shortcutsText.isEmpty()) {
                message = FindBundle.message("find.search.again.from.top.action.message", message);
            } else {
                message = FindBundle.message("find.search.again.from.top.hotkey.message", message,
                        shortcutsText);
            }
        } else {
            AnAction action = ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_PREVIOUS);
            String shortcutsText = KeymapUtil.getFirstKeyboardShortcutText(action);
            if (shortcutsText.isEmpty()) {
                message = FindBundle.message("find.search.again.from.bottom.action.message", message);
            } else {
                message = FindBundle.message("find.search.again.from.bottom.hotkey.message", message,
                        shortcutsText);
            }
        }
        JComponent component = HintUtil.createInformationLabel(message);
        final LightweightHint hint = new LightweightHint(component);
        HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, HintManager.UNDER,
                HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING,
                0, false);
        return true;
    }
    if (!secondPass) {
        offset = isForward ? 0 : editor.getDocument().getTextLength();
        return highlightNextHighlighter(highlighters, editor, offset, isForward, true);
    }

    return false;
}

From source file:com.intellij.refactoring.copy.CopyFilesOrDirectoriesDialog.java

License:Apache License

@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/*from w  ww. ja  va  2  s. c  o m*/
        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();
}