Can't enable NSMenuItemMBS

I am using an NSSearchFieldControlMBS in macOS and would like to add an NSMenuItemMBS to the existing right-click contextual menu. I do this in the WillShowContextualMenu event, where I insert the new NSMenuItem into the existing menu:

dim mItem as new NSMenuItemMBS
mItem.CreateMenuItem(“Perform Recent Search”)
mItem.Enabled = true
menu.insertItem(mItem, 0)

It works, but the menu item is not enabled, because the contextual menu’s autoenabled property = true . I can set that to false, but then default items like Cut, Copy, and Paste are always enabled, which is incorrect.

There would seem to be an easy way to force the new menu item to be enabled. Am I missing something simple?

Sounds like you may need to implement validateMenuItem(menuItem as NSMenuItemMBS) as boolean event to return true.

Thank you, it works (read on).

I had seen that, but didn’t know how to apply it. Now that I have figured out how to, the menu item is correctly enabled. But I don’t know why it is. Here is what I did:

I subclassed NSMenuItemMBS as a “validatingNSMenuItemMBS”, and in the code dimmed mItem as a validatingNSMenuItemMBS.

I added the ValidateMenuItem event to the class, returned true, and put a breakpoint there. When I right-clicked on the SearchFieldControl, the breakpoint didn’t fire. However, the new menu item was enabled.

I tried returning false from the ValidateMenuItem event, just in case there was some bug with the breakpoint. The menu item was still enabled.

Now, in code, whatever I set mItem.enabled to is what I see.

What I did works, but I have no idea why.