KeyMappingEditorComponent and dynamic Components

I have a top-level Component with its own Commands (Undo, Redo, etc.), and several ApplicationCommandTargets, each with their own Commands too. These Targets are NOT instantiated at first: my UI is dynamic, the user can choose what part of the UI should be present.

All this works fine, but when displaying the KeyMappingEditorComponent, only the keys from the Targets that have already been instantiated are shown. Once their respective Commands have been added, they appear in the KeyMappingEditorComponent, but not before.

So the problem is that, when starting the application, it is not possible for the user to define, or even see, the keys for the Commands of my dynamic Components, as they have not appeared yet!

Am I doing something wrong, is there a clean way to declare the commands for non-existing Targets yet?


I would probably not use any kind of “live” connection to actual key mappings when showing that key mapping editor component. Instead, I’d keep my own data structure that says what WOULD be mapped IF the specific components were visible, save them in an object at the top level of my app, and then assign those mappings to a given dynamic component whenever one of them is actually created. You could use a std::map object for that, or some kind of lookup table based on indexes, or whatever seems easiest. Just my 2 cents worth. :slight_smile:

1 Like

Thanks for your answer, I’ll try to do that. I guess I can create a short-lived ApplicationCommandManager with Commands retrieved from the top/children Components, and create a KeyPressMappingSet from it… Not hard to do, but too bad there isn’t JUCE built-in way to do that, seems a like a small oversight :).


Ok, the solution is quite simple actually: only have one ApplicationCommandManager (as suggested by the documentation). At the beginning of the app, I call registerAllCommandsForTarget on it, each time with a sub-object of my dynamic Components (inheriting ApplicationCommandTarget).

Just after that, I also apply the possibly stored XML of the previously saved keys.

And so, I can start the app with an ApplicationCommandManager already filled with all the Commands of all the various dynamic pannels that may appear later.