Skip to content

Commit

Permalink
Use IconLayerProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
kikugie committed Jul 30, 2024
1 parent 28b38c1 commit 56dcb81
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
20 changes: 9 additions & 11 deletions src/main/kotlin/platform/mixin/framework/MixinIconProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,17 @@ package com.demonwav.mcdev.platform.mixin.framework
import com.demonwav.mcdev.MinecraftSettings
import com.demonwav.mcdev.asset.MixinAssets
import com.demonwav.mcdev.platform.mixin.util.isMixin
import com.demonwav.mcdev.platform.mixin.util.mixinAnnotation
import com.intellij.ide.IconProvider
import com.intellij.ide.IconLayerProvider
import com.intellij.openapi.util.Iconable
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
import com.intellij.ui.LayeredIcon
import javax.swing.Icon

class MixinIconProvider : IconProvider() {
override fun getIcon(element: PsiElement, flags: Int) : Icon? =
if (MinecraftSettings.instance.mixinClassIcon && element is PsiClass && element.isMixin)
LayeredIcon.create(element.withoutMixin().getIcon(flags), MixinAssets.MIXIN_MARK)
else null
class MixinIconProvider : IconLayerProvider {
override fun getLayerIcon(element: Iconable, isLocked: Boolean): Icon? =
MixinAssets.MIXIN_MARK.takeIf {
MinecraftSettings.instance.mixinClassIcon && element is PsiClass && element.isMixin
}

private fun PsiClass.withoutMixin(): PsiClass =
(copy() as PsiClass).apply { mixinAnnotation?.delete() }
override fun getLayerDescription(): String =
"Mixin class"
}
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@

<library.presentationProvider implementation="com.demonwav.mcdev.platform.mixin.framework.MixinPresentationProvider" />

<iconProvider implementation="com.demonwav.mcdev.platform.mixin.framework.MixinIconProvider" />
<iconLayerProvider implementation="com.demonwav.mcdev.platform.mixin.framework.MixinIconProvider" />

<!--region MixinExtras Expression Language-->
<fileType name="MixinExtras Expression File"
Expand Down

0 comments on commit 56dcb81

Please sign in to comment.