Is it possible to set hint text for a menu item in...
# jewel
f
Is it possible to set hint text for a menu item in a MenuScope? I found selectableItemWithActionType, but that only accepts the limited set of copy/paste/cut/select all actions. I guess it's possible to make my own MenuItemShortcutHintProvider that overrides the text to display something custom, but I'm still limited to 4 different action types
s
Not that I know; it's not a possibility in Swing either unless you have custom renderers anyway (and honestly it'd be a very weird UX)
f
How would it be very weird UX? It's a standard way of denoting shortcuts for toolbar actions
s
I misunderstood what you meant, I thought you wanted to show some random text there instead of shortcuts
For shortcuts yes, the hint provider is the right way to do it
f
Does the hint have no effect on the actual shortcut?
s
At the moment the hints are purely visual
f
As in, the shortcuts have to be implemented separately with the window-level key events
Ah, okay. What should I do if I want more than 4 different items?
s
I have a design to properly do shortcuts but it'll take some time, hopefully it'll ship by eoy
I don't remember the details of the hint provider. @Daniel Souza Bertoldi do you? Or was it someone else that did it? I forget
f
It's just
Copy code
/** Provides formatted shortcut hint strings for [ContextMenuItemOptionAction] entries shown in menus. */
public interface MenuItemShortcutHintProvider {
    /**
     * Gets the formatted shortcut string for the given action identifier.
     *
     * @param actionType The action type. See [ContextMenuItemOptionAction].
     * @return The human-readable shortcut string (e.g., "⌘C", "Ctrl+S"), or empty if no shortcut is defined or it
     *   shouldn't be displayed.
     */
    public fun getShortcutHint(actionType: ContextMenuItemOptionAction): String
}

/** The predefined actions for [ContextMenuItemOption]s. */
@Suppress("AbstractClassCanBeInterface") // Binary compatibility: sealed class cannot be changed to interface
public sealed class ContextMenuItemOptionAction {
    /** Represents a "Copy" action. */
    public data object CopyMenuItemOptionAction : ContextMenuItemOptionAction()

    /** Represents a "Paste" action. */
    public data object PasteMenuItemOptionAction : ContextMenuItemOptionAction()

    /** Represents a "Cut" action. */
    public data object CutMenuItemOptionAction : ContextMenuItemOptionAction()

    /** Represents a "Select All" action. */
    public data object SelectAllMenuItemOptionAction : ContextMenuItemOptionAction()
}
So it seems like if you want more than 4 different actions, you can't, because it's sealed
Which doesn't make much sense to me, even in a text viewing/editing context menu you may still want more than 4 different actions with hints (e.g. lookup symbol)
s
Yeah this seems rather limited, hope we'll have proper actions with keymaps support coming in by EOY as I mentioned
👍 1
d
Yeah that's the current API we have for now 😕 I don't recall if there war ever plans on expanding this code after
MenuItemShortcutHintProvider
was created, but I do agree it's very limited
s
We'll make sure it's more flexible in the actions system
🙏 1