Example usage for com.intellij.openapi.actionSystem IdeActions ACTION_FIND_NEXT

List of usage examples for com.intellij.openapi.actionSystem IdeActions ACTION_FIND_NEXT

Introduction

In this page you can find the example usage for com.intellij.openapi.actionSystem IdeActions ACTION_FIND_NEXT.

Prototype

String ACTION_FIND_NEXT

To view the source code for com.intellij.openapi.actionSystem IdeActions ACTION_FIND_NEXT.

Click Source Link

Usage

From source file:com.intellij.find.editorHeaderActions.NextOccurrenceAction.java

License:Apache License

public NextOccurrenceAction(EditorSearchComponent editorSearchComponent,
        Getter<JTextComponent> editorTextField) {
    super(editorSearchComponent);
    myTextField = editorTextField;//from w  ww. jav a  2 s  .  c o m
    copyFrom(ActionManager.getInstance().getAction(IdeActions.ACTION_NEXT_OCCURENCE));
    ArrayList<Shortcut> shortcuts = new ArrayList<Shortcut>();
    ContainerUtil.addAll(shortcuts,
            ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_NEXT).getShortcutSet().getShortcuts());
    if (!editorSearchComponent.getFindModel().isMultiline()) {
        ContainerUtil.addAll(shortcuts, ActionManager.getInstance()
                .getAction(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN).getShortcutSet().getShortcuts());

        shortcuts.add(new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), null));
    }

    registerShortcutsForComponent(shortcuts, editorTextField.get());
}

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   www .j  a  v  a  2  s .c  om
            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 w w w .  j ava  2s.  c  o  m
        }

        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;
            }//w w  w .j  a v a2 s.  c  o 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;
}