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