You'll note that ToolbarExtender is of type FExtender rather than FToolbarExtender or FMenuExtender.
By using a generic FExtender class rather than a specific subclass, the framework allows you to create a series of command-function mappings that can be used on either menus or toolbars. The delegate that actually adds the UI controls (in this instance, AddMenuExtension) can link those controls to a subset of commands from your FExtender.
This way, you don't need to have different TCommands classes for different types of extensions, and you can place the commands into a single central class regardless of where those commands are invoked from the UI.
As a result, the only changes that are required are as follows:
- Swapping calls to AddToolBarExtension with AddMenuExtension
- Creating a function that can be bound to FMenuExtensionDelegate rather than FToolbarExtensionDelegate
- Adding the extender to a Menu Extensibility Manager rather than a Toolbar Extensibility Manager