Search in sources :

Example 36 with EditorColorsScheme

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

the class ChameleonSyntaxHighlightingPass method collectHighlights.

private void collectHighlights(@NotNull PsiElement element, @NotNull List<HighlightInfo> inside, @NotNull List<HighlightInfo> outside, @NotNull ProperTextRange priorityRange) {
    EditorColorsScheme scheme = ObjectUtils.notNull(getColorsScheme(), EditorColorsManager.getInstance().getGlobalScheme());
    TextAttributes defaultAttrs = scheme.getAttributes(HighlighterColors.TEXT);
    Language language = ILazyParseableElementType.LANGUAGE_KEY.get(element.getNode());
    if (language == null)
        return;
    SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(language, myProject, myFile.getVirtualFile());
    for (PsiElement token : psiTraverser(element).traverse(TreeTraversal.LEAVES_DFS)) {
        TextRange tr = token.getTextRange();
        if (tr.isEmpty())
            continue;
        IElementType type = PsiUtilCore.getElementType(token);
        TextAttributesKey[] keys = syntaxHighlighter.getTokenHighlights(type);
        // force attribute colors to override host' ones
        TextAttributes attributes = null;
        for (TextAttributesKey key : keys) {
            TextAttributes attrs2 = scheme.getAttributes(key);
            if (attrs2 != null) {
                attributes = attributes == null ? attrs2 : TextAttributes.merge(attributes, attrs2);
            }
        }
        TextAttributes forcedAttributes;
        if (attributes == null || attributes.isEmpty() || attributes.equals(defaultAttrs)) {
            forcedAttributes = TextAttributes.ERASE_MARKER;
        } else {
            HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT).range(tr).textAttributes(TextAttributes.ERASE_MARKER).createUnconditionally();
            (priorityRange.contains(tr) ? inside : outside).add(info);
            forcedAttributes = new TextAttributes(attributes.getForegroundColor(), attributes.getBackgroundColor(), attributes.getEffectColor(), attributes.getEffectType(), attributes.getFontType());
        }
        HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT).range(tr).textAttributes(forcedAttributes).createUnconditionally();
        (priorityRange.contains(tr) ? inside : outside).add(info);
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Language(com.intellij.lang.Language) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) ProperTextRange(com.intellij.openapi.util.ProperTextRange) TextRange(com.intellij.openapi.util.TextRange) SyntaxHighlighter(com.intellij.openapi.fileTypes.SyntaxHighlighter) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) PsiElement(com.intellij.psi.PsiElement)

Example 37 with EditorColorsScheme

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

the class SeverityUtil method getSeverityBasedTextAttributes.

private static SeverityRegistrar.SeverityBasedTextAttributes getSeverityBasedTextAttributes(@NotNull SeverityRegistrar registrar, @NotNull HighlightInfoType type) {
    final EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
    final TextAttributes textAttributes = scheme.getAttributes(type.getAttributesKey());
    if (textAttributes != null) {
        return new SeverityRegistrar.SeverityBasedTextAttributes(textAttributes, (HighlightInfoType.HighlightInfoTypeImpl) type);
    }
    TextAttributes severity = registrar.getTextAttributesBySeverity(type.getSeverity(null));
    return new SeverityRegistrar.SeverityBasedTextAttributes(severity, (HighlightInfoType.HighlightInfoTypeImpl) type);
}
Also used : TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme)

Example 38 with EditorColorsScheme

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

the class ActionUsagePanel method configureByText.

private void configureByText(final String usageText, FileType fileType) {
    Document document = myEditor.getDocument();
    String text = StringUtil.convertLineSeparators(usageText);
    document.replaceString(0, document.getTextLength(), text);
    final EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
    myEditor.setHighlighter(EditorHighlighterFactory.getInstance().createEditorHighlighter(fileType, scheme, null));
    setupSpots(document);
}
Also used : EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme)

Example 39 with EditorColorsScheme

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

the class ModuleToDoNode method update.

