Hiding Submenus

I understand very well now how to hide/disable contextual menu commands, but…

Is there a way to hide a sub-menu title from appearing when the contents of the sub-menu itself are all hidden? I can’t seem to find a solution to this one.

It’s not an issue of functionality, but aesthetics. I’d rather the sub-menu not appear if nothing within it is currently available.

Not sure if this is relevant to finding the solution I seek, but I did notice that when just 1 of a given submenu’s items is active, and none of the parent-level items are (save the given sub-menu), that sole sub-menu item appears as if it is in the parent (no sub-menu title, pop-up arrow, etc) which is really useful in certain situations.

But how to hide a sub-menu entirely (not merely its contents)?



I bet the thing to do is create two prototypes (or sub-prototypes, rather), one with the sub-menu, one without, with an appropriate dynamic property linked to a replace with other command?

Seems convoluted, but I think I could get that work.

In lieu of a more efficient solution offered in the meantime, that is…