Search in sources :

Example 36 with TextAttributesKey

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

the class RainbowColorsInSchemeState method apply.

public void apply(@Nullable EditorColorsScheme scheme) {
    if (scheme != null && scheme != myEditedScheme) {
        RainbowHighlighter.transferRainbowState(scheme, myEditedScheme);
        for (TextAttributesKey key : RainbowHighlighter.RAINBOW_COLOR_KEYS) {
            Color color = myEditedScheme.getAttributes(key).getForegroundColor();
            if (!color.equals(scheme.getAttributes(key).getForegroundColor())) {
                scheme.setAttributes(key, RainbowHighlighter.createRainbowAttribute(color));
            }
        }
        updateRainbowMarkup();
    }
}
Also used : TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey)

Example 37 with TextAttributesKey

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

the class SimpleEditorPreview method startBlinkingHighlights.

private List<HighlightData> startBlinkingHighlights(final EditorEx editor, final String attrKey, final SyntaxHighlighter highlighter, final boolean show, final Alarm alarm, final int count, final ColorSettingsPage page) {
    if (show && count <= 0)
        return Collections.emptyList();
    removeDecorations(editor);
    boolean found = false;
    List<HighlightData> highlights = new ArrayList<>();
    List<HighlightData> matchingHighlights = new ArrayList<>();
    for (HighlightData highlightData : myHighlightData) {
        boolean highlight = show && highlightData.getHighlightType().equals(attrKey);
        highlightData.addToCollection(highlights, highlight);
        if (highlight) {
            matchingHighlights.add(highlightData);
            found = true;
        }
    }
    if (!found && highlighter != null) {
        HighlighterIterator iterator = editor.getHighlighter().createIterator(0);
        do {
            IElementType tokenType = iterator.getTokenType();
            TextAttributesKey[] tokenHighlights = highlighter.getTokenHighlights(tokenType);
            for (final TextAttributesKey tokenHighlight : tokenHighlights) {
                String type = tokenHighlight.getExternalName();
                if (show && type != null && type.equals(attrKey)) {
                    HighlightData highlightData = new HighlightData(iterator.getStart(), iterator.getEnd(), BLINKING_HIGHLIGHTS_ATTRIBUTES);
                    highlights.add(highlightData);
                    matchingHighlights.add(highlightData);
                }
            }
            iterator.advance();
        } while (!iterator.atEnd());
    }
    final Map<TextAttributesKey, String> displayText = ColorSettingsUtil.keyToDisplayTextMap(page);
    // sort highlights to avoid overlappings
    Collections.sort(highlights, Comparator.comparingInt(HighlightData::getStartOffset));
    for (int i = highlights.size() - 1; i >= 0; i--) {
        HighlightData highlightData = highlights.get(i);
        int startOffset = highlightData.getStartOffset();
        HighlightData prevHighlightData = i == 0 ? null : highlights.get(i - 1);
        if (prevHighlightData != null && startOffset <= prevHighlightData.getEndOffset() && highlightData.getHighlightType().equals(prevHighlightData.getHighlightType())) {
            prevHighlightData.setEndOffset(highlightData.getEndOffset());
        } else {
            highlightData.addHighlToView(editor, myOptions.getSelectedScheme(), displayText);
        }
    }
    alarm.cancelAllRequests();
    alarm.addComponentRequest(() -> startBlinkingHighlights(editor, attrKey, highlighter, !show, alarm, count - 1, page), 400);
    return matchingHighlights;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) HighlightData(com.intellij.application.options.colors.highlighting.HighlightData) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator)

Example 38 with TextAttributesKey

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

the class SimpleEditorPreview method selectItem.

@Nullable
private static String selectItem(HighlighterIterator itr, SyntaxHighlighter highlighter) {
    IElementType tokenType = itr.getTokenType();
    if (tokenType == null)
        return null;
    TextAttributesKey[] highlights = highlighter.getTokenHighlights(tokenType);
    String s = null;
    for (int i = highlights.length - 1; i >= 0; i--) {
        if (highlights[i] != HighlighterColors.TEXT) {
            s = highlights[i].getExternalName();
            break;
        }
    }
    return s == null ? HighlighterColors.TEXT.getExternalName() : s;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) Nullable(org.jetbrains.annotations.Nullable)

