1
#include "Precompiled.h"
2
#include "UndoManager.h"
3
#include "CommandManager.h"
4
#include "WidgetSelectorManager.h"
6
template <> tools::UndoManager* MyGUI::Singleton<tools::UndoManager>::msInstance = nullptr;
7
template <> const char* MyGUI::Singleton<tools::UndoManager>::mClassTypeName("UndoManager");
11
const int UNDO_COUNT = 64;
13
UndoManager::UndoManager() :
15
mOperations(UNDO_COUNT),
17
mEditorWidgets(nullptr),
20
CommandManager::getInstance().registerCommand("Command_Undo", MyGUI::newDelegate(this, &UndoManager::commandUndo));
21
CommandManager::getInstance().registerCommand("Command_Redo", MyGUI::newDelegate(this, &UndoManager::commandRedo));
24
void UndoManager::initialise(EditorWidgets* _ew)
27
mLastProperty = PR_DEFAULT;
29
UndoManager::getInstance().addValue();
33
void UndoManager::shutdown()
35
for (size_t i = 0; i < mOperations.GetSize(); i++)
37
delete mOperations[i];
42
void UndoManager::undo()
44
if (mPosition == mOperations.GetSize() - 1) return;
49
mEditorWidgets->clear();
50
mEditorWidgets->loadxmlDocument(mOperations[mPosition]);
53
void UndoManager::redo()
55
if (mPosition == 0) return;
60
mEditorWidgets->clear();
61
mEditorWidgets->loadxmlDocument(mOperations[mPosition]);
64
void UndoManager::addValue(int _property)
68
if ((_property != PR_DEFAULT) && (_property == mLastProperty))
70
delete mOperations.Front();
71
mOperations.PopFirst();
72
mOperations.Push( mEditorWidgets->savexmlDocument() );
76
mLastProperty = _property;
80
mLastProperty = PR_DEFAULT;
83
delete mOperations.Front();
84
mOperations.PopFirst();
89
if ( mOperations.IsFull() ) delete mOperations.Back();
90
mOperations.Push( mEditorWidgets->savexmlDocument() );
94
void UndoManager::commandUndo(const MyGUI::UString& _commandName, bool& _result)
97
WidgetSelectorManager::getInstance().setSelectedWidget(nullptr);
102
void UndoManager::commandRedo(const MyGUI::UString& _commandName, bool& _result)
105
WidgetSelectorManager::getInstance().setSelectedWidget(nullptr);
110
void UndoManager::setUnsaved(bool _value)
112
if (mUnsaved != _value)
115
eventChanges(mUnsaved);
1
#include "Precompiled.h"
2
#include "UndoManager.h"
3
#include "CommandManager.h"
4
#include "WidgetSelectorManager.h"
6
template <> tools::UndoManager* MyGUI::Singleton<tools::UndoManager>::msInstance = nullptr;
7
template <> const char* MyGUI::Singleton<tools::UndoManager>::mClassTypeName = "UndoManager";
12
const int UNDO_COUNT = 64;
14
UndoManager::UndoManager() :
16
mOperations(UNDO_COUNT),
18
mEditorWidgets(nullptr),
21
CommandManager::getInstance().getEvent("Command_Undo")->connect(this, &UndoManager::commandUndo);
22
CommandManager::getInstance().getEvent("Command_Redo")->connect(this, &UndoManager::commandRedo);
25
void UndoManager::initialise(EditorWidgets* _ew)
28
mLastProperty = PR_DEFAULT;
30
UndoManager::getInstance().addValue();
34
void UndoManager::shutdown()
36
for (size_t i = 0; i < mOperations.GetSize(); i++)
38
delete mOperations[i];
43
void UndoManager::undo()
45
if (mPosition == mOperations.GetSize() - 1) return;
50
mEditorWidgets->clear();
51
mEditorWidgets->loadxmlDocument(mOperations[mPosition]);
54
void UndoManager::redo()
56
if (mPosition == 0) return;
61
mEditorWidgets->clear();
62
mEditorWidgets->loadxmlDocument(mOperations[mPosition]);
65
void UndoManager::addValue(int _property)
69
if ((_property != PR_DEFAULT) && (_property == mLastProperty))
71
delete mOperations.Front();
72
mOperations.PopFirst();
73
mOperations.Push( mEditorWidgets->savexmlDocument() );
77
mLastProperty = _property;
81
mLastProperty = PR_DEFAULT;
84
delete mOperations.Front();
85
mOperations.PopFirst();
90
if ( mOperations.IsFull() ) delete mOperations.Back();
91
mOperations.Push( mEditorWidgets->savexmlDocument() );
95
void UndoManager::commandUndo(const MyGUI::UString& _commandName, bool& _result)
98
WidgetSelectorManager::getInstance().setSelectedWidget(nullptr);
103
void UndoManager::commandRedo(const MyGUI::UString& _commandName, bool& _result)
106
WidgetSelectorManager::getInstance().setSelectedWidget(nullptr);
111
void UndoManager::setUnsaved(bool _value)
113
if (mUnsaved != _value)
116
eventChanges(mUnsaved);