From f1f2d5b4d3560fbb5ab716c8d6709f2ef26f79b4 Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Mon, 14 Jan 2019 18:48:17 +0100 Subject: [PATCH] Change dsl marker gutter icon to use different colors #KT-27769 Fixed --- .../dsl/DslHighlighterExtension.kt | 6 ++++-- .../markers/DslHighlightingMarker.kt | 19 ++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/dsl/DslHighlighterExtension.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/dsl/DslHighlighterExtension.kt index 85203e7fcbc..c19a23869d7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/dsl/DslHighlighterExtension.kt +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/dsl/DslHighlighterExtension.kt @@ -44,7 +44,7 @@ class DslHighlighterExtension : HighlighterExtension() { fun externalKeyName(index: Int) = "KOTLIN_DSL_STYLE$index" val descriptionsToStyles = (1..numStyles).associate { index -> - "Dsl//${styleOptionDisplayName(index)}" to styles[index - 1] + "Dsl//${styleOptionDisplayName(index)}" to styleById(index) } fun styleOptionDisplayName(index: Int) = "Style$index" @@ -60,8 +60,10 @@ class DslHighlighterExtension : HighlighterExtension() { }?.annotationClass ?: return null val styleId = styleIdByMarkerAnnotation(markerAnnotation) ?: return null - return styles[styleId - 1] + return styleById(styleId) } + + fun styleById(styleId: Int): TextAttributesKey = styles[styleId - 1] } } diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/DslHighlightingMarker.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/DslHighlightingMarker.kt index a3276ea1a32..c4317231fe9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/DslHighlightingMarker.kt +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/DslHighlightingMarker.kt @@ -9,11 +9,13 @@ import com.intellij.application.options.colors.ColorAndFontOptions import com.intellij.codeHighlighting.Pass import com.intellij.codeInsight.daemon.GutterIconNavigationHandler import com.intellij.codeInsight.daemon.LineMarkerInfo -import com.intellij.icons.AllIcons import com.intellij.ide.DataManager +import com.intellij.openapi.editor.colors.EditorColorsManager import com.intellij.openapi.editor.markup.GutterIconRenderer import com.intellij.psi.PsiElement import com.intellij.util.Function +import com.intellij.util.ui.ColorsIcon +import com.intellij.util.ui.JBUI import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.idea.KotlinLanguage @@ -21,6 +23,7 @@ import org.jetbrains.kotlin.idea.core.toDescriptor import org.jetbrains.kotlin.idea.highlighter.dsl.DslHighlighterExtension import org.jetbrains.kotlin.idea.highlighter.dsl.isDslHighlightingMarker import org.jetbrains.kotlin.psi.KtClass +import javax.swing.Icon import javax.swing.JComponent private val navHandler = GutterIconNavigationHandler { event, element -> @@ -39,7 +42,7 @@ fun collectHighlightingColorsMarkers( ktClass: KtClass, result: MutableCollection> ) { - if (ktClass.styleIdForMarkerAnnotation() == null) return + val styleId = ktClass.styleIdForMarkerAnnotation() ?: return val anchor = ktClass.nameIdentifier ?: return @@ -47,7 +50,7 @@ fun collectHighlightingColorsMarkers( LineMarkerInfo( anchor, anchor.textRange, - AllIcons.Gutter.Colors, + createIcon(styleId), Pass.LINE_MARKERS, toolTipHandler, navHandler, GutterIconRenderer.Alignment.RIGHT @@ -55,10 +58,16 @@ fun collectHighlightingColorsMarkers( ) } +private fun createIcon(styleId: Int): Icon { + val globalScheme = EditorColorsManager.getInstance().globalScheme + val markersColor = globalScheme.getAttributes(DslHighlighterExtension.styleById(styleId)).foregroundColor + val defaultColor = globalScheme.defaultForeground + return JBUI.scale(ColorsIcon(12, markersColor, defaultColor, defaultColor, markersColor)) +} + private fun KtClass.styleIdForMarkerAnnotation(): Int? { val classDescriptor = toDescriptor() as? ClassDescriptor ?: return null if (classDescriptor.kind != ClassKind.ANNOTATION_CLASS) return null if (!classDescriptor.isDslHighlightingMarker()) return null return DslHighlighterExtension.styleIdByMarkerAnnotation(classDescriptor) -} - +} \ No newline at end of file