Search in sources :

Example 26 with HighlightManager

use of com.intellij.codeInsight.highlighting.HighlightManager in project intellij-community by JetBrains.

the class GrIntroduceHandlerBase method showDialog.

@Nullable
private Settings showDialog(@NotNull GrIntroduceContext context) {
    // Add occurrences highlighting
    ArrayList<RangeHighlighter> highlighters = new ArrayList<>();
    HighlightManager highlightManager = null;
    if (context.getEditor() != null) {
        highlightManager = HighlightManager.getInstance(context.getProject());
        EditorColorsManager colorsManager = EditorColorsManager.getInstance();
        TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
        if (context.getOccurrences().length > 1) {
            highlightManager.addOccurrenceHighlights(context.getEditor(), context.getOccurrences(), attributes, true, highlighters);
        }
    }
    GrIntroduceDialog<Settings> dialog = getDialog(context);
    dialog.show();
    if (dialog.isOK()) {
        if (context.getEditor() != null) {
            for (RangeHighlighter highlighter : highlighters) {
                highlightManager.removeSegmentHighlighter(context.getEditor(), highlighter);
            }
        }
        return dialog.getSettings();
    } else {
        if (context.getOccurrences().length > 1) {
            WindowManager.getInstance().getStatusBar(context.getProject()).setInfo(GroovyRefactoringBundle.message("press.escape.to.remove.the.highlighting"));
        }
    }
    return null;
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) Nullable(org.jetbrains.annotations.Nullable)

Example 27 with HighlightManager

use of com.intellij.codeInsight.highlighting.HighlightManager in project intellij-community by JetBrains.

the class GroovyRefactoringUtil method highlightOccurrencesByRanges.

public static void highlightOccurrencesByRanges(Project project, Editor editor, TextRange[] ranges) {
    if (editor == null)
        return;
    ArrayList<RangeHighlighter> highlighters = new ArrayList<>();
    HighlightManager highlightManager = HighlightManager.getInstance(project);
    EditorColorsManager colorsManager = EditorColorsManager.getInstance();
    TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
    for (TextRange range : ranges) {
        highlightManager.addRangeHighlight(editor, range.getStartOffset(), range.getEndOffset(), attributes, false, highlighters);
    }
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) TextRange(com.intellij.openapi.util.TextRange) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager)

Example 28 with HighlightManager

use of com.intellij.codeInsight.highlighting.HighlightManager in project intellij-community by JetBrains.

the class HighlightUtils method highlightElements.

public static void highlightElements(@NotNull final Collection<? extends PsiElement> elementCollection) {
    if (elementCollection.isEmpty()) {
        return;
    }
    if (elementCollection.contains(null)) {
        throw new IllegalArgumentException("Nulls passed in collection: " + elementCollection);
    }
    final Application application = ApplicationManager.getApplication();
    application.invokeLater(() -> {
        final PsiElement[] elements = PsiUtilCore.toPsiElementArray(elementCollection);
        final PsiElement firstElement = elements[0];
        if (ContainerUtil.exists(elements, element -> !element.isValid())) {
            return;
        }
        final Project project = firstElement.getProject();
        if (project.isDisposed())
            return;
        final FileEditorManager editorManager = FileEditorManager.getInstance(project);
        final EditorColorsManager editorColorsManager = EditorColorsManager.getInstance();
        final Editor editor = editorManager.getSelectedTextEditor();
        if (editor == null) {
            return;
        }
        final EditorColorsScheme globalScheme = editorColorsManager.getGlobalScheme();
        final TextAttributes textattributes = globalScheme.getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
        final HighlightManager highlightManager = HighlightManager.getInstance(project);
        highlightManager.addOccurrenceHighlights(editor, elements, textattributes, true, null);
        final WindowManager windowManager = WindowManager.getInstance();
        final StatusBar statusBar = windowManager.getStatusBar(project);
        statusBar.setInfo(InspectionGadgetsBundle.message("press.escape.to.remove.highlighting.message"));
        final FindManager findmanager = FindManager.getInstance(project);
        FindModel findmodel = findmanager.getFindNextModel();
        if (findmodel == null) {
            findmodel = findmanager.getFindInFileModel();
        }
        findmodel.setSearchHighlighters(true);
        findmanager.setFindWasPerformed();
        findmanager.setFindNextModel(findmodel);
    });
}
Also used : FindModel(com.intellij.find.FindModel) HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) StatusBar(com.intellij.openapi.wm.StatusBar) WindowManager(com.intellij.openapi.wm.WindowManager) Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FindManager(com.intellij.find.FindManager) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) Editor(com.intellij.openapi.editor.Editor) Application(com.intellij.openapi.application.Application) PsiElement(com.intellij.psi.PsiElement)

Example 29 with HighlightManager

use of com.intellij.codeInsight.highlighting.HighlightManager in project intellij-community by JetBrains.

the class InplaceRefactoring method finish.

public void finish(boolean success) {
    if (!ourRenamersStack.isEmpty() && ourRenamersStack.peek() == this) {
        ourRenamersStack.pop();
    }
    if (myHighlighters != null) {
        if (!myProject.isDisposed()) {
            final HighlightManager highlightManager = HighlightManager.getInstance(myProject);
            for (RangeHighlighter highlighter : myHighlighters) {
                highlightManager.removeSegmentHighlighter(myEditor, highlighter);
            }
        }
        myHighlighters = null;
        myEditor.putUserData(INPLACE_RENAMER, null);
    }
    if (myBalloon != null) {
        if (!isRestart()) {
            myBalloon.hide();
        }
    }
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager)

Example 30 with HighlightManager

use of com.intellij.codeInsight.highlighting.HighlightManager in project intellij-community by JetBrains.

the class ExtractMethodHandler method highlightPrepareError.

public static void highlightPrepareError(PrepareFailedException e, PsiFile file, Editor editor, final Project project) {
    if (e.getFile() == file) {
        final TextRange textRange = e.getTextRange();
        final HighlightManager highlightManager = HighlightManager.getInstance(project);
        EditorColorsManager colorsManager = EditorColorsManager.getInstance();
        TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
        highlightManager.addRangeHighlight(editor, textRange.getStartOffset(), textRange.getEndOffset(), attributes, true, null);
        final LogicalPosition logicalPosition = editor.offsetToLogicalPosition(textRange.getStartOffset());
        editor.getScrollingModel().scrollTo(logicalPosition, ScrollType.MAKE_VISIBLE);
        WindowManager.getInstance().getStatusBar(project).setInfo(RefactoringBundle.message("press.escape.to.remove.the.highlighting"));
    }
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) TextRange(com.intellij.openapi.util.TextRange) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager)

Aggregations

HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)34 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)26 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)23 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)18 Editor (com.intellij.openapi.editor.Editor)9 Project (com.intellij.openapi.project.Project)9 TextRange (com.intellij.openapi.util.TextRange)9 ArrayList (java.util.ArrayList)8 PsiElement (com.intellij.psi.PsiElement)6 WindowManager (com.intellij.openapi.wm.WindowManager)4 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)3 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)3 XmlTag (com.intellij.psi.xml.XmlTag)3 Nullable (org.jetbrains.annotations.Nullable)3 TargetElementUtil (com.intellij.codeInsight.TargetElementUtil)2 FindManager (com.intellij.find.FindManager)2 FindModel (com.intellij.find.FindModel)2 EditorWindow (com.intellij.injected.editor.EditorWindow)2 Application (com.intellij.openapi.application.Application)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2