ApplicationCommandManager for context menus


#1

Hi Jules,

I like the command dispatching architecture of the ApplicationCommandManager class and I would like to use it not only for the main application commands but also for some small context menus managed by specific components.

But both the ApplicationCommandManager documentation and this forum seem to convey the idea that you can only have one instance of ApplicationCommandManager in your application.

I have derived my component from ApplicationCommandTarget and set it up to respond to a ‘cmd_TestCommand’ command, then I have tried this:

[code]void myComp::mouseDown(const MouseEvent& e)
{
if(e.mods.isPopupMenu())
{
ApplicationCommandManager acm;
PopupMenu menu;

acm.setFirstCommandTarget(this);
acm.registerAllCommandsForTarget(this);

menu.setLookAndFeel(MdLookAndFeel::instance());
menu.addCommandItem(&acm, cmd_TestCommand);

menu.show();
}[/code]

and it works perfectly. After all, I couldn’t see anything in JUCE code that should break this approach.

So my question is: am I going toward disaster by designing my code like this or not?

Thanks


#2

well yes, that’s probably fine! If you’re only using this new instance locally for your modal loop, then I can’t think of a reason why it’d be a problem!


#3

i have another suggestion: It would be nice, if you can associated a string to the Command-Item, which is passed to the ApplicationCommandTarget, especially for “recent files” sub-menus.


#4

i have another suggestion: It would be nice, if you can associated a string to the Command-Item, which is passed to the ApplicationCommandTarget, especially for "recent files" sub-menus.

This!!!

Is there a good solution?  I need it for a similar application...