From d0c818f94513424205abeae6692b19848f25df4c Mon Sep 17 00:00:00 2001 From: Nikolay Rykunov Date: Tue, 10 Oct 2023 20:15:40 +0200 Subject: [PATCH 1/3] Support new 233 API for IntelliJ theming * Extract implementation for 232 and 233 in separate modules * Don't use reflection for introduced API --- .../theme/IntUiThemeDescriptorReader.kt | 11 ++-- .../theme/IntelliJThemeGeneratorPlugin.kt | 2 +- .../jetbrains/jewel/IntelliJThemeIconData.kt | 8 +-- .../org/jetbrains/jewel/InternalJewelApi.kt | 1 + .../jewel/themes/PaletteMapperFactory.kt | 19 ++++--- .../themes/StandalonePaletteMapperFactory.kt | 4 +- .../jetbrains/jewel/bridge/BridgeIconData.kt | 13 +++-- .../bridge/BridgePaletteMapperFactory.kt | 0 .../jewel/bridge/IconsPathPatching.kt | 29 ++++++++++ .../jewel/bridge/UiThemeExtensions.kt | 6 ++- .../jetbrains/jewel/bridge/BridgeIconData.kt | 53 +++++++++++++++++++ .../bridge/BridgePaletteMapperFactory.kt | 30 +++++++++++ .../jewel/bridge/IconsPathPatching.kt | 29 ++++++++++ .../jewel/bridge/UiThemeExtensions.kt | 8 +++ .../jewel/bridge/BridgeIconMapper.kt | 20 ++----- 15 files changed, 195 insertions(+), 38 deletions(-) rename ide-laf-bridge/{ => ide-laf-bridge-232}/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeIconData.kt (81%) rename ide-laf-bridge/{ => ide-laf-bridge-232}/src/main/kotlin/org/jetbrains/jewel/bridge/BridgePaletteMapperFactory.kt (100%) create mode 100644 ide-laf-bridge/ide-laf-bridge-232/src/main/kotlin/org/jetbrains/jewel/bridge/IconsPathPatching.kt rename ide-laf-bridge/{ => ide-laf-bridge-232}/src/main/kotlin/org/jetbrains/jewel/bridge/UiThemeExtensions.kt (91%) create mode 100644 ide-laf-bridge/ide-laf-bridge-233/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeIconData.kt create mode 100644 ide-laf-bridge/ide-laf-bridge-233/src/main/kotlin/org/jetbrains/jewel/bridge/BridgePaletteMapperFactory.kt create mode 100644 ide-laf-bridge/ide-laf-bridge-233/src/main/kotlin/org/jetbrains/jewel/bridge/IconsPathPatching.kt create mode 100644 ide-laf-bridge/ide-laf-bridge-233/src/main/kotlin/org/jetbrains/jewel/bridge/UiThemeExtensions.kt diff --git a/buildSrc/src/main/kotlin/org/jetbrains/jewel/buildlogic/theme/IntUiThemeDescriptorReader.kt b/buildSrc/src/main/kotlin/org/jetbrains/jewel/buildlogic/theme/IntUiThemeDescriptorReader.kt index 42447ce95..829fe4634 100644 --- a/buildSrc/src/main/kotlin/org/jetbrains/jewel/buildlogic/theme/IntUiThemeDescriptorReader.kt +++ b/buildSrc/src/main/kotlin/org/jetbrains/jewel/buildlogic/theme/IntUiThemeDescriptorReader.kt @@ -175,7 +175,12 @@ internal object IntUiThemeDescriptorReader { } addProperty(createOverrideStringMapProperty("iconOverrides", iconOverrides)) - addProperty(createOverrideStringMapProperty("selectionColorPalette", theme.iconColorsOnSelection)) + addProperty( + createOverrideStringMapProperty( + "selectionColorPalette", + theme.iconColorsOnSelection + ) + ) }.build()) addProperty( @@ -185,11 +190,11 @@ internal object IntUiThemeDescriptorReader { ) } - private fun createOverrideStringMapProperty(name: String, values: Map) = + private inline fun createOverrideStringMapProperty(name: String, values: Map) = PropertySpec.builder( name = name, type = Map::class.asTypeName() - .parameterizedBy(String::class.asTypeName(), String::class.asTypeName()), + .parameterizedBy(K::class.asTypeName(), V::class.asTypeName()), KModifier.OVERRIDE ) .initializer( diff --git a/buildSrc/src/main/kotlin/org/jetbrains/jewel/buildlogic/theme/IntelliJThemeGeneratorPlugin.kt b/buildSrc/src/main/kotlin/org/jetbrains/jewel/buildlogic/theme/IntelliJThemeGeneratorPlugin.kt index 0512eeb50..a77427a20 100644 --- a/buildSrc/src/main/kotlin/org/jetbrains/jewel/buildlogic/theme/IntelliJThemeGeneratorPlugin.kt +++ b/buildSrc/src/main/kotlin/org/jetbrains/jewel/buildlogic/theme/IntelliJThemeGeneratorPlugin.kt @@ -122,5 +122,5 @@ data class IntellijThemeDescriptor( val colors: Map = emptyMap(), val ui: Map = emptyMap(), val icons: Map = emptyMap(), - val iconColorsOnSelection: Map = emptyMap(), + val iconColorsOnSelection: Map = emptyMap(), ) diff --git a/core/src/main/kotlin/org/jetbrains/jewel/IntelliJThemeIconData.kt b/core/src/main/kotlin/org/jetbrains/jewel/IntelliJThemeIconData.kt index 0531c1f61..18a42d88b 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/IntelliJThemeIconData.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/IntelliJThemeIconData.kt @@ -7,13 +7,13 @@ import androidx.compose.ui.graphics.Color interface IntelliJThemeIconData { val iconOverrides: Map - val colorPalette: Map - val selectionColorPalette: Map + val colorPalette: Map + val selectionColorPalette: Map fun selectionColorMapping() = selectionColorPalette.mapNotNull { (key, value) -> val keyColor = key.toColorOrNull() ?: return@mapNotNull null - val valueColor = value.toColorOrNull() ?: return@mapNotNull null + val valueColor = Color(value) keyColor to valueColor }.toMap() } @@ -41,7 +41,7 @@ object EmptyThemeIconData : IntelliJThemeIconData { override val colorPalette: Map = emptyMap() - override val selectionColorPalette: Map = emptyMap() + override val selectionColorPalette: Map = emptyMap() override fun toString() = "EmptyThemeIconData(iconOverrides=[], colorPalette=[], selectionColorPalette=[])" diff --git a/core/src/main/kotlin/org/jetbrains/jewel/InternalJewelApi.kt b/core/src/main/kotlin/org/jetbrains/jewel/InternalJewelApi.kt index a5e62faf7..2c91a33a1 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/InternalJewelApi.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/InternalJewelApi.kt @@ -8,5 +8,6 @@ package org.jetbrains.jewel AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR, + AnnotationTarget.PROPERTY, ) annotation class InternalJewelApi diff --git a/core/src/main/kotlin/org/jetbrains/jewel/themes/PaletteMapperFactory.kt b/core/src/main/kotlin/org/jetbrains/jewel/themes/PaletteMapperFactory.kt index 643477153..915a52a72 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/themes/PaletteMapperFactory.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/themes/PaletteMapperFactory.kt @@ -6,8 +6,8 @@ import org.jetbrains.jewel.PaletteMapper abstract class PaletteMapperFactory { protected fun createInternal( - iconColorPalette: Map, - keyPalette: Map, + iconColorPalette: Map, + keyPalette: Map, themeColors: Map, isDark: Boolean, ): PaletteMapper { @@ -20,15 +20,20 @@ abstract class PaletteMapperFactory { val map = selectMap(key, checkBoxes, trees, ui) ?: continue // If the value is one of the named colors in the theme, use that named color's value - val namedColor = themeColors.get(value) as? String - val resolvedValue = namedColor ?: value + val namedColor = themeColors[value]?.let { rawColor -> + when (rawColor) { + is Int -> Color(rawColor) + is String -> rawColor.toColorOrNull() + else -> null + } + } // If either the key or the resolved value aren't valid colors, ignore the entry val keyAsColor = resolveKeyColor(key, keyPalette, isDark) ?: continue - val resolvedValueAsColor = resolvedValue.toColorOrNull() ?: continue + val resolvedColor = namedColor ?: value?.toColorOrNull() ?: continue // Save the new entry (oldColor -> newColor) in the map - map[keyAsColor] = resolvedValueAsColor + map[keyAsColor] = resolvedColor } return PaletteMapper( @@ -39,7 +44,7 @@ abstract class PaletteMapperFactory { } // See com.intellij.ide.ui.UITheme.toColorString - private fun resolveKeyColor(key: String, keyPalette: Map, isDark: Boolean): Color? { + private fun resolveKeyColor(key: String, keyPalette: Map, isDark: Boolean): Color? { val darkKey = "$key.Dark" val resolvedKey = if (isDark && keyPalette.containsKey(darkKey)) darkKey else key return keyPalette[resolvedKey]?.toColorOrNull() diff --git a/core/src/main/kotlin/org/jetbrains/jewel/themes/StandalonePaletteMapperFactory.kt b/core/src/main/kotlin/org/jetbrains/jewel/themes/StandalonePaletteMapperFactory.kt index bd49dc09d..2c0687e91 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/themes/StandalonePaletteMapperFactory.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/themes/StandalonePaletteMapperFactory.kt @@ -71,9 +71,9 @@ object StandalonePaletteMapperFactory : PaletteMapperFactory() { isDark = isDark, ) - private fun Map.asColorStringsMap() = + private fun Map.asColorStringsMap(): Map = mapValues { (_, color) -> - "#${color.toArgb().toString(16).padStart(6, '0')}" + color.toArgb() } override fun logInfo(message: String) { diff --git a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeIconData.kt b/ide-laf-bridge/ide-laf-bridge-232/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeIconData.kt similarity index 81% rename from ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeIconData.kt rename to ide-laf-bridge/ide-laf-bridge-232/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeIconData.kt index 3c69af4a1..c59f54492 100644 --- a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeIconData.kt +++ b/ide-laf-bridge/ide-laf-bridge-232/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeIconData.kt @@ -1,14 +1,18 @@ package org.jetbrains.jewel.bridge import androidx.compose.runtime.Immutable +import androidx.compose.ui.graphics.Color import com.intellij.ide.ui.UITheme +import com.intellij.ui.ColorUtil import org.jetbrains.jewel.IntelliJThemeIconData +import org.jetbrains.jewel.InternalJewelApi @Immutable -internal class BridgeIconData( +@InternalJewelApi +class BridgeIconData( override val iconOverrides: Map, override val colorPalette: Map, - override val selectionColorPalette: Map, + override val selectionColorPalette: Map, ) : IntelliJThemeIconData { override fun equals(other: Any?): Boolean { @@ -37,10 +41,13 @@ internal class BridgeIconData( companion object { + @OptIn(InternalJewelApi::class) fun readFromLaF(): BridgeIconData { val uiTheme = currentUiThemeOrNull() val iconMap = uiTheme?.icons.orEmpty() - val selectedIconColorPalette = uiTheme?.selectedIconColorPalette.orEmpty() + val selectedIconColorPalette = uiTheme?.selectedIconColorPalette.orEmpty().mapValues { + ColorUtil.fromHex(it.value).rgb + } val colorPalette = UITheme.getColorPalette() return BridgeIconData(iconMap, colorPalette, selectedIconColorPalette) diff --git a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgePaletteMapperFactory.kt b/ide-laf-bridge/ide-laf-bridge-232/src/main/kotlin/org/jetbrains/jewel/bridge/BridgePaletteMapperFactory.kt similarity index 100% rename from ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgePaletteMapperFactory.kt rename to ide-laf-bridge/ide-laf-bridge-232/src/main/kotlin/org/jetbrains/jewel/bridge/BridgePaletteMapperFactory.kt diff --git a/ide-laf-bridge/ide-laf-bridge-232/src/main/kotlin/org/jetbrains/jewel/bridge/IconsPathPatching.kt b/ide-laf-bridge/ide-laf-bridge-232/src/main/kotlin/org/jetbrains/jewel/bridge/IconsPathPatching.kt new file mode 100644 index 000000000..65b1d9c83 --- /dev/null +++ b/ide-laf-bridge/ide-laf-bridge-232/src/main/kotlin/org/jetbrains/jewel/bridge/IconsPathPatching.kt @@ -0,0 +1,29 @@ +package org.jetbrains.jewel.bridge + +import com.intellij.util.ui.DirProvider +import org.jetbrains.jewel.InternalJewelApi + +@InternalJewelApi +fun getPatchedIconPath( + dirProvider: DirProvider, + originalPath: String, + classLoaders: List +): String? { + val clazz = Class.forName("com.intellij.ui.icons.CachedImageIconKt") + val patchIconPath = clazz.getMethod("patchIconPath", String::class.java, ClassLoader::class.java) + patchIconPath.isAccessible = true + + // For all provided classloaders, we try to get the patched path, both using + // the original path, and an "abridged" path that has gotten the icon path prefix + // removed (the classloader is set up differently in prod IDEs and when running + // from Gradle, and the icon could be in either place depending on the environment) + val fallbackPath = originalPath.removePrefix(dirProvider.dir()) + val patchedPath = classLoaders.firstNotNullOfOrNull { classLoader -> + val patchedPathAndClassLoader = + patchIconPath.invoke(null, originalPath.removePrefix("/"), classLoader) + ?: patchIconPath.invoke(null, fallbackPath, classLoader) + patchedPathAndClassLoader as? Pair<*, *> + }?.first as? String + + return patchedPath +} diff --git a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/UiThemeExtensions.kt b/ide-laf-bridge/ide-laf-bridge-232/src/main/kotlin/org/jetbrains/jewel/bridge/UiThemeExtensions.kt similarity index 91% rename from ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/UiThemeExtensions.kt rename to ide-laf-bridge/ide-laf-bridge-232/src/main/kotlin/org/jetbrains/jewel/bridge/UiThemeExtensions.kt index 61c0f4dc2..cee7a675b 100644 --- a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/UiThemeExtensions.kt +++ b/ide-laf-bridge/ide-laf-bridge-232/src/main/kotlin/org/jetbrains/jewel/bridge/UiThemeExtensions.kt @@ -4,6 +4,7 @@ import com.intellij.ide.ui.LafManager import com.intellij.ide.ui.UITheme import com.intellij.ide.ui.laf.UIThemeBasedLookAndFeelInfo import com.intellij.openapi.diagnostic.Logger +import org.jetbrains.jewel.InternalJewelApi import java.lang.reflect.Field private val logger = Logger.getInstance("UiThemeExtensions") @@ -11,11 +12,14 @@ private val logger = Logger.getInstance("UiThemeExtensions") private val classUITheme get() = UITheme::class.java +@Suppress("UnstableApiUsage") +@InternalJewelApi internal fun currentUiThemeOrNull() = (LafManager.getInstance().currentLookAndFeel as? UIThemeBasedLookAndFeelInfo)?.theme // TODO #116 replace with public API access once it's made available (IJP 233?) -internal val UITheme.icons: Map +@InternalJewelApi +val UITheme.icons: Map get() = readMapField(classUITheme.getDeclaredField("icons")) .filterKeys { it != "ColorPalette" } diff --git a/ide-laf-bridge/ide-laf-bridge-233/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeIconData.kt b/ide-laf-bridge/ide-laf-bridge-233/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeIconData.kt new file mode 100644 index 000000000..0078240f5 --- /dev/null +++ b/ide-laf-bridge/ide-laf-bridge-233/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeIconData.kt @@ -0,0 +1,53 @@ +package org.jetbrains.jewel.bridge + +import androidx.compose.runtime.Immutable +import com.intellij.ide.ui.UITheme +import org.jetbrains.jewel.IntelliJThemeIconData +import org.jetbrains.jewel.InternalJewelApi + +@Immutable +@InternalJewelApi +class BridgeIconData( + override val iconOverrides: Map, + override val colorPalette: Map, + override val selectionColorPalette: Map, +) : IntelliJThemeIconData { + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as BridgeIconData + + if (iconOverrides != other.iconOverrides) return false + if (colorPalette != other.colorPalette) return false + if (selectionColorPalette != other.selectionColorPalette) return false + + return true + } + + override fun hashCode(): Int { + var result = iconOverrides.hashCode() + result = 31 * result + colorPalette.hashCode() + result = 31 * result + selectionColorPalette.hashCode() + return result + } + + override fun toString(): String = + "BridgeIconData(iconOverrides=$iconOverrides, colorPalette=$colorPalette, " + + "selectionColorPalette=$selectionColorPalette)" + + companion object { + + @Suppress("UnstableApiUsage") + fun readFromLaF(): BridgeIconData { + val uiTheme = currentUiThemeOrNull() + val bean = uiTheme?.describe() + val iconMap = bean?.icons.orEmpty() + val selectedIconColorPalette = bean?.iconColorsOnSelection.orEmpty() + + val colorPalette = UITheme.getColorPalette() + return BridgeIconData(iconMap, colorPalette, selectedIconColorPalette) + } + } +} diff --git a/ide-laf-bridge/ide-laf-bridge-233/src/main/kotlin/org/jetbrains/jewel/bridge/BridgePaletteMapperFactory.kt b/ide-laf-bridge/ide-laf-bridge-233/src/main/kotlin/org/jetbrains/jewel/bridge/BridgePaletteMapperFactory.kt new file mode 100644 index 000000000..c296ac625 --- /dev/null +++ b/ide-laf-bridge/ide-laf-bridge-233/src/main/kotlin/org/jetbrains/jewel/bridge/BridgePaletteMapperFactory.kt @@ -0,0 +1,30 @@ +package org.jetbrains.jewel.bridge + +import com.intellij.ide.ui.UITheme +import com.intellij.openapi.diagnostic.thisLogger +import org.jetbrains.jewel.PaletteMapper +import org.jetbrains.jewel.themes.PaletteMapperFactory + +object BridgePaletteMapperFactory : PaletteMapperFactory() { + + private val logger = thisLogger() + + @Suppress("UnstableApiUsage") + fun create(isDark: Boolean): PaletteMapper { + // If we can't read the current theme, no mapping is possible + val uiTheme = currentUiThemeOrNull() ?: return PaletteMapper.Empty + logger.info("Parsing theme info from theme ${uiTheme.name} (id: ${uiTheme.id}, isDark: ${uiTheme.isDark})") + + val bean = uiTheme.describe() + + val iconColorPalette = bean.colorPalette + val keyPalette = UITheme.getColorPalette() + val themeColors = bean.colors + + return createInternal(iconColorPalette, keyPalette, themeColors, isDark) + } + + override fun logInfo(message: String) { + logger.info(message) + } +} diff --git a/ide-laf-bridge/ide-laf-bridge-233/src/main/kotlin/org/jetbrains/jewel/bridge/IconsPathPatching.kt b/ide-laf-bridge/ide-laf-bridge-233/src/main/kotlin/org/jetbrains/jewel/bridge/IconsPathPatching.kt new file mode 100644 index 000000000..03c9c922e --- /dev/null +++ b/ide-laf-bridge/ide-laf-bridge-233/src/main/kotlin/org/jetbrains/jewel/bridge/IconsPathPatching.kt @@ -0,0 +1,29 @@ +package org.jetbrains.jewel.bridge + +import com.intellij.ui.icons.patchIconPath +import com.intellij.util.ui.DirProvider +import org.jetbrains.jewel.InternalJewelApi + +@InternalJewelApi +@Suppress("UnstableApiUsage") +fun getPatchedIconPath( + dirProvider: DirProvider, + originalPath: String, + classLoaders: List +): String? { + // For all provided classloaders, we try to get the patched path, both using + // the original path, and an "abridged" path that has gotten the icon path prefix + // removed (the classloader is set up differently in prod IDEs and when running + // from Gradle, and the icon could be in either place depending on the environment) + val fallbackPath = originalPath.removePrefix(dirProvider.dir()) + + for (classLoader in classLoaders) { + val patchedPath = patchIconPath(originalPath.removePrefix("/"), classLoader)?.first + ?: patchIconPath(fallbackPath, classLoader)?.first + + if (patchedPath != null) { + return patchedPath + } + } + return null +} diff --git a/ide-laf-bridge/ide-laf-bridge-233/src/main/kotlin/org/jetbrains/jewel/bridge/UiThemeExtensions.kt b/ide-laf-bridge/ide-laf-bridge-233/src/main/kotlin/org/jetbrains/jewel/bridge/UiThemeExtensions.kt new file mode 100644 index 000000000..81a6cd6da --- /dev/null +++ b/ide-laf-bridge/ide-laf-bridge-233/src/main/kotlin/org/jetbrains/jewel/bridge/UiThemeExtensions.kt @@ -0,0 +1,8 @@ +package org.jetbrains.jewel.bridge + +import com.intellij.ide.ui.LafManager +import com.intellij.ide.ui.laf.UIThemeLookAndFeelInfo + +@Suppress("UnstableApiUsage") +internal fun currentUiThemeOrNull(): UIThemeLookAndFeelInfo? = + LafManager.getInstance().currentUIThemeLookAndFeel?.takeIf { it.isInitialized } diff --git a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeIconMapper.kt b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeIconMapper.kt index 9c85bef76..8201a9a1c 100644 --- a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeIconMapper.kt +++ b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeIconMapper.kt @@ -5,6 +5,7 @@ import com.intellij.openapi.diagnostic.thisLogger import com.intellij.util.ui.DirProvider import org.jetbrains.jewel.ClassLoaderProvider import org.jetbrains.jewel.IntelliJThemeIconData +import org.jetbrains.jewel.InternalJewelApi internal object BridgeIconMapper : IconMapper { @@ -12,6 +13,7 @@ internal object BridgeIconMapper : IconMapper { private val dirProvider = DirProvider() + @OptIn(InternalJewelApi::class) override fun mapPath( originalPath: String, iconData: IntelliJThemeIconData, @@ -26,23 +28,7 @@ internal object BridgeIconMapper : IconMapper { return originalPath } - // TODO #116 replace with public API access once it's made available (IJP 233?) - val clazz = Class.forName("com.intellij.ui.icons.CachedImageIconKt") - val patchIconPath = clazz.getMethod("patchIconPath", String::class.java, ClassLoader::class.java) - patchIconPath.isAccessible = true - - // For all provided classloaders, we try to get the patched path, both using - // the original path, and an "abridged" path that has gotten the icon path prefix - // removed (the classloader is set up differently in prod IDEs and when running - // from Gradle, and the icon could be in either place depending on the environment) - val fallbackPath = originalPath.removePrefix(dirProvider.dir()) - val patchedPath = classLoaders.firstNotNullOfOrNull { classLoader -> - val patchedPathAndClassLoader = - patchIconPath.invoke(null, originalPath.removePrefix("/"), classLoader) - ?: patchIconPath.invoke(null, fallbackPath, classLoader) - patchedPathAndClassLoader as? Pair<*, *> - }?.first as? String - + val patchedPath = getPatchedIconPath(dirProvider, originalPath, classLoaders) val path = if (patchedPath != null) { logger.info("Found icon mapping: '$originalPath' -> '$patchedPath'") patchedPath From 49bc9e94a7846d0603868bead044014135a8cc91 Mon Sep 17 00:00:00 2001 From: Nikolay Rykunov Date: Wed, 11 Oct 2023 14:51:28 +0200 Subject: [PATCH 2/3] Enable CI for IJ 233 --- .github/workflows/build.yml | 4 ++-- .github/workflows/publish.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ad2e981e8..2289703bc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: matrix: supported-ij-version: - 232 -# - 233 + - 233 steps: - uses: actions/checkout@v3 @@ -35,7 +35,7 @@ jobs: matrix: supported-ij-version: - 232 -# - 233 + - 233 steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 047cac7f4..988c8359a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -33,7 +33,7 @@ jobs: matrix: supported-ij-version: - 232 - # - 233 + - 233 steps: - uses: actions/checkout@v3 From 33f7067326dc4f6a1666bd226e9b8436f82ec207 Mon Sep 17 00:00:00 2001 From: Nikolay Rykunov Date: Wed, 11 Oct 2023 15:20:22 +0200 Subject: [PATCH 3/3] Fix codestyle --- .../main/kotlin/org/jetbrains/jewel/bridge/BridgeIconData.kt | 1 - .../main/kotlin/org/jetbrains/jewel/bridge/IconsPathPatching.kt | 2 +- .../main/kotlin/org/jetbrains/jewel/bridge/IconsPathPatching.kt | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/ide-laf-bridge/ide-laf-bridge-232/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeIconData.kt b/ide-laf-bridge/ide-laf-bridge-232/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeIconData.kt index c59f54492..ea6ff34ee 100644 --- a/ide-laf-bridge/ide-laf-bridge-232/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeIconData.kt +++ b/ide-laf-bridge/ide-laf-bridge-232/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeIconData.kt @@ -1,7 +1,6 @@ package org.jetbrains.jewel.bridge import androidx.compose.runtime.Immutable -import androidx.compose.ui.graphics.Color import com.intellij.ide.ui.UITheme import com.intellij.ui.ColorUtil import org.jetbrains.jewel.IntelliJThemeIconData diff --git a/ide-laf-bridge/ide-laf-bridge-232/src/main/kotlin/org/jetbrains/jewel/bridge/IconsPathPatching.kt b/ide-laf-bridge/ide-laf-bridge-232/src/main/kotlin/org/jetbrains/jewel/bridge/IconsPathPatching.kt index 65b1d9c83..dea03a894 100644 --- a/ide-laf-bridge/ide-laf-bridge-232/src/main/kotlin/org/jetbrains/jewel/bridge/IconsPathPatching.kt +++ b/ide-laf-bridge/ide-laf-bridge-232/src/main/kotlin/org/jetbrains/jewel/bridge/IconsPathPatching.kt @@ -7,7 +7,7 @@ import org.jetbrains.jewel.InternalJewelApi fun getPatchedIconPath( dirProvider: DirProvider, originalPath: String, - classLoaders: List + classLoaders: List, ): String? { val clazz = Class.forName("com.intellij.ui.icons.CachedImageIconKt") val patchIconPath = clazz.getMethod("patchIconPath", String::class.java, ClassLoader::class.java) diff --git a/ide-laf-bridge/ide-laf-bridge-233/src/main/kotlin/org/jetbrains/jewel/bridge/IconsPathPatching.kt b/ide-laf-bridge/ide-laf-bridge-233/src/main/kotlin/org/jetbrains/jewel/bridge/IconsPathPatching.kt index 03c9c922e..52aba2360 100644 --- a/ide-laf-bridge/ide-laf-bridge-233/src/main/kotlin/org/jetbrains/jewel/bridge/IconsPathPatching.kt +++ b/ide-laf-bridge/ide-laf-bridge-233/src/main/kotlin/org/jetbrains/jewel/bridge/IconsPathPatching.kt @@ -9,7 +9,7 @@ import org.jetbrains.jewel.InternalJewelApi fun getPatchedIconPath( dirProvider: DirProvider, originalPath: String, - classLoaders: List + classLoaders: List, ): String? { // For all provided classloaders, we try to get the patched path, both using // the original path, and an "abridged" path that has gotten the icon path prefix