-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[JEWEL-845] Add Context Menu to External Links #3107
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
base: master
Are you sure you want to change the base?
[JEWEL-845] Add Context Menu to External Links #3107
Conversation
platform/jewel/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeLabelProvider.kt
Outdated
Show resolved
Hide resolved
platform/jewel/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeUriHandler.kt
Outdated
Show resolved
Hide resolved
.../ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/SwingComparisonTabPanel.kt
Show resolved
Hide resolved
platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Link.kt
Outdated
Show resolved
Hide resolved
...rm/jewel/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/theme/SwingBridgeTheme.kt
Outdated
Show resolved
Hide resolved
platform/jewel/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeLabelProvider.kt
Outdated
Show resolved
Hide resolved
platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/util/LabelProvider.kt
Outdated
Show resolved
Hide resolved
platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Link.kt
Outdated
Show resolved
Hide resolved
platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Link.kt
Outdated
Show resolved
Hide resolved
...el/samples/showcase/src/main/kotlin/org/jetbrains/jewel/samples/showcase/components/Links.kt
Outdated
Show resolved
Hide resolved
5f30676
to
4fdae8a
Compare
@@ -119,7 +119,7 @@ public class ContextSubmenu(label: String, public val submenu: () -> List<Contex | |||
|
|||
public class ContextMenuItemOption( | |||
public val icon: IconKey? = null, | |||
public val actionType: ContextMenuItemOptionAction, | |||
public val actionType: ContextMenuItemOptionAction? = null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The actionType
parameter (which is used to map to a shortcut hint) should've been optional, my bad. You can have an item with an icon but no shortcut or vice versa.
@@ -167,7 +167,9 @@ public fun MenuContent( | |||
val selectableItems = remember(items) { items.filterIsInstance<MenuSelectableItem>() } | |||
|
|||
val anyItemHasIcon = remember { selectableItems.any { it.iconKey != null } } | |||
val anyItemHasKeybinding = remember { selectableItems.any { it.keybinding != null || it.itemOptionAction != null } } | |||
val anyItemHasKeybinding = remember { | |||
selectableItems.any { it.keybinding?.isNotEmpty() == true || it.itemOptionAction != null } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another minor mistake from the previous PR: the keybinding
parameter will always be an empty set. So we shouldn't check if it's null, but if it's not empty.
public class IntUiStringProvider : StringProvider { | ||
override fun fetchStringFromKey(key: String): String = | ||
when (key) { | ||
"action.text.open.link.in.browser" -> "Open Link in Browser" | ||
"action.text.copy.link.address" -> "Copy Link Address" | ||
else -> "" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we should have a more robust architecture to map an label key to its actual string representation, but that's outside the scope of this PR.
If this approach is fine for everybody, I'll create an issue in our board about improving this.
b949d49
to
4a00c9d
Compare
@DanielSouzaBertoldi please add release notes... and check if there are conflicts — GitHub seems very confused :D ![]() |
platform/jewel/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeUriHandler.kt
Outdated
Show resolved
Hide resolved
import org.jetbrains.jewel.foundation.InternalJewelApi | ||
|
||
@InternalJewelApi | ||
public interface StringProvider { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add KDoc. Also, I'd name this something like MessageResourceResolver
as it seems to be what it does in the IDE version, but am open to alternatives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly I'm kinda bad in coming up with names but I like your suggestion, it's way more specific and direct. @faogustavo what do you think?
platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/util/StringProvider.kt
Outdated
Show resolved
Hide resolved
...nt-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/IntUiStringProvider.kt
Outdated
Show resolved
Hide resolved
...form/jewel/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeStringProvider.kt
Outdated
Show resolved
Hide resolved
platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Link.kt
Outdated
Show resolved
Hide resolved
platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Link.kt
Outdated
Show resolved
Hide resolved
platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Link.kt
Outdated
Show resolved
Hide resolved
platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Link.kt
Outdated
Show resolved
Hide resolved
platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Link.kt
Show resolved
Hide resolved
3bac839
to
ec04122
Compare
[JEWEL-845] Add Context Menu to External Links Updating branch now that JetBrains#3091 merged update api dumps applying pr suggestions reran apichecktest add KDoc to MessageResourceResolver add KDoc to MessageResourceResolver undo sample xml run config
37c3a53
to
8eb8868
Compare
Context
Important
For the popup to render correctly outside the row bounds in the
SwingComparisonTabPanel
we need #3105 merged, however it's not a prerequesite for us to open this PR.Currently, our ExternalLink implementation doesn't show a context menu with the default action group from IntelliJ
BrowserLink
component (see screenshot below). This PR makes the necessary changes to show such context menu for external links only.Main Changes
LabelProvider
interface which both IDE and standalone versions will implement to return the action action label.BridgeUriHandler
class which implementsUriHandler
since in IDE we need to call IntelliJ'sBrowserUtil.browse()
function.ExternalLink
overload where clicking the element automatically opens the given link and also displays aContextMenu
. It also has a new parameterlink
which users can use to specify the actual link from the text.SwingComparisonPanel
.Evidences
Right clicking external link
Screen.Recording.2025-07-07.at.10.39.49.mov
Screen.Recording.2025-07-07.at.10.37.43.mov
Using a valid browser link
Screen.Recording.2025-07-07.at.10.57.03.mov
Screen.Recording.2025-07-07.at.10.42.26.mov
Using an empty string
Screen.Recording.2025-07-07.at.10.59.07.mov
Screen.Recording.2025-07-07.at.11.00.07.mov
Release notes
New features
ExternalLink
component now displays a context menu with two default options when right-clicking the link: open in browser and copy link address