diff --git a/examples/DemoRunner/Source/Demos/JUCEDemos.h b/examples/DemoRunner/Source/Demos/JUCEDemos.h index 4faf1c6107..0d18838d87 100644 --- a/examples/DemoRunner/Source/Demos/JUCEDemos.h +++ b/examples/DemoRunner/Source/Demos/JUCEDemos.h @@ -75,3 +75,4 @@ CodeEditorComponent::ColourScheme getLightColourScheme(); extern std::unique_ptr sharedAudioDeviceManager; AudioDeviceManager& getSharedAudioDeviceManager (int numInputChannels = -1, int numOutputChannels = -1); +ApplicationCommandManager& getGlobalCommandManager(); diff --git a/examples/DemoRunner/Source/Main.cpp b/examples/DemoRunner/Source/Main.cpp index 59922b2b59..c0114a999a 100644 --- a/examples/DemoRunner/Source/Main.cpp +++ b/examples/DemoRunner/Source/Main.cpp @@ -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 mainWindow; + ApplicationCommandManager commandManager; }; +ApplicationCommandManager& getGlobalCommandManager() +{ + return dynamic_cast (JUCEApplication::getInstance())->getGlobalCommandManager(); +} + //============================================================================== // This macro generates the main() routine that launches the app. START_JUCE_APPLICATION (DemoRunnerApplication) diff --git a/examples/GUI/KeyMappingsDemo.h b/examples/GUI/KeyMappingsDemo.h index 1fc66ecaaf..e50e360c73 100644 --- a/examples/GUI/KeyMappingsDemo.h +++ b/examples/GUI/KeyMappingsDemo.h @@ -249,7 +249,12 @@ public: } private: + #if JUCE_DEMO_RUNNER + ApplicationCommandManager& commandManager = getGlobalCommandManager(); + #else ApplicationCommandManager commandManager; + #endif + KeyMappingEditorComponent keyMappingEditor { *commandManager.getKeyMappings(), true}; KeyPressTarget keyTarget; diff --git a/examples/GUI/MenusDemo.h b/examples/GUI/MenusDemo.h index f56f61ca22..844c525d45 100644 --- a/examples/GUI/MenusDemo.h +++ b/examples/GUI/MenusDemo.h @@ -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 menuBar; MenuBarPosition menuBarPosition = MenuBarPosition::window;