This is a question about how Sublime implements its application menu on macOS (the NSMenu
).
This isn’t directly related to Sublime Text, but I would really appreciate it if you could give me any direction as to how you’ve solved this small problem when programming Sublime Text.
Basically, I have an app that registers shortcuts (the source is here), and I have multi-key shortcuts (like "cmd+k, cmd+a"
, etc). But no matter what I do I can’t customise the keyEquivalent
(the shortcut text) in the NSMenuItem
.
Here’s an image of Sublime Text doing what I mean, the keyEquivalent
text is boxed:
By default, an NSMenuItem
generates that string from whatever you pass in as a keyEquivalent
, and so having these custom strings isn’t supported by default.
Now, I’ve tried making a completely custom view in order to get this behaviour, but once I do that thanks to some strange translucency/apperance issues the background color of the NSMenuItem
is botched. Here’s an attempt:
This is setting the background color to EXACTLY the same blue as the highlighted color.
As you can see it doesn’t work (this is achieved using a completely custom NSView
), and it creates different colors behind an NSImage
. Weird.
This is the blue I want it to be like.
Here’s Sublime doing the same thing, with the correct color:
I would really appreciate it if you could let me know how you manage to have a custom keyEquivalent
shortcut string with a normal NSMenuItem
.