Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve string-based Icon deprecation #555

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions samples/ide-plugin/src/main/kotlin/icons/IdeSampleIconKeys.kt
Original file line number Diff line number Diff line change
@@ -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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have NewUI mappings for these, so a simple PathIconKey is enough

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Yesterday, I replaced another icon on one of my branches and I created like the gitHub one you are improving. Gotta improve mine as well 🙏🏻

val jewelToolWindow = PathIconKey("icons/jewel-tool-window.svg", IdeSampleIconKeys::class.java)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -107,10 +108,9 @@ internal class SwingComparisonTabPanel : BorderLayoutPanel() {

compose {
Icon(
"icons/jewel-tool-window.svg",
null,
[email protected],
Modifier.border(1.dp, Color.Red),
key = IdeSampleIconKeys.jewelToolWindow,
contentDescription = null,
modifier = Modifier.border(1.dp, Color.Red),
)
}
}.layout(RowLayout.PARENT_GRID)
Expand Down
24 changes: 20 additions & 4 deletions ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Icon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Param names are necessary for the resulting code to compile, especially with the vararg versions.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 It saves a bit of time. I was manually adding the names and then running the ReplaceWith.

"key = Icon(PathIconKey(resource, iconClass), contentDescription = contentDescription, " +
"colorFilter = colorFilter, modifier = modifier, hints)",
"org.jetbrains.jewel.ui.icon.PathIconKey",
),
)
@Composable
public fun Icon(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down