1 /*!
2 	@file
3 	@author		Albert Semenov
4 	@date		08/2010
5 */
6 
7 #include "Precompiled.h"
8 #include "CommandManager.h"
9 
10 template <> tools::CommandManager* MyGUI::Singleton<tools::CommandManager>::msInstance = nullptr;
11 template <> const char* MyGUI::Singleton<tools::CommandManager>::mClassTypeName = "CommandManager";
12 
13 namespace tools
14 {
15 
initialise()16 	void CommandManager::initialise()
17 	{
18 	}
19 
shutdown()20 	void CommandManager::shutdown()
21 	{
22 		for (MapEvent::iterator iter = mEvents.begin(); iter != mEvents.end(); iter++)
23 			delete iter->second;
24 
25 		mEvents.clear();
26 	}
27 
executeCommand(const MyGUI::UString & _command)28 	bool CommandManager::executeCommand(const MyGUI::UString& _command)
29 	{
30 		bool result = false;
31 		MyGUI::UString command = _command;
32 		size_t index = _command.find('.');
33 		if (index != MyGUI::UString::npos)
34 		{
35 			command = _command.substr(0, index);
36 			mData = _command.substr(index + 1);
37 		}
38 
39 		EventType* event = getEvent(command);
40 		if (event != nullptr)
41 		{
42 			event->operator()(command, result);
43 		}
44 		else
45 		{
46 			MYGUI_LOG(Warning, "Command '" << command << "' not found");
47 		}
48 
49 		mData.clear();
50 
51 		return result;
52 	}
53 
setCommandData(const MyGUI::UString & _data)54 	void CommandManager::setCommandData(const MyGUI::UString& _data)
55 	{
56 		mData = _data;
57 	}
58 
getCommandData() const59 	const MyGUI::UString& CommandManager::getCommandData() const
60 	{
61 		return mData;
62 	}
63 
getEvent(const MyGUI::UString & _command)64 	CommandManager::EventType* CommandManager::getEvent(const MyGUI::UString& _command)
65 	{
66 		MapEvent::iterator event = mEvents.find(_command);
67 		if (event != mEvents.end())
68 			return (*event).second;
69 
70 		EventType* type = new EventType();
71 		mEvents[_command] = type;
72 		return type;
73 	}
74 
75 }
76