Better localization for dsl style icon change
This commit is contained in:
@@ -10,22 +10,16 @@ import com.intellij.codeHighlighting.Pass
|
|||||||
import com.intellij.codeInsight.daemon.GutterIconNavigationHandler
|
import com.intellij.codeInsight.daemon.GutterIconNavigationHandler
|
||||||
import com.intellij.codeInsight.daemon.LineMarkerInfo
|
import com.intellij.codeInsight.daemon.LineMarkerInfo
|
||||||
import com.intellij.ide.DataManager
|
import com.intellij.ide.DataManager
|
||||||
import com.intellij.openapi.editor.colors.EditorColorsManager
|
|
||||||
import com.intellij.openapi.editor.markup.GutterIconRenderer
|
import com.intellij.openapi.editor.markup.GutterIconRenderer
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.ui.LayeredIcon
|
|
||||||
import com.intellij.util.Function
|
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.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||||
import org.jetbrains.kotlin.idea.KotlinIcons
|
|
||||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||||
import org.jetbrains.kotlin.idea.core.toDescriptor
|
import org.jetbrains.kotlin.idea.core.toDescriptor
|
||||||
import org.jetbrains.kotlin.idea.highlighter.dsl.DslHighlighterExtension
|
import org.jetbrains.kotlin.idea.highlighter.dsl.DslHighlighterExtension
|
||||||
import org.jetbrains.kotlin.idea.highlighter.dsl.isDslHighlightingMarker
|
import org.jetbrains.kotlin.idea.highlighter.dsl.isDslHighlightingMarker
|
||||||
import org.jetbrains.kotlin.psi.KtClass
|
import org.jetbrains.kotlin.psi.KtClass
|
||||||
import javax.swing.Icon
|
|
||||||
import javax.swing.JComponent
|
import javax.swing.JComponent
|
||||||
|
|
||||||
private val navHandler = GutterIconNavigationHandler<PsiElement> { event, element ->
|
private val navHandler = GutterIconNavigationHandler<PsiElement> { event, element ->
|
||||||
@@ -52,7 +46,7 @@ fun collectHighlightingColorsMarkers(
|
|||||||
LineMarkerInfo<PsiElement>(
|
LineMarkerInfo<PsiElement>(
|
||||||
anchor,
|
anchor,
|
||||||
anchor.textRange,
|
anchor.textRange,
|
||||||
createIcon(styleId),
|
createDslStyleIcon(styleId),
|
||||||
Pass.LINE_MARKERS,
|
Pass.LINE_MARKERS,
|
||||||
toolTipHandler, navHandler,
|
toolTipHandler, navHandler,
|
||||||
GutterIconRenderer.Alignment.RIGHT
|
GutterIconRenderer.Alignment.RIGHT
|
||||||
@@ -60,21 +54,6 @@ fun collectHighlightingColorsMarkers(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createIcon(styleId: Int): Icon {
|
|
||||||
val globalScheme = EditorColorsManager.getInstance().globalScheme
|
|
||||||
val markersColor = globalScheme.getAttributes(DslHighlighterExtension.styleById(styleId)).foregroundColor
|
|
||||||
val icon = LayeredIcon(2)
|
|
||||||
val defaultIcon = KotlinIcons.DSL_MARKER_ANNOTATION
|
|
||||||
icon.setIcon(defaultIcon, 0)
|
|
||||||
icon.setIcon(
|
|
||||||
ColorsIcon(defaultIcon.iconHeight / 2, markersColor).scale(JBUI.pixScale()),
|
|
||||||
1,
|
|
||||||
defaultIcon.iconHeight / 2,
|
|
||||||
defaultIcon.iconWidth / 2
|
|
||||||
)
|
|
||||||
return icon
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun KtClass.styleIdForMarkerAnnotation(): Int? {
|
private fun KtClass.styleIdForMarkerAnnotation(): Int? {
|
||||||
val classDescriptor = toDescriptor() as? ClassDescriptor ?: return null
|
val classDescriptor = toDescriptor() as? ClassDescriptor ?: return null
|
||||||
if (classDescriptor.kind != ClassKind.ANNOTATION_CLASS) return null
|
if (classDescriptor.kind != ClassKind.ANNOTATION_CLASS) return null
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2000-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.highlighter.markers
|
|
||||||
|
|
||||||
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.markup.GutterIconRenderer
|
|
||||||
import com.intellij.psi.PsiElement
|
|
||||||
import com.intellij.util.Function
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
|
||||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
|
||||||
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.JComponent
|
|
||||||
|
|
||||||
private val navHandler = GutterIconNavigationHandler<PsiElement> { event, element ->
|
|
||||||
val dataContext = (event.component as? JComponent)?.let { DataManager.getInstance().getDataContext(it) }
|
|
||||||
?: return@GutterIconNavigationHandler
|
|
||||||
val ktClass = element?.parent as? KtClass ?: return@GutterIconNavigationHandler
|
|
||||||
val styleId = ktClass.styleIdForMarkerAnnotation() ?: return@GutterIconNavigationHandler
|
|
||||||
ColorAndFontOptions.selectOrEditColor(dataContext, DslHighlighterExtension.styleOptionDisplayName(styleId), KotlinLanguage.NAME)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val toolTipHandler = Function<PsiElement, String> {
|
|
||||||
"Marker annotation for DSL"
|
|
||||||
}
|
|
||||||
|
|
||||||
fun collectHighlightingColorsMarkers(
|
|
||||||
ktClass: KtClass,
|
|
||||||
result: MutableCollection<LineMarkerInfo<*>>
|
|
||||||
) {
|
|
||||||
if (ktClass.styleIdForMarkerAnnotation() == null) return
|
|
||||||
|
|
||||||
val anchor = ktClass.nameIdentifier ?: return
|
|
||||||
|
|
||||||
result.add(
|
|
||||||
LineMarkerInfo<PsiElement>(
|
|
||||||
anchor,
|
|
||||||
anchor.textRange,
|
|
||||||
AllIcons.Gutter.Colors,
|
|
||||||
Pass.LINE_MARKERS,
|
|
||||||
toolTipHandler, navHandler,
|
|
||||||
GutterIconRenderer.Alignment.RIGHT
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2000-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.highlighter.markers
|
|
||||||
|
|
||||||
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.markup.GutterIconRenderer
|
|
||||||
import com.intellij.psi.PsiElement
|
|
||||||
import com.intellij.util.Function
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
|
||||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
|
||||||
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.JComponent
|
|
||||||
|
|
||||||
private val navHandler = GutterIconNavigationHandler<PsiElement> { event, element ->
|
|
||||||
val dataContext = (event.component as? JComponent)?.let { DataManager.getInstance().getDataContext(it) }
|
|
||||||
?: return@GutterIconNavigationHandler
|
|
||||||
val ktClass = element?.parent as? KtClass ?: return@GutterIconNavigationHandler
|
|
||||||
val styleId = ktClass.styleIdForMarkerAnnotation() ?: return@GutterIconNavigationHandler
|
|
||||||
ColorAndFontOptions.selectOrEditColor(dataContext, DslHighlighterExtension.styleOptionDisplayName(styleId), KotlinLanguage.NAME)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val toolTipHandler = Function<PsiElement, String> {
|
|
||||||
"Marker annotation for DSL"
|
|
||||||
}
|
|
||||||
|
|
||||||
fun collectHighlightingColorsMarkers(
|
|
||||||
ktClass: KtClass,
|
|
||||||
result: MutableCollection<LineMarkerInfo<*>>
|
|
||||||
) {
|
|
||||||
if (ktClass.styleIdForMarkerAnnotation() == null) return
|
|
||||||
|
|
||||||
val anchor = ktClass.nameIdentifier ?: return
|
|
||||||
|
|
||||||
result.add(
|
|
||||||
LineMarkerInfo<PsiElement>(
|
|
||||||
anchor,
|
|
||||||
anchor.textRange,
|
|
||||||
AllIcons.Gutter.Colors,
|
|
||||||
Pass.LINE_MARKERS,
|
|
||||||
toolTipHandler, navHandler,
|
|
||||||
GutterIconRenderer.Alignment.RIGHT
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2000-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.highlighter.markers
|
|
||||||
|
|
||||||
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.markup.GutterIconRenderer
|
|
||||||
import com.intellij.psi.PsiElement
|
|
||||||
import com.intellij.util.Function
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
|
||||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
|
||||||
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.JComponent
|
|
||||||
|
|
||||||
private val navHandler = GutterIconNavigationHandler<PsiElement> { event, element ->
|
|
||||||
val dataContext = (event.component as? JComponent)?.let { DataManager.getInstance().getDataContext(it) }
|
|
||||||
?: return@GutterIconNavigationHandler
|
|
||||||
val ktClass = element?.parent as? KtClass ?: return@GutterIconNavigationHandler
|
|
||||||
val styleId = ktClass.styleIdForMarkerAnnotation() ?: return@GutterIconNavigationHandler
|
|
||||||
ColorAndFontOptions.selectOrEditColor(dataContext, DslHighlighterExtension.styleOptionDisplayName(styleId), KotlinLanguage.NAME)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val toolTipHandler = Function<PsiElement, String> {
|
|
||||||
"Marker annotation for DSL"
|
|
||||||
}
|
|
||||||
|
|
||||||
fun collectHighlightingColorsMarkers(
|
|
||||||
ktClass: KtClass,
|
|
||||||
result: MutableCollection<LineMarkerInfo<*>>
|
|
||||||
) {
|
|
||||||
if (ktClass.styleIdForMarkerAnnotation() == null) return
|
|
||||||
|
|
||||||
val anchor = ktClass.nameIdentifier ?: return
|
|
||||||
|
|
||||||
result.add(
|
|
||||||
LineMarkerInfo<PsiElement>(
|
|
||||||
anchor,
|
|
||||||
anchor.textRange,
|
|
||||||
AllIcons.Gutter.Colors,
|
|
||||||
Pass.LINE_MARKERS,
|
|
||||||
toolTipHandler, navHandler,
|
|
||||||
GutterIconRenderer.Alignment.RIGHT
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.highlighter.markers
|
||||||
|
|
||||||
|
import com.intellij.openapi.editor.colors.EditorColorsManager
|
||||||
|
import com.intellij.ui.LayeredIcon
|
||||||
|
import com.intellij.util.ui.ColorsIcon
|
||||||
|
import com.intellij.util.ui.JBUI
|
||||||
|
import org.jetbrains.kotlin.idea.KotlinIcons
|
||||||
|
import org.jetbrains.kotlin.idea.highlighter.dsl.DslHighlighterExtension
|
||||||
|
import javax.swing.Icon
|
||||||
|
|
||||||
|
// BUNCH: 182
|
||||||
|
// BUNCH: as35
|
||||||
|
// BUNCH: as34
|
||||||
|
internal fun createDslStyleIcon(styleId: Int): Icon {
|
||||||
|
val globalScheme = EditorColorsManager.getInstance().globalScheme
|
||||||
|
val markersColor = globalScheme.getAttributes(DslHighlighterExtension.styleById(styleId)).foregroundColor
|
||||||
|
val icon = LayeredIcon(2)
|
||||||
|
val defaultIcon = KotlinIcons.DSL_MARKER_ANNOTATION
|
||||||
|
icon.setIcon(defaultIcon, 0)
|
||||||
|
icon.setIcon(
|
||||||
|
ColorsIcon(defaultIcon.iconHeight / 2, markersColor).scale(JBUI.pixScale()),
|
||||||
|
1,
|
||||||
|
defaultIcon.iconHeight / 2,
|
||||||
|
defaultIcon.iconWidth / 2
|
||||||
|
)
|
||||||
|
return icon
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.highlighter.markers
|
||||||
|
|
||||||
|
import com.intellij.icons.AllIcons
|
||||||
|
import javax.swing.Icon
|
||||||
|
|
||||||
|
// BUNCH: 182
|
||||||
|
// BUNCH: as35
|
||||||
|
// BUNCH: as34
|
||||||
|
internal fun createDslStyleIcon(styleId: Int): Icon {
|
||||||
|
return AllIcons.Gutter.Colors
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.highlighter.markers
|
||||||
|
|
||||||
|
import com.intellij.icons.AllIcons
|
||||||
|
import javax.swing.Icon
|
||||||
|
|
||||||
|
// BUNCH: 182
|
||||||
|
// BUNCH: as35
|
||||||
|
// BUNCH: as34
|
||||||
|
internal fun createDslStyleIcon(styleId: Int): Icon {
|
||||||
|
return AllIcons.Gutter.Colors
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.highlighter.markers
|
||||||
|
|
||||||
|
import com.intellij.icons.AllIcons
|
||||||
|
import javax.swing.Icon
|
||||||
|
|
||||||
|
// BUNCH: 182
|
||||||
|
// BUNCH: as35
|
||||||
|
// BUNCH: as34
|
||||||
|
internal fun createDslStyleIcon(styleId: Int): Icon {
|
||||||
|
return AllIcons.Gutter.Colors
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user