1 /*! 2 @file 3 @author Albert Semenov 4 @date 07/2012 5 */ 6 7 #include "Precompiled.h" 8 #include "DataListBaseControl.h" 9 #include "CommandManager.h" 10 #include "DialogManager.h" 11 #include "MessageBoxManager.h" 12 #include "DataManager.h" 13 #include "ActionManager.h" 14 #include "ActionCreateData.h" 15 #include "ActionCloneData.h" 16 #include "ActionDestroyData.h" 17 #include "ActionRenameData.h" 18 #include "ActionChangePositionData.h" 19 #include "PropertyUtility.h" 20 #include "DataUtility.h" 21 22 namespace tools 23 { 24 DataListBaseControl()25 DataListBaseControl::DataListBaseControl() : 26 mListBoxControl(nullptr) 27 { 28 } 29 OnInitialise(Control * _parent,MyGUI::Widget * _place,const std::string & _layoutName)30 void DataListBaseControl::OnInitialise(Control* _parent, MyGUI::Widget* _place, const std::string& _layoutName) 31 { 32 Control::OnInitialise(_parent, _place, _layoutName); 33 34 mListBoxControl = findControl<ListBoxDataControl>(); 35 36 if (mListBoxControl != nullptr) 37 { 38 mListBoxControl->setEnableChangePosition(true); 39 mListBoxControl->eventChangePosition.connect(this, &DataListBaseControl::notifyChangePosition); 40 mListBoxControl->eventChangeName.connect(this, &DataListBaseControl::notifyChangeName); 41 } 42 } 43 checkCommand(bool _result)44 bool DataListBaseControl::checkCommand(bool _result) 45 { 46 if (_result) 47 return false; 48 49 if (DialogManager::getInstance().getAnyDialog()) 50 return false; 51 52 if (MessageBoxManager::getInstance().hasAny()) 53 return false; 54 55 return true; 56 } 57 commandCreateData(const MyGUI::UString & _commandName,bool & _result)58 void DataListBaseControl::commandCreateData(const MyGUI::UString& _commandName, bool& _result) 59 { 60 if (!checkCommand(_result)) 61 return; 62 63 DataPtr data = DataUtility::getSelectedDataByType(mParentType); 64 if (data != nullptr) 65 { 66 ActionCreateData* command = new ActionCreateData(); 67 command->setType(mCurrentType); 68 command->setParent(data); 69 command->setUniqueProperty(mPropertyForUnique); 70 71 ActionManager::getInstance().doAction(command); 72 } 73 74 _result = true; 75 } 76 commandCloneData(const MyGUI::UString & _commandName,bool & _result)77 void DataListBaseControl::commandCloneData(const MyGUI::UString& _commandName, bool& _result) 78 { 79 if (!checkCommand(_result)) 80 return; 81 82 DataPtr data = DataUtility::getSelectedDataByType(mCurrentType); 83 if (data != nullptr) 84 { 85 ActionCloneData* command = new ActionCloneData(); 86 command->setPrototype(data); 87 command->setUniqueProperty(mPropertyForUnique); 88 89 ActionManager::getInstance().doAction(command); 90 } 91 92 _result = true; 93 } 94 commandDestroyData(const MyGUI::UString & _commandName,bool & _result)95 void DataListBaseControl::commandDestroyData(const MyGUI::UString& _commandName, bool& _result) 96 { 97 if (!checkCommand(_result)) 98 return; 99 100 DataPtr data = DataUtility::getSelectedDataByType(mCurrentType); 101 if (data != nullptr) 102 { 103 ActionDestroyData* command = new ActionDestroyData(); 104 command->setData(data); 105 command->setUniqueProperty(mPropertyForUnique); 106 107 ActionManager::getInstance().doAction(command); 108 } 109 110 _result = true; 111 } 112 commandRenameData(const MyGUI::UString & _commandName,bool & _result)113 void DataListBaseControl::commandRenameData(const MyGUI::UString& _commandName, bool& _result) 114 { 115 if (!checkCommand(_result)) 116 return; 117 118 if (mListBoxControl != nullptr) 119 mListBoxControl->OnRenameData(); 120 121 _result = true; 122 } 123 setDataInfo(const std::string & _parentType,const std::string & _currentType,const std::string & _propertyName,const std::string & _propertyUnique)124 void DataListBaseControl::setDataInfo(const std::string& _parentType, const std::string& _currentType, const std::string& _propertyName, const std::string& _propertyUnique) 125 { 126 mParentType = _parentType; 127 mCurrentType = _currentType; 128 mPropertyForName = _propertyName; 129 mPropertyForUnique = _propertyUnique; 130 131 if (mListBoxControl != nullptr) 132 { 133 mListBoxControl->setDataInfo(mParentType, mCurrentType, mPropertyForName); 134 if (!mPropertyForUnique.empty()) 135 mListBoxControl->addPropertyNameEnabled(mPropertyForUnique); 136 } 137 } 138 notifyChangePosition(DataPtr _data1,DataPtr _data2)139 void DataListBaseControl::notifyChangePosition(DataPtr _data1, DataPtr _data2) 140 { 141 ActionChangePositionData* command = new ActionChangePositionData(); 142 command->setData1(_data1); 143 command->setData2(_data2); 144 145 ActionManager::getInstance().doAction(command); 146 } 147 notifyChangeName(DataPtr _data,const std::string & _name)148 void DataListBaseControl::notifyChangeName(DataPtr _data, const std::string& _name) 149 { 150 PropertyUtility::executeAction(_data->getProperty(mPropertyForName), _name); 151 } 152 getParentType() const153 const std::string& DataListBaseControl::getParentType() const 154 { 155 return mParentType; 156 } 157 getCurrentType() const158 const std::string& DataListBaseControl::getCurrentType() const 159 { 160 return mCurrentType; 161 } 162 getPropertyForUnique() const163 const std::string& DataListBaseControl::getPropertyForUnique() const 164 { 165 return mPropertyForUnique; 166 } 167 168 } 169