Search in sources :

Example 41 with EditorColorsManager

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

the class HighlightUsagesHandler method highlightReferences.

public static void highlightReferences(@NotNull Project project, @NotNull PsiElement element, @NotNull List<PsiReference> refs, Editor editor, PsiFile file, boolean clearHighlights) {
    HighlightManager highlightManager = HighlightManager.getInstance(project);
    EditorColorsManager manager = EditorColorsManager.getInstance();
    TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
    TextAttributes writeAttributes = manager.getGlobalScheme().getAttributes(EditorColors.WRITE_SEARCH_RESULT_ATTRIBUTES);
    setupFindModel(project);
    ReadWriteAccessDetector detector = ReadWriteAccessDetector.findDetector(element);
    if (detector != null) {
        List<PsiReference> readRefs = new ArrayList<>();
        List<PsiReference> writeRefs = new ArrayList<>();
        for (PsiReference ref : refs) {
            if (detector.getReferenceAccess(element, ref) == ReadWriteAccessDetector.Access.Read) {
                readRefs.add(ref);
            } else {
                writeRefs.add(ref);
            }
        }
        doHighlightRefs(highlightManager, editor, readRefs, attributes, clearHighlights);
        doHighlightRefs(highlightManager, editor, writeRefs, writeAttributes, clearHighlights);
    } else {
        doHighlightRefs(highlightManager, editor, refs, attributes, clearHighlights);
    }
    TextRange range = getNameIdentifierRange(file, element);
    if (range != null) {
        TextAttributes nameAttributes = attributes;
        if (detector != null && detector.isDeclarationWriteAccess(element)) {
            nameAttributes = writeAttributes;
        }
        highlightRanges(highlightManager, editor, nameAttributes, clearHighlights, Arrays.asList(range));
    }
}
Also used : ArrayList(java.util.ArrayList) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) TextRange(com.intellij.openapi.util.TextRange) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager)

Example 42 with EditorColorsManager

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

the class CopyReferenceAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    DataContext dataContext = e.getDataContext();
    Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
    Project project = CommonDataKeys.PROJECT.getData(dataContext);
    List<PsiElement> elements = getElementsToCopy(editor, dataContext);
    if (!doCopy(elements, project, editor) && editor != null && project != null) {
        Document document = editor.getDocument();
        PsiFile file = PsiDocumentManager.getInstance(project).getCachedPsiFile(document);
        if (file != null) {
            String toCopy = getFileFqn(file) + ":" + (editor.getCaretModel().getLogicalPosition().line + 1);
            CopyPasteManager.getInstance().setContents(new StringSelection(toCopy));
            setStatusBarText(project, toCopy + " has been copied");
        }
        return;
    }
    HighlightManager highlightManager = HighlightManager.getInstance(project);
    EditorColorsManager manager = EditorColorsManager.getInstance();
    TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
    if (elements.size() == 1 && editor != null && project != null) {
        PsiElement element = elements.get(0);
        PsiElement nameIdentifier = IdentifierUtil.getNameIdentifier(element);
        if (nameIdentifier != null) {
            highlightManager.addOccurrenceHighlights(editor, new PsiElement[] { nameIdentifier }, attributes, true, null);
        } else {
            PsiReference reference = TargetElementUtil.findReference(editor, editor.getCaretModel().getOffset());
            if (reference != null) {
                highlightManager.addOccurrenceHighlights(editor, new PsiReference[] { reference }, attributes, true, null);
            } else if (element != PsiDocumentManager.getInstance(project).getCachedPsiFile(editor.getDocument())) {
                highlightManager.addOccurrenceHighlights(editor, new PsiElement[] { element }, attributes, true, null);
            }
        }
    }
}
Also used : HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) Document(com.intellij.openapi.editor.Document) StringSelection(java.awt.datatransfer.StringSelection) Project(com.intellij.openapi.project.Project) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Editor(com.intellij.openapi.editor.Editor)

Example 43 with EditorColorsManager

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

the class PythonHighlightingTest method testDeclarations.

public void testDeclarations() {
    EditorColorsManager manager = EditorColorsManager.getInstance();
    EditorColorsScheme scheme = (EditorColorsScheme) manager.getGlobalScheme().clone();
    manager.addColorsScheme(scheme);
    EditorColorsManager.getInstance().setGlobalScheme(scheme);
    TextAttributesKey xKey = TextAttributesKey.find("PY.CLASS_DEFINITION");
    TextAttributes xAttributes = new TextAttributes(Color.blue, Color.black, Color.white, EffectType.BOXED, Font.BOLD);
    scheme.setAttributes(xKey, xAttributes);
    xKey = TextAttributesKey.find("PY.FUNC_DEFINITION");
    xAttributes = new TextAttributes(Color.red, Color.black, Color.white, EffectType.BOXED, Font.BOLD);
    scheme.setAttributes(xKey, xAttributes);
    xKey = TextAttributesKey.find("PY.PREDEFINED_DEFINITION");
    xAttributes = new TextAttributes(Color.green, Color.black, Color.white, EffectType.BOXED, Font.BOLD);
    scheme.setAttributes(xKey, xAttributes);
    doTest();
}
Also used : TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey)

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