// Connects the given accelerator to the given command (identified by the string) void EventManager::connectAccelerator(IAccelerator& accelerator, const std::string& command) { IEventPtr event = findEvent(command); if (!event->empty()) { // Command found, connect it to the accelerator by passing its pointer accelerator.connectEvent(event); } else { // Command NOT found rWarning() << "EventManager: Unable to connect command: " << command << std::endl; } }
void loadAccelerators() { xml::NodeList shortcutSets = GlobalRegistry().findXPath("user/ui/input//shortcuts"); // If we have two sets of shortcuts, delete the default ones if (shortcutSets.size() > 1) { GlobalRegistry().deleteXPath("user/ui/input//shortcuts[@name='default']"); } // Find all accelerators xml::NodeList shortcutList = GlobalRegistry().findXPath("user/ui/input/shortcuts//shortcut"); if (!shortcutList.empty()) { globalOutputStream() << "EventManager: Shortcuts found in Registry: " << shortcutList.size() << "\n"; for (unsigned int i = 0; i < shortcutList.size(); i++) { const std::string key = shortcutList[i].getAttributeValue("key"); const std::string command = shortcutList[i].getAttributeValue("command"); // Try to lookup the command IEvent* event = findEvent(command); // Check if valid key / command definitions were found if (key != "" && event != NULL) { // Get the modifier string (e.g. "SHIFT+ALT") const std::string modifierStr = shortcutList[i].getAttributeValue("modifiers"); if (!duplicateAccelerator(key, modifierStr, event)) { // Create the accelerator object IAccelerator* accelerator = addAccelerator(key, modifierStr); // Connect the newly created accelerator to the command accelerator->connectEvent(event); } } } } else { // No accelerator definitions found! globalOutputStream() << "EventManager: No shortcut definitions found...\n"; } }