I need some suggestion cause i'm not able to make the code respond like i would. I explain the situation.
I have the application logic class, which holds the ApplicationCommandManager class and the state and functions that implements the program logic, then i have multiple windows that can be or not be open at the same time. Each window have sub components that are ApplicationCommandTarget that respond to specific actions and trigger main class logic (this way i can centralize ApplicationCommandManager::
commandStatusChanged to notify all the targets to update their state).
Each content component implement ApplicationCommandTarget::getNextCommandTarget like this:
ApplicationCommandTarget* ContentComponent::getNextCommandTarget()
{
return findFirstTargetParentComponent();
}
So it should never reach the other window when the same command is invoked.
Now i want to register as key listeners for the two windows the same set of key mappings. For example, window 1 have ctrl+z mapped to undoAction, and window 2 have ctrl+z mapped to another action say saveAsAction.
Window 1 and Window 2 when they are opened do:
// ... constructor getApplicationCommandManager().registerAllCommandsForTarget(this); addKeyListener(getApplicationCommandManager().getKeyMappings()); // ... destructor removeKeyListener(getApplicationCommandManager().getKeyMappings()); Array<CommandID> commands; dynamic_cast<ApplicationCommandtarget*>(getContentComponent())->getAllCommands(commands); for (int i = 0; i < commands.size(); i++) getApplicationCommandManager().removeCommand(commands[i]);
But if i open Window 1, then open and close Window 2, then Window 1 does not responds to key events anymore (and ctrl+z does nothing, and it's even removed from it's popup menu item description).
How i'm supposed to work in this situation ? Have a separate ApplicationCommandManager for every Target ? Create all the windows in advance and register everything without unregister the key listeners ?
Also how about responding to key events only for the window that actually have focus without routing events to the other window, which actually is a problem cause ApplicationCommandManager::setFirstCommandTarget should be the one with the focus ?
Anybody can shed some light on this ?
