1 /*!
2 	@file
3 	@author		Albert Semenov
4 	@date		09/2010
5 */
6 
7 #include "Precompiled.h"
8 #include "SettingsResourcePathsControl.h"
9 #include "SettingsManager.h"
10 #include "Localise.h"
11 #include "FactoryManager.h"
12 
13 namespace tools
14 {
15 
FACTORY_ITEM_ATTRIBUTE(SettingsResourcePathsControl)16 	FACTORY_ITEM_ATTRIBUTE(SettingsResourcePathsControl)
17 
18 	SettingsResourcePathsControl::SettingsResourcePathsControl() :
19 		mResourcePathAdd(nullptr),
20 		mResourcePathDelete(nullptr),
21 		mResourcePaths(nullptr),
22 		mOpenSaveFileDialog(nullptr)
23 	{
24 	}
25 
~SettingsResourcePathsControl()26 	SettingsResourcePathsControl::~SettingsResourcePathsControl()
27 	{
28 		mResourcePathAdd->eventMouseButtonClick -= MyGUI::newDelegate(this, &SettingsResourcePathsControl::notifyClickAdd);
29 		mResourcePathDelete->eventMouseButtonClick -= MyGUI::newDelegate(this, &SettingsResourcePathsControl::notifyClickDelete);
30 
31 		delete mOpenSaveFileDialog;
32 		mOpenSaveFileDialog = nullptr;
33 	}
34 
OnInitialise(Control * _parent,MyGUI::Widget * _place,const std::string & _layoutName)35 	void SettingsResourcePathsControl::OnInitialise(Control* _parent, MyGUI::Widget* _place, const std::string& _layoutName)
36 	{
37 		Control::OnInitialise(_parent, _place, _layoutName);
38 
39 		assignWidget(mResourcePathAdd, "ResourcePathAdd");
40 		assignWidget(mResourcePathDelete, "ResourcePathDelete");
41 		assignWidget(mResourcePaths, "ResourcePaths");
42 
43 		mOpenSaveFileDialog = new OpenSaveFileDialog();
44 		mOpenSaveFileDialog->Initialise(SettingsManager::getInstance().getValue("EditorState/OpenSaveFileDialogLayout"));
45 		mOpenSaveFileDialog->setDialogInfo(replaceTags("CaptionOpenFolder"), replaceTags("ButtonOpenFolder"), true);
46 		mOpenSaveFileDialog->eventEndDialog.connect(this, &SettingsResourcePathsControl::notifyEndDialogOpenSaveFile);
47 
48 		mResourcePathAdd->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsResourcePathsControl::notifyClickAdd);
49 		mResourcePathDelete->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsResourcePathsControl::notifyClickDelete);
50 	}
51 
loadSettings()52 	void SettingsResourcePathsControl::loadSettings()
53 	{
54 		mResourcePaths->removeAllItems();
55 		SettingsManager::VectorString paths = SettingsManager::getInstance().getValueList("Resources/AdditionalPath.List");
56 		for (SettingsManager::VectorString::const_iterator item = paths.begin(); item != paths.end(); ++ item)
57 			mResourcePaths->addItem(*item);
58 	}
59 
saveSettings()60 	void SettingsResourcePathsControl::saveSettings()
61 	{
62 		SettingsManager::VectorString paths;
63 		for (size_t index = 0; index < mResourcePaths->getItemCount(); ++ index)
64 			paths.push_back(mResourcePaths->getItemNameAt(index));
65 		SettingsManager::getInstance().setValueList("Resources/AdditionalPath.List", paths);
66 	}
67 
notifyClickAdd(MyGUI::Widget * _sender)68 	void SettingsResourcePathsControl::notifyClickAdd(MyGUI::Widget* _sender)
69 	{
70 		mOpenSaveFileDialog->doModal();
71 	}
72 
notifyClickDelete(MyGUI::Widget * _sender)73 	void SettingsResourcePathsControl::notifyClickDelete(MyGUI::Widget* _sender)
74 	{
75 		size_t index = mResourcePaths->getIndexSelected();
76 		if (index != MyGUI::ITEM_NONE)
77 			mResourcePaths->removeItemAt(index);
78 	}
79 
notifyEndDialogOpenSaveFile(Dialog * _sender,bool _result)80 	void SettingsResourcePathsControl::notifyEndDialogOpenSaveFile(Dialog* _sender, bool _result)
81 	{
82 		if (_result)
83 			mResourcePaths->addItem(mOpenSaveFileDialog->getCurrentFolder());
84 
85 		mOpenSaveFileDialog->endModal();
86 	}
87 
OnCommand(const std::string & _command)88 	void SettingsResourcePathsControl::OnCommand(const std::string& _command)
89 	{
90 		Control::OnCommand(_command);
91 
92 		if (_command == "Command_LoadSettings")
93 			loadSettings();
94 		else if (_command == "Command_SaveSettings")
95 			saveSettings();
96 	}
97 
98 }
99