Search in sources :

Example 51 with RangeHighlighter

use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.

the class DuplicatesImpl method replaceMatch.

private static boolean replaceMatch(final Project project, final MatchProvider provider, final Match match, @NotNull final Editor editor, final int idx, final int size, Ref<Boolean> showAll, final String confirmDuplicatePrompt, boolean skipPromptWhenOne) {
    final ArrayList<RangeHighlighter> highlighters = previewMatch(project, match, editor);
    try {
        if (!ApplicationManager.getApplication().isUnitTestMode()) {
            if ((!skipPromptWhenOne || size > 1) && (showAll.get() == null || !showAll.get())) {
                final String prompt = provider.getConfirmDuplicatePrompt(match);
                final ReplacePromptDialog promptDialog = new ReplacePromptDialog(false, provider.getReplaceDuplicatesTitle(idx, size), project) {

                    @Override
                    protected String getMessage() {
                        final String message = super.getMessage();
                        return prompt != null ? message + " " + prompt : message;
                    }
                };
                promptDialog.show();
                final boolean allChosen = promptDialog.getExitCode() == FindManager.PromptResult.ALL;
                showAll.set(allChosen);
                if (allChosen && confirmDuplicatePrompt != null && prompt == null) {
                    if (Messages.showOkCancelDialog(project, "In order to replace all occurrences method signature will be changed. Proceed?", CommonBundle.getWarningTitle(), Messages.getWarningIcon()) != Messages.OK)
                        return true;
                }
                if (promptDialog.getExitCode() == FindManager.PromptResult.SKIP)
                    return false;
                if (promptDialog.getExitCode() == FindManager.PromptResult.CANCEL)
                    return true;
            }
        }
    } finally {
        HighlightManager.getInstance(project).removeSegmentHighlighter(editor, highlighters.get(0));
    }
    // call change signature when needed
    provider.prepareSignature(match);
    new WriteCommandAction(project, MethodDuplicatesHandler.REFACTORING_NAME, MethodDuplicatesHandler.REFACTORING_NAME) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            try {
                provider.processMatch(match);
            } catch (IncorrectOperationException e) {
                LOG.error(e);
            }
        }
    }.execute();
    return false;
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) ReplacePromptDialog(com.intellij.ui.ReplacePromptDialog) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Result(com.intellij.openapi.application.Result)

Example 52 with RangeHighlighter

use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.

the class AnnotateStackTraceAction method getHyperlinkVirtualFile.

@Nullable
@CalledWithReadLock
private static VirtualFile getHyperlinkVirtualFile(@NotNull List<RangeHighlighter> links) {
    RangeHighlighter key = ContainerUtil.getLastItem(links);
    if (key == null)
        return null;
    HyperlinkInfo info = EditorHyperlinkSupport.getHyperlinkInfo(key);
    if (!(info instanceof FileHyperlinkInfo))
        return null;
    OpenFileDescriptor descriptor = ((FileHyperlinkInfo) info).getDescriptor();
    return descriptor != null ? descriptor.getFile() : null;
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) FileHyperlinkInfo(com.intellij.execution.filters.FileHyperlinkInfo) FileHyperlinkInfo(com.intellij.execution.filters.FileHyperlinkInfo) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo) CalledWithReadLock(org.jetbrains.annotations.CalledWithReadLock) Nullable(org.jetbrains.annotations.Nullable)

Example 53 with RangeHighlighter

use of com.intellij.openapi.editor.markup.RangeHighlighter in project ideavim by JetBrains.

the class SearchGroup method removeSearchHighlight.

private static void removeSearchHighlight(@NotNull Editor editor) {
    Collection<RangeHighlighter> ehl = EditorData.getLastHighlights(editor);
    if (ehl == null) {
        return;
    }
    for (RangeHighlighter rh : ehl) {
        editor.getMarkupModel().removeHighlighter(rh);
    }
    ehl.clear();
    EditorData.setLastHighlights(editor, null);
    EditorData.setLastSearch(editor, null);
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter)

Example 54 with RangeHighlighter

use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.

the class VcsPreviewPanel method addHighlighter.

private void addHighlighter(@NotNull Range range, @NotNull ColorKey colorKey) {
    TextRange textRange = DiffUtil.getLinesRange(myEditor.getDocument(), range.getLine1(), range.getLine2());
    RangeHighlighter highlighter = LineStatusMarkerRenderer.createRangeHighlighter(range, textRange, myEditor.getMarkupModel());
    highlighter.setLineMarkerRenderer(new LineStatusMarkerRenderer(range) {

        @Override
        public boolean canDoAction(MouseEvent e) {
            return isInsideMarkerArea(e);
        }

        @Override
        public void doAction(Editor editor, MouseEvent e) {
            myDispatcher.getMulticaster().selectionInPreviewChanged(colorKey.getExternalName());
        }
    });
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) LineStatusMarkerRenderer(com.intellij.openapi.vcs.ex.LineStatusMarkerRenderer) MouseEvent(java.awt.event.MouseEvent) TextRange(com.intellij.openapi.util.TextRange) Editor(com.intellij.openapi.editor.Editor)

Example 55 with RangeHighlighter

use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.

the class EditorHyperlinkSupport method createHyperlink.

@NotNull
private RangeHighlighter createHyperlink(final int highlightStartOffset, final int highlightEndOffset, @Nullable final TextAttributes highlightAttributes, @NotNull final HyperlinkInfo hyperlinkInfo, @Nullable TextAttributes followedHyperlinkAttributes, int layer) {
    TextAttributes textAttributes = highlightAttributes != null ? highlightAttributes : getHyperlinkAttributes();
    final RangeHighlighter highlighter = myEditor.getMarkupModel().addRangeHighlighter(highlightStartOffset, highlightEndOffset, layer, textAttributes, HighlighterTargetArea.EXACT_RANGE);
    associateHyperlink(highlighter, hyperlinkInfo, followedHyperlinkAttributes);
    return highlighter;
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)97 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)26 TextRange (com.intellij.openapi.util.TextRange)22 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)18 Editor (com.intellij.openapi.editor.Editor)15 ArrayList (java.util.ArrayList)15 NotNull (org.jetbrains.annotations.NotNull)15 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)10 Project (com.intellij.openapi.project.Project)10 RelativePoint (com.intellij.ui.awt.RelativePoint)8 Nullable (org.jetbrains.annotations.Nullable)8 Document (com.intellij.openapi.editor.Document)7 EditorEx (com.intellij.openapi.editor.ex.EditorEx)7 MarkupModelEx (com.intellij.openapi.editor.ex.MarkupModelEx)7 MarkupModel (com.intellij.openapi.editor.markup.MarkupModel)7 PsiElement (com.intellij.psi.PsiElement)6 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)5 EditorWindow (com.intellij.injected.editor.EditorWindow)4 Result (com.intellij.openapi.application.Result)4 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)4