From 0a43abe01250513defe947b2e7aa5ce865364a4a Mon Sep 17 00:00:00 2001 From: Sebastiano Poggi Date: Thu, 22 Aug 2024 10:35:44 +0200 Subject: [PATCH] Improve string-based Icon deprecation (#555) Adding the PathIconKey import and param names to the ReplaceWith makes the auto-upgrade seamless. It would result in red code otherwise. Upgrade Icon in SwingComparisonTabPanel to new style. --- .../main/kotlin/icons/IdeSampleIconKeys.kt | 5 ++-- .../ideplugin/SwingComparisonTabPanel.kt | 8 +++---- .../org/jetbrains/jewel/ui/component/Icon.kt | 24 +++++++++++++++---- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/samples/ide-plugin/src/main/kotlin/icons/IdeSampleIconKeys.kt b/samples/ide-plugin/src/main/kotlin/icons/IdeSampleIconKeys.kt index ef1527944..6d740f3dc 100644 --- a/samples/ide-plugin/src/main/kotlin/icons/IdeSampleIconKeys.kt +++ b/samples/ide-plugin/src/main/kotlin/icons/IdeSampleIconKeys.kt @@ -1,7 +1,8 @@ package icons -import org.jetbrains.jewel.ui.icon.IntelliJIconKey +import org.jetbrains.jewel.ui.icon.PathIconKey object IdeSampleIconKeys { - val gitHub = IntelliJIconKey("icons/github.svg", "icons/github.svg", IdeSampleIconKeys::class.java) + val gitHub = PathIconKey("icons/github.svg", IdeSampleIconKeys::class.java) + val jewelToolWindow = PathIconKey("icons/jewel-tool-window.svg", IdeSampleIconKeys::class.java) } diff --git a/samples/ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/SwingComparisonTabPanel.kt b/samples/ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/SwingComparisonTabPanel.kt index 405bfa2c5..39416df4c 100644 --- a/samples/ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/SwingComparisonTabPanel.kt +++ b/samples/ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/SwingComparisonTabPanel.kt @@ -30,6 +30,7 @@ import com.intellij.ui.dsl.builder.panel import com.intellij.util.ui.JBFont import com.intellij.util.ui.JBUI import com.intellij.util.ui.components.BorderLayoutPanel +import icons.IdeSampleIconKeys import icons.JewelIcons import org.jetbrains.jewel.bridge.JewelComposePanel import org.jetbrains.jewel.bridge.medium @@ -107,10 +108,9 @@ internal class SwingComparisonTabPanel : BorderLayoutPanel() { compose { Icon( - "icons/jewel-tool-window.svg", - null, - this@SwingComparisonTabPanel.javaClass, - Modifier.border(1.dp, Color.Red), + key = IdeSampleIconKeys.jewelToolWindow, + contentDescription = null, + modifier = Modifier.border(1.dp, Color.Red), ) } }.layout(RowLayout.PARENT_GRID) diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Icon.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Icon.kt index bb972f4b9..89c6d7b66 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Icon.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Icon.kt @@ -42,7 +42,11 @@ import java.io.InputStream @Deprecated( "Use the IconKey-based API instead", - ReplaceWith("Icon(PathIconKey(resource, iconClass), contentDescription, colorFilter, modifier, hints)"), + ReplaceWith( + "key = Icon(PathIconKey(resource, iconClass), contentDescription = contentDescription, " + + "colorFilter = colorFilter, modifier = modifier, hints)", + "org.jetbrains.jewel.ui.icon.PathIconKey", + ), ) @Composable public fun Icon( @@ -66,7 +70,11 @@ public fun Icon( @Deprecated( "Use the IconKey-based API instead", - ReplaceWith("Icon(PathIconKey(resource, iconClass), contentDescription, colorFilter, modifier, hint)"), + ReplaceWith( + "key = Icon(PathIconKey(resource, iconClass), contentDescription = contentDescription, " + + "colorFilter = colorFilter, modifier = modifier, hint = hint)", + "org.jetbrains.jewel.ui.icon.PathIconKey", + ), ) @Composable public fun Icon( @@ -90,7 +98,11 @@ public fun Icon( @Deprecated( "Use the IconKey-based API instead", - ReplaceWith("Icon(PathIconKey(resource, iconClass), contentDescription, tint, modifier, hints)"), + ReplaceWith( + "Icon(key = PathIconKey(resource, iconClass), contentDescription = contentDescription, " + + "tint = tint, modifier = modifier, hints = hints)", + "org.jetbrains.jewel.ui.icon.PathIconKey", + ), ) @Composable public fun Icon( @@ -114,7 +126,11 @@ public fun Icon( @Deprecated( "Use the IconKey-based API instead", - ReplaceWith("Icon(PathIconKey(resource, iconClass), contentDescription, tint, modifier, hints)"), + ReplaceWith( + "Icon(key = PathIconKey(resource, iconClass), contentDescription = contentDescription, " + + "tint = tint, modifier = modifier, hint = hint)", + "org.jetbrains.jewel.ui.icon.PathIconKey", + ), ) @Composable public fun Icon(