Eric
I had tried that before, expecting it to work, but it appears ContextualMenus don’t work on the Mac. Extract from the manual: “ContextualMenus do not work with PopupMenu on macOS due to a limitation of the underlying macOS control that is used.”
So currently I am using a desktopMenuItem.popup in the MouseUp event - and having to backfill the result into the text of a blank first row so that it looks as if it has been selected. Not as pretty.
On my Mac (Ventura 13.2, Xojo 2022r4) - ConstructContextualMenu does not fire when clicking the control.
In your code, base is the root menuItem for the popup control, but you have assigned to it the result of your popMenu (base = popMenu.popUp). I’m not sure that would work as you indicate.
There’s probably a feedback somewhere for doing this, as the underlying macOS control will happily allow it, it’s just Xojo’s framework that sits atop won’t.
What you can do is to build a hierarchical menu of menu items, Then you grab [NSMenuitem submenu] from the base item, then use [NSPopupButton setMenu:] to set that menu onto the PopupMenu.
When I used it, I dynamically built the menu at open and used addHandler to capture the action event of each item. However I was using the PopupMenu in a “PullDown” form [NSPopupButton setPullsDown:], whereby selecting an item from the menu didn’t change the displayed label of the PopupMenu.
The declares for doing this is part of my App Kit, but are NOT compatible with DesktopControls. I’m sure the MVPs can provide you with a version or plugin that works with DesktopControls.