1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Use global ApplicationCommandManager in KeyMappingsDemo and MenusDemo when running in DemoRunner

This commit is contained in:
ed 2021-05-17 16:19:35 +01:00
parent dda48ebec3
commit 2e5509f401
4 changed files with 26 additions and 2 deletions

View file

@ -75,3 +75,4 @@ CodeEditorComponent::ColourScheme getLightColourScheme();
extern std::unique_ptr<AudioDeviceManager> sharedAudioDeviceManager;
AudioDeviceManager& getSharedAudioDeviceManager (int numInputChannels = -1, int numOutputChannels = -1);
ApplicationCommandManager& getGlobalCommandManager();

View file

@ -111,8 +111,10 @@ public:
void shutdown() override { mainWindow = nullptr; }
//==============================================================================
void systemRequestedQuit() override { quit(); }
void anotherInstanceStarted (const String&) override {}
void systemRequestedQuit() override { quit(); }
void anotherInstanceStarted (const String&) override {}
ApplicationCommandManager& getGlobalCommandManager() { return commandManager; }
private:
class MainAppWindow : public DocumentWindow
@ -161,8 +163,14 @@ private:
};
std::unique_ptr<MainAppWindow> mainWindow;
ApplicationCommandManager commandManager;
};
ApplicationCommandManager& getGlobalCommandManager()
{
return dynamic_cast<DemoRunnerApplication*> (JUCEApplication::getInstance())->getGlobalCommandManager();
}
//==============================================================================
// This macro generates the main() routine that launches the app.
START_JUCE_APPLICATION (DemoRunnerApplication)

View file

@ -249,7 +249,12 @@ public:
}
private:
#if JUCE_DEMO_RUNNER
ApplicationCommandManager& commandManager = getGlobalCommandManager();
#else
ApplicationCommandManager commandManager;
#endif
KeyMappingEditorComponent keyMappingEditor { *commandManager.getKeyMappings(), true};
KeyPressTarget keyTarget;

View file

@ -157,6 +157,10 @@ public:
setApplicationCommandManagerToWatch (&commandManager);
commandManager.registerAllCommandsForTarget (this);
// this ensures that commands invoked on the DemoRunner application are correctly
// forwarded to this demo
commandManager.setFirstCommandTarget (this);
// this lets the command manager use keypresses that arrive in our window to send out commands
addKeyListener (commandManager.getKeyMappings());
@ -174,6 +178,8 @@ public:
#if JUCE_MAC
MenuBarModel::setMacMainMenu (nullptr);
#endif
commandManager.setFirstCommandTarget (nullptr);
}
void resized() override
@ -316,7 +322,11 @@ public:
}
private:
#if JUCE_DEMO_RUNNER
ApplicationCommandManager& commandManager = getGlobalCommandManager();
#else
ApplicationCommandManager commandManager;
#endif
std::unique_ptr<MenuBarComponent> menuBar;
MenuBarPosition menuBarPosition = MenuBarPosition::window;