Does AppKit provides anything to create "mutually exclusive menu items" by default?

Hi,


I've implemented mutually exclusives buttons using NSSegmentedControl for a NSToolbar. Is there such a thing for Menu Items in AppKit, or do I have to do it by hand?


UPDATE: By mutually exclusives menu items I mean items that are can't both be enabled, or that can't both be in the same state at the same time.


Thanks!

What do you mean ?


Do you mean disabling one menu item when another is enabled ?

Do you mean removing it ?

Do you mean unchecking ?


I do think you would have to do any of this programmatically.

The only function I see here with a very small similarity is autoenable, but that's probably not what you are looking for.

Thanks! That' what I have found so far. I'm dong it by hand. Any of your three guesses would have done it.


PS: I updated the question.

That should not be too hard to implement.


To make it easier to use and maintain, I would create a func with NSMenuItem argument:

func enableExclusive(_ menuItem: NSMenuItem, on: Bool= true) {
     // disable all of the group
     menuItem.isEnabled = on
}



You can enable only the argument

Or disable all (on: false)


Don't forget to close the thread once OK.

You will want to do this in the menu validation or else it might not "stick."


https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/MenuList/Articles/EnablingMenuItems.html

If I understand your question correctly, that is usually achieved by


1) grouping the related options inside separators

2) toggling the state property of the menuItems accordingly


The state of a NSMenuItem displays or hide a checkmark to the left of the menu title (like the character encoding options in Safari there are at least 30 to choose from bu only one can be selected at any time). When state if .on the checkmark is dispalyed and .off hides it. You don't do that in NSUserInterfaceValidations, instead, you implement it in your IBAction.


I know I'm a little bit late but I hope it clarifies the proper way to do it.


https://developer.apple.com/design/human-interface-guidelines/macos/menus/menu-anatomy/

Does AppKit provides anything to create "mutually exclusive menu items" by default?
 
 
Q