Manages QActions and their shortcuts.
An ActionManager object is meant to manage all actions for one widget class. All actions are addressed by their internal name (a string that must be unique within the widget class). The manager stores multiple QActions per internal name, i.e., one action per instance of the widget class. The text of the action is the localized string of the action while the internal name is never translated as it is meant to be used to identify the action in the configuration of the application. The localized text is taken from the last added action or removed action for each internal name. The managed widgets can change their language as often as needed but should have the same language all the time. Otherwise, the language of actionText() will depend on the order of the action addition. Actions that are deleted (e.g., when their widget is deleted) are automatically removed from the manager. The keyboard shortcuts assigned to an internal name are preserved even when no action of the type exists. If setShortcuts() has been called before addAction() the action's shortcuts are replaced in addAction(). If setShortcuts() has not been called before the first call to addAction() (for a specific name that is) the shortcuts of the first added action will be taken for all other added actions.
The typical usage of ActionManager is:
- read configured shortcuts from the configuration files of the application and call ActionManager::setShortcuts() for each of them
- create an instance of the widget class
- create actions for the widget
- call ActionManager::addAction() for each action
- if the configuration files contained a shortcut for the action, it will be set for the added action, otherwise the default shortcut set in the widget initialization code will be preserved
- create more instances of the widget class and register their actions in the same way
- call ActionManager::setShortcuts() to change the shortcut for all actions addressed by the same internal name in all existing widget instances
There is one more thing to consider: As long as addShortcut() is called and addAction() is not, actionText() will return the internal name instead of the localized name. It might therefore be a good idea to create an instance of the corresponding widget at application startup, create all actions for it, and immediately delete it again.