Example 39 with TextAttributesKey

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

the class ApplicationInspectionProfileManager method registerProvidedSeverities.

// It should be public to be available from Upsource
public static void registerProvidedSeverities() {
    for (SeveritiesProvider provider : Extensions.getExtensions(SeveritiesProvider.EP_NAME)) {
        for (HighlightInfoType t : provider.getSeveritiesHighlightInfoTypes()) {
            HighlightSeverity highlightSeverity = t.getSeverity(null);
            SeverityRegistrar.registerStandard(t, highlightSeverity);
            TextAttributesKey attributesKey = t.getAttributesKey();
            Icon icon = t instanceof HighlightInfoType.Iconable ? ((HighlightInfoType.Iconable) t).getIcon() : null;
            HighlightDisplayLevel.registerSeverity(highlightSeverity, attributesKey, icon);
        }
    }
}
Also used : HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) SeveritiesProvider(com.intellij.codeInsight.daemon.impl.SeveritiesProvider) HighlightInfoType(com.intellij.codeInsight.daemon.impl.HighlightInfoType)

Example 40 with TextAttributesKey

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

the class EclipseColorSchemeImporter method setupMissingColors.

private static void setupMissingColors(@NotNull EditorColorsScheme scheme) {
    Color background = scheme.getDefaultBackground();
    String defaultSchemeName = ColorUtil.isDark(background) ? "Darcula" : EditorColorsScheme.DEFAULT_SCHEME_NAME;
    EditorColorsScheme baseScheme = DefaultColorSchemesManager.getInstance().getScheme(defaultSchemeName);
    assert baseScheme != null : "Can not find default scheme '" + defaultSchemeName + "'!";
    for (TextAttributesKey attributesKey : ATTRIBUTES_TO_COPY) {
        copyAttributes(baseScheme, scheme, attributesKey);
    }
    for (String keyName : EXTERNAL_ATTRIBUTES) {
        TextAttributesKey key = TextAttributesKey.createTextAttributesKey(keyName);
        copyAttributes(baseScheme, scheme, key);
    }
    Color lightForeground = ColorUtil.mix(background, scheme.getDefaultForeground(), 0.5);
    scheme.setColor(EditorColors.WHITESPACES_COLOR, lightForeground);
    scheme.setColor(EditorColors.INDENT_GUIDE_COLOR, lightForeground);
    scheme.setColor(EditorColors.SOFT_WRAP_SIGN_COLOR, lightForeground);
    TextAttributes matchedBrace = new TextAttributes();
    matchedBrace.setEffectType(EffectType.BOXED);
    matchedBrace.setEffectColor(lightForeground);
    scheme.setAttributes(CodeInsightColors.MATCHED_BRACE_ATTRIBUTES, matchedBrace);
    TextAttributes unmatchedBrace = matchedBrace.clone();
    unmatchedBrace.setEffectColor(ColorUtil.mix(background, Color.RED, 0.5));
}
Also used : TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey)

Aggregations

TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)49 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)28 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)12 NotNull (org.jetbrains.annotations.NotNull)9 IElementType (com.intellij.psi.tree.IElementType)8 HighlightInfoType (com.intellij.codeInsight.daemon.impl.HighlightInfoType)7 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)6 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)6 TextRange (com.intellij.openapi.util.TextRange)5 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)4 HighlightData (com.intellij.application.options.colors.highlighting.HighlightData)3 PresentationData (com.intellij.ide.projectView.PresentationData)3 Language (com.intellij.lang.Language)3 Lexer (com.intellij.lexer.Lexer)3 SyntaxHighlighter (com.intellij.openapi.fileTypes.SyntaxHighlighter)3 AttributesDescriptor (com.intellij.openapi.options.colors.AttributesDescriptor)3 Project (com.intellij.openapi.project.Project)3 Pair (com.intellij.openapi.util.Pair)3 PsiElement (com.intellij.psi.PsiElement)3 NamedScope (com.intellij.psi.search.scope.packageSet.NamedScope)3