Search in sources :

Example 36 with EditorColorsManager

use of com.intellij.openapi.editor.colors.EditorColorsManager 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 37 with EditorColorsManager

use of com.intellij.openapi.editor.colors.EditorColorsManager in project intellij-community by JetBrains.

the class UsagePreviewPanel method highlight.

public static void highlight(@NotNull final List<UsageInfo> infos, @NotNull final Editor editor, @NotNull final Project project, boolean highlightOnlyNameElements, int highlightLayer) {
    LOG.assertTrue(!PsiDocumentManager.getInstance(project).hasUncommitedDocuments());
    MarkupModel markupModel = editor.getMarkupModel();
    for (RangeHighlighter highlighter : markupModel.getAllHighlighters()) {
        if (highlighter.getUserData(IN_PREVIEW_USAGE_FLAG) != null) {
            highlighter.dispose();
        }
    }
    for (int i = infos.size() - 1; i >= 0; i--) {
        // finish with the first usage so that caret end up there
        UsageInfo info = infos.get(i);
        PsiElement psiElement = info.getElement();
        if (psiElement == null || !psiElement.isValid())
            continue;
        int offsetInFile = psiElement.getTextOffset();
        EditorColorsManager colorManager = EditorColorsManager.getInstance();
        TextAttributes attributes = colorManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
        TextRange elementRange = psiElement.getTextRange();
        TextRange infoRange = info.getRangeInElement();
        TextRange textRange = infoRange == null || infoRange.getStartOffset() > elementRange.getLength() || infoRange.getEndOffset() > elementRange.getLength() ? null : elementRange.cutOut(infoRange);
        if (textRange == null)
            textRange = elementRange;
        // hack to determine element range to highlight
        if (highlightOnlyNameElements && psiElement instanceof PsiNamedElement && !(psiElement instanceof PsiFile)) {
            PsiFile psiFile = psiElement.getContainingFile();
            PsiElement nameElement = psiFile.findElementAt(offsetInFile);
            if (nameElement != null) {
                textRange = nameElement.getTextRange();
            }
        }
        // highlight injected element in host document textrange
        textRange = InjectedLanguageManager.getInstance(project).injectedToHost(psiElement, textRange);
        RangeHighlighter highlighter = markupModel.addRangeHighlighter(textRange.getStartOffset(), textRange.getEndOffset(), highlightLayer, attributes, HighlighterTargetArea.EXACT_RANGE);
        highlighter.putUserData(IN_PREVIEW_USAGE_FLAG, Boolean.TRUE);
        editor.getCaretModel().moveToOffset(textRange.getEndOffset());
    }
    editor.getScrollingModel().scrollToCaret(ScrollType.CENTER);
}
Also used : TextRange(com.intellij.openapi.util.TextRange) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) UsageInfo(com.intellij.usageView.UsageInfo)

Example 38 with EditorColorsManager

use of com.intellij.openapi.editor.colors.EditorColorsManager 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)

Example 39 with EditorColorsManager

use of com.intellij.openapi.editor.colors.EditorColorsManager in project intellij-community by JetBrains.

the class RefactoringUtil method highlightAllOccurrences.

/**
   * @return List of highlighters
   */
public static List<RangeHighlighter> highlightAllOccurrences(Project project, PsiElement[] occurrences, Editor editor) {
    ArrayList<RangeHighlighter> highlighters = new ArrayList<>();
    HighlightManager highlightManager = HighlightManager.getInstance(project);
    EditorColorsManager colorsManager = EditorColorsManager.getInstance();
    TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
    if (occurrences.length > 1) {
        for (PsiElement occurrence : occurrences) {
            final RangeMarker rangeMarker = occurrence.getUserData(ElementToWorkOn.TEXT_RANGE);
            if (rangeMarker != null && rangeMarker.isValid()) {
                highlightManager.addRangeHighlight(editor, rangeMarker.getStartOffset(), rangeMarker.getEndOffset(), attributes, true, highlighters);
            } else {
                final TextRange textRange = occurrence.getTextRange();
                highlightManager.addRangeHighlight(editor, textRange.getStartOffset(), textRange.getEndOffset(), attributes, true, highlighters);
            }
        }
    }
    return highlighters;
}
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) RangeMarker(com.intellij.openapi.editor.RangeMarker)

Example 40 with EditorColorsManager

use of com.intellij.openapi.editor.colors.EditorColorsManager in project intellij-community by JetBrains.

the class DocumentationComponent method applyFontSize.

private void applyFontSize() {
    Document document = myEditorPane.getDocument();
    if (!(document instanceof StyledDocument)) {
        return;
    }
    final StyledDocument styledDocument = (StyledDocument) document;
    EditorColorsManager colorsManager = EditorColorsManager.getInstance();
    EditorColorsScheme scheme = colorsManager.getGlobalScheme();
    StyleConstants.setFontSize(myFontSizeStyle, JBUI.scale(getQuickDocFontSize().getSize()));
    if (Registry.is("documentation.component.editor.font")) {
        StyleConstants.setFontFamily(myFontSizeStyle, scheme.getEditorFontName());
    }
    ApplicationManager.getApplication().executeOnPooledThread(() -> styledDocument.setCharacterAttributes(0, styledDocument.getLength(), myFontSizeStyle, false));
}
Also used : EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) HTMLDocument(javax.swing.text.html.HTMLDocument)

Aggregations

EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)43 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)37 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)22 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)14 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)9 Editor (com.intellij.openapi.editor.Editor)7 Project (com.intellij.openapi.project.Project)7 TextRange (com.intellij.openapi.util.TextRange)7 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)6 ArrayList (java.util.ArrayList)6 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)4 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)3 WindowManager (com.intellij.openapi.wm.WindowManager)3 PsiElement (com.intellij.psi.PsiElement)3 Nullable (org.jetbrains.annotations.Nullable)3 FindManager (com.intellij.find.FindManager)2 FindModel (com.intellij.find.FindModel)2 Application (com.intellij.openapi.application.Application)2 Document (com.intellij.openapi.editor.Document)2 StatusBar (com.intellij.openapi.wm.StatusBar)2