Understanding ApplicationCommandManager from the demo


#1

I feel like I'm close to understanding how the demo uses ApplicationCommandManager

void MainAppWindow::handleAsyncUpdate()
{
    // This registers all of our commands with the command manager but has to be done after the window has
    // been created so we can find the number of rendering engines available
    ApplicationCommandManager& commandManager = MainAppWindow::getApplicationCommandManager();
    commandManager.registerAllCommandsForTarget (contentComponent);
    commandManager.registerAllCommandsForTarget (JUCEApplication::getInstance());
}

So, I can place breakpoints at the start of

void getAllCommands (Array<CommandID>& commands) override
{

(gets hit once), and

void getCommandInfo (CommandID commandID, ApplicationCommandInfo& result) override
{

(gets hit about 20 times, obviously once for each command that getAllCommands returned)

So I understand 'commandManager.registerAllCommandsForTarget (contentComponent);'

But I don't get the next line: commandManager.registerAllCommandsForTarget (JUCEApplication::getInstance());

Why register the application itself to receive commands? JuceDemoApplication didn't override getAllCommands or getCommandInfo

I notice there is a default implementation in juce_application.cpp, which just creates a single "Quit" command.

So do we need to 'commandManager.registerAllCommandsForTarget (JUCEApplication::getInstance());' just for this to work? (Wouldn't it make more sense if the JUCEApplication constructor automatically did this?)

If I test the hypothesis by setting a breakpoint in:

// *** juce_application.cpp ***

void JUCEApplication::getAllCommands (Array<CommandID>& commands)
{
    commands.add (StandardApplicationCommandIDs::quit);
}

I find to my surprise that this breakpoint doesn't get hit.  Why not?


#2

Check Introjucer code.. much easier to follow.