Ejemplo n.º 1
0
// Loads the default shortcuts from the registry
void EventManager::loadAccelerators() {
	if (_debugMode) {
		std::cout << "EventManager: Loading accelerators...\n";
	}

	xml::NodeList shortcutSets = GlobalRegistry().findXPath("user/ui/input//shortcuts");

	if (_debugMode) {
		std::cout << "Found " << shortcutSets.size() << " sets.\n";
	}

	// 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.size() > 0) {
		rMessage() << "EventManager: Shortcuts found in Registry: " <<
			static_cast<int>(shortcutList.size()) << std::endl;
		for (unsigned int i = 0; i < shortcutList.size(); i++) {
			const std::string key = shortcutList[i].getAttributeValue("key");

			if (_debugMode) {
				std::cout << "Looking up command: " << shortcutList[i].getAttributeValue("command") << "\n";
				std::cout << "Key is: >> " << key << " << \n";
			}

			// Try to lookup the command
			IEventPtr event = findEvent(shortcutList[i].getAttributeValue("command"));

			// Check for a non-empty key string
			if (key != "") {
				 // Check for valid command definitions were found
				if (!event->empty()) {
					// 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 {
					rWarning() << "EventManager: Cannot load shortcut definition (command invalid)."
						<< std::endl;
				}
			}
		}
	}
	else {
		// No accelerator definitions found!
		rWarning() << "EventManager: No shortcut definitions found..." << std::endl;
	}
}
Ejemplo n.º 2
0
	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";
		}
	}