File: DataListBaseControl.cpp

package info (click to toggle)
mygui 3.4.3%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 38,792 kB
  • sloc: cpp: 133,849; ansic: 30,249; xml: 15,794; cs: 12,601; tcl: 776; python: 400; makefile: 35; sh: 4
file content (167 lines) | stat: -rw-r--r-- 4,127 bytes parent folder | download
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*!
	@file
	@author		Albert Semenov
	@date		07/2012
*/

#include "Precompiled.h"
#include "DataListBaseControl.h"
#include "CommandManager.h"
#include "DialogManager.h"
#include "MessageBoxManager.h"
#include "DataManager.h"
#include "ActionManager.h"
#include "ActionCreateData.h"
#include "ActionCloneData.h"
#include "ActionDestroyData.h"
#include "ActionRenameData.h"
#include "ActionChangePositionData.h"
#include "PropertyUtility.h"
#include "DataUtility.h"

namespace tools
{

	void DataListBaseControl::OnInitialise(Control* _parent, MyGUI::Widget* _place, std::string_view _layoutName)
	{
		Control::OnInitialise(_parent, _place, _layoutName);

		mListBoxControl = findControl<ListBoxDataControl>();

		if (mListBoxControl != nullptr)
		{
			mListBoxControl->setEnableChangePosition(true);
			mListBoxControl->eventChangePosition.connect(this, &DataListBaseControl::notifyChangePosition);
			mListBoxControl->eventChangeName.connect(this, &DataListBaseControl::notifyChangeName);
		}
	}

	bool DataListBaseControl::checkCommand(bool _result)
	{
		if (_result)
			return false;

		if (DialogManager::getInstance().getAnyDialog())
			return false;

		if (MessageBoxManager::getInstance().hasAny())
			return false;

		return true;
	}

	void DataListBaseControl::commandCreateData(const MyGUI::UString& _commandName, bool& _result)
	{
		if (!checkCommand(_result))
			return;

		DataPtr data = DataUtility::getSelectedDataByType(mParentType);
		if (data != nullptr)
		{
			ActionCreateData* command = new ActionCreateData();
			command->setType(mCurrentType);
			command->setParent(data);
			command->setUniqueProperty(mPropertyForUnique);

			ActionManager::getInstance().doAction(command);
		}

		_result = true;
	}

	void DataListBaseControl::commandCloneData(const MyGUI::UString& _commandName, bool& _result)
	{
		if (!checkCommand(_result))
			return;

		DataPtr data = DataUtility::getSelectedDataByType(mCurrentType);
		if (data != nullptr)
		{
			ActionCloneData* command = new ActionCloneData();
			command->setPrototype(data);
			command->setUniqueProperty(mPropertyForUnique);

			ActionManager::getInstance().doAction(command);
		}

		_result = true;
	}

	void DataListBaseControl::commandDestroyData(const MyGUI::UString& _commandName, bool& _result)
	{
		if (!checkCommand(_result))
			return;

		DataPtr data = DataUtility::getSelectedDataByType(mCurrentType);
		if (data != nullptr)
		{
			ActionDestroyData* command = new ActionDestroyData();
			command->setData(data);
			command->setUniqueProperty(mPropertyForUnique);

			ActionManager::getInstance().doAction(command);
		}

		_result = true;
	}

	void DataListBaseControl::commandRenameData(const MyGUI::UString& _commandName, bool& _result)
	{
		if (!checkCommand(_result))
			return;

		if (mListBoxControl != nullptr)
			mListBoxControl->OnRenameData();

		_result = true;
	}

	void DataListBaseControl::setDataInfo(
		std::string_view _parentType,
		std::string_view _currentType,
		std::string_view _propertyName,
		std::string_view _propertyUnique)
	{
		mParentType = _parentType;
		mCurrentType = _currentType;
		mPropertyForName = _propertyName;
		mPropertyForUnique = _propertyUnique;

		if (mListBoxControl != nullptr)
		{
			mListBoxControl->setDataInfo(mParentType, mCurrentType, mPropertyForName);
			if (!mPropertyForUnique.empty())
				mListBoxControl->addPropertyNameEnabled(mPropertyForUnique);
		}
	}

	void DataListBaseControl::notifyChangePosition(DataPtr _data1, DataPtr _data2)
	{
		ActionChangePositionData* command = new ActionChangePositionData();
		command->setData1(_data1);
		command->setData2(_data2);

		ActionManager::getInstance().doAction(command);
	}

	void DataListBaseControl::notifyChangeName(DataPtr _data, std::string_view _name)
	{
		PropertyUtility::executeAction(_data->getProperty(mPropertyForName), _name);
	}

	const std::string& DataListBaseControl::getParentType() const
	{
		return mParentType;
	}

	const std::string& DataListBaseControl::getCurrentType() const
	{
		return mCurrentType;
	}

	const std::string& DataListBaseControl::getPropertyForUnique() const
	{
		return mPropertyForUnique;
	}

}