@Override
public void update(PresentationData presentation) {
    if (DumbService.getInstance(getProject()).isDumb())
        return;
    String newName = getValue().getName();
    int nameEndOffset = newName.length();
    int todoItemCount = getTodoItemCount(getValue());
    int fileCount = getFileCount(getValue());
    newName = IdeBundle.message("node.todo.group", newName, todoItemCount, fileCount);
    myHighlightedRegions.clear();
    TextAttributes textAttributes = new TextAttributes();
    if (CopyPasteManager.getInstance().isCutElement(getValue())) {
        textAttributes.setForegroundColor(CopyPasteManager.CUT_COLOR);
    }
    myHighlightedRegions.add(new HighlightedRegion(0, nameEndOffset, textAttributes));
    EditorColorsScheme colorsScheme = UsageTreeColorsScheme.getInstance().getScheme();
    myHighlightedRegions.add(new HighlightedRegion(nameEndOffset, newName.length(), colorsScheme.getAttributes(UsageTreeColors.NUMBER_OF_USAGES)));
    presentation.setIcon(ModuleType.get(getValue()).getIcon());
    presentation.setPresentableText(newName);
}
Also used : TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) HighlightedRegion(com.intellij.ui.HighlightedRegion) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme)

Example 40 with EditorColorsScheme

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

the class TodoDirNode method updateImpl.

@Override
protected void updateImpl(PresentationData data) {
    super.updateImpl(data);
    int fileCount = getFileCount(getValue());
    if (getValue() == null || !getValue().isValid() || fileCount == 0) {
        setValue(null);
        return;
    }
    VirtualFile directory = getValue().getVirtualFile();
    boolean isProjectRoot = !ProjectRootManager.getInstance(getProject()).getFileIndex().isInContent(directory);
    String newName = isProjectRoot || getStructure().getIsFlattenPackages() ? getValue().getVirtualFile().getPresentableUrl() : getValue().getName();
    int nameEndOffset = newName.length();
    int todoItemCount = getTodoItemCount(getValue());
    newName = IdeBundle.message("node.todo.group", newName, todoItemCount, fileCount);
    myHighlightedRegions.clear();
    TextAttributes textAttributes = new TextAttributes();
    Color newColor = FileStatusManager.getInstance(getProject()).getStatus(getValue().getVirtualFile()).getColor();
    if (CopyPasteManager.getInstance().isCutElement(getValue())) {
        newColor = CopyPasteManager.CUT_COLOR;
    }
    textAttributes.setForegroundColor(newColor);
    myHighlightedRegions.add(new HighlightedRegion(0, nameEndOffset, textAttributes));
    EditorColorsScheme colorsScheme = UsageTreeColorsScheme.getInstance().getScheme();
    myHighlightedRegions.add(new HighlightedRegion(nameEndOffset, newName.length(), colorsScheme.getAttributes(UsageTreeColors.NUMBER_OF_USAGES)));
    data.setPresentableText(newName);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) HighlightedRegion(com.intellij.ui.HighlightedRegion) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme)

Aggregations

EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)103 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)31 NotNull (org.jetbrains.annotations.NotNull)28 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)17 Nullable (org.jetbrains.annotations.Nullable)15 Document (com.intellij.openapi.editor.Document)14 Project (com.intellij.openapi.project.Project)14 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)12 Editor (com.intellij.openapi.editor.Editor)11 DocumentMarkupModel (com.intellij.openapi.editor.impl.DocumentMarkupModel)10 EditorEx (com.intellij.openapi.editor.ex.EditorEx)8 TextRange (com.intellij.openapi.util.TextRange)8 EditorHighlighter (com.intellij.openapi.editor.highlighter.EditorHighlighter)7 PsiFile (com.intellij.psi.PsiFile)7 List (java.util.List)7 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)6 ApplicationManager (com.intellij.openapi.application.ApplicationManager)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 java.awt (java.awt)6 java.util (java.util)6