OK, how would one go about having menu items that are both sub-menu containers and selectable items in their own right?
The only way I can see to do this is to make a completely custom menu component, have it masquerade as a normal menu item, but also as a sub menu container. Then catch sub-menu selections and trigger them as its own. This leads to two problems:
The menu IDs of the child items are not guaranteed to be unique with respect to the ‘main’ menu tree. The constructor could return a count of used IDs I guess. This seems cumbersome though.
The custom component is not owned by the menu. This is a pain in that in my particular case, this is a context sensitive menu that is being built up by a number of different methods. As such I don’t really want to encumber calling methods with the job of knowing about child components that may have been created by other methods.
Is there a better way of going about this, or:
- could either addSubMenu be extended to also allow clicking and a return ID (this would be cleaner).
- addCustomItem() for raw components be modified to optionally also take ownership of passed components.