~ubuntu-branches/ubuntu/vivid/mygui/vivid

« back to all changes in this revision

Viewing changes to Tools/LayoutEditor/UndoManager.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Howard, Bret Curtis, Scott Howard
  • Date: 2014-09-18 17:57:48 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20140918175748-dd8va78mvpw1jbes
Tags: 3.2.1-1
[ Bret Curtis ]
* Updated license for majority of files from LGPL to Expat (MIT)

[ Scott Howard ]
* New upstream release
* Updated patch to add build option for system GLEW libraries
* All patches accepted upstream except shared_libraries.patch
* Bumped SONAME due to dropped symbols, updated *.symbols and package
  names
* Updated license of debian/* to Expat with permission of all authors
* Don't install Doxygen autogenerated md5 and map files (thanks
  lintian)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "Precompiled.h"
2
 
#include "UndoManager.h"
3
 
#include "CommandManager.h"
4
 
#include "WidgetSelectorManager.h"
5
 
 
6
 
template <> tools::UndoManager* MyGUI::Singleton<tools::UndoManager>::msInstance = nullptr;
7
 
template <> const char* MyGUI::Singleton<tools::UndoManager>::mClassTypeName("UndoManager");
8
 
 
9
 
namespace tools
10
 
{
11
 
        const int UNDO_COUNT = 64;
12
 
 
13
 
        UndoManager::UndoManager() :
14
 
                mPosition(0),
15
 
                mOperations(UNDO_COUNT),
16
 
                mLastProperty(0),
17
 
                mEditorWidgets(nullptr),
18
 
                mUnsaved(false)
19
 
        {
20
 
                CommandManager::getInstance().registerCommand("Command_Undo", MyGUI::newDelegate(this, &UndoManager::commandUndo));
21
 
                CommandManager::getInstance().registerCommand("Command_Redo", MyGUI::newDelegate(this, &UndoManager::commandRedo));
22
 
        }
23
 
 
24
 
        void UndoManager::initialise(EditorWidgets* _ew)
25
 
        {
26
 
                mPosition = 0;
27
 
                mLastProperty = PR_DEFAULT;
28
 
                mEditorWidgets = _ew;
29
 
                UndoManager::getInstance().addValue();
30
 
                setUnsaved(false);
31
 
        }
32
 
 
33
 
        void UndoManager::shutdown()
34
 
        {
35
 
                for (size_t i = 0; i < mOperations.GetSize(); i++)
36
 
                {
37
 
                        delete mOperations[i];
38
 
                }
39
 
                mOperations.Clear();
40
 
        }
41
 
 
42
 
        void UndoManager::undo()
43
 
        {
44
 
                if (mPosition == mOperations.GetSize() - 1) return;
45
 
 
46
 
                setUnsaved(true);
47
 
 
48
 
                mPosition++;
49
 
                mEditorWidgets->clear();
50
 
                mEditorWidgets->loadxmlDocument(mOperations[mPosition]);
51
 
        }
52
 
 
53
 
        void UndoManager::redo()
54
 
        {
55
 
                if (mPosition == 0) return;
56
 
 
57
 
                setUnsaved(true);
58
 
 
59
 
                mPosition--;
60
 
                mEditorWidgets->clear();
61
 
                mEditorWidgets->loadxmlDocument(mOperations[mPosition]);
62
 
        }
63
 
 
64
 
        void UndoManager::addValue(int _property)
65
 
        {
66
 
                setUnsaved(true);
67
 
 
68
 
                if ((_property != PR_DEFAULT) && (_property == mLastProperty))
69
 
                {
70
 
                        delete mOperations.Front();
71
 
                        mOperations.PopFirst();
72
 
                        mOperations.Push( mEditorWidgets->savexmlDocument() );
73
 
                        return;
74
 
                }
75
 
 
76
 
                mLastProperty = _property;
77
 
 
78
 
                if ( mPosition != 0 )
79
 
                {
80
 
                        mLastProperty = PR_DEFAULT;
81
 
                        while (mPosition)
82
 
                        {
83
 
                                delete mOperations.Front();
84
 
                                mOperations.PopFirst();
85
 
                                mPosition--;
86
 
                        }
87
 
                }
88
 
 
89
 
                if ( mOperations.IsFull() ) delete mOperations.Back();
90
 
                mOperations.Push( mEditorWidgets->savexmlDocument() );
91
 
                mPosition = 0;
92
 
        }
93
 
 
94
 
        void UndoManager::commandUndo(const MyGUI::UString& _commandName, bool& _result)
95
 
        {
96
 
                undo();
97
 
                WidgetSelectorManager::getInstance().setSelectedWidget(nullptr);
98
 
 
99
 
                _result = true;
100
 
        }
101
 
 
102
 
        void UndoManager::commandRedo(const MyGUI::UString& _commandName, bool& _result)
103
 
        {
104
 
                redo();
105
 
                WidgetSelectorManager::getInstance().setSelectedWidget(nullptr);
106
 
 
107
 
                _result = true;
108
 
        }
109
 
 
110
 
        void UndoManager::setUnsaved(bool _value)
111
 
        {
112
 
                if (mUnsaved != _value)
113
 
                {
114
 
                        mUnsaved = _value;
115
 
                        eventChanges(mUnsaved);
116
 
                }
117
 
        }
118
 
 
119
 
} // namespace tools
 
1
#include "Precompiled.h"
 
2
#include "UndoManager.h"
 
3
#include "CommandManager.h"
 
4
#include "WidgetSelectorManager.h"
 
5
 
 
6
template <> tools::UndoManager* MyGUI::Singleton<tools::UndoManager>::msInstance = nullptr;
 
7
template <> const char* MyGUI::Singleton<tools::UndoManager>::mClassTypeName = "UndoManager";
 
8
 
 
9
namespace tools
 
10
{
 
11
 
 
12
        const int UNDO_COUNT = 64;
 
13
 
 
14
        UndoManager::UndoManager() :
 
15
                mPosition(0),
 
16
                mOperations(UNDO_COUNT),
 
17
                mLastProperty(0),
 
18
                mEditorWidgets(nullptr),
 
19
                mUnsaved(false)
 
20
        {
 
21
                CommandManager::getInstance().getEvent("Command_Undo")->connect(this, &UndoManager::commandUndo);
 
22
                CommandManager::getInstance().getEvent("Command_Redo")->connect(this, &UndoManager::commandRedo);
 
23
        }
 
24
 
 
25
        void UndoManager::initialise(EditorWidgets* _ew)
 
26
        {
 
27
                mPosition = 0;
 
28
                mLastProperty = PR_DEFAULT;
 
29
                mEditorWidgets = _ew;
 
30
                UndoManager::getInstance().addValue();
 
31
                setUnsaved(false);
 
32
        }
 
33
 
 
34
        void UndoManager::shutdown()
 
35
        {
 
36
                for (size_t i = 0; i < mOperations.GetSize(); i++)
 
37
                {
 
38
                        delete mOperations[i];
 
39
                }
 
40
                mOperations.Clear();
 
41
        }
 
42
 
 
43
        void UndoManager::undo()
 
44
        {
 
45
                if (mPosition == mOperations.GetSize() - 1) return;
 
46
 
 
47
                setUnsaved(true);
 
48
 
 
49
                mPosition++;
 
50
                mEditorWidgets->clear();
 
51
                mEditorWidgets->loadxmlDocument(mOperations[mPosition]);
 
52
        }
 
53
 
 
54
        void UndoManager::redo()
 
55
        {
 
56
                if (mPosition == 0) return;
 
57
 
 
58
                setUnsaved(true);
 
59
 
 
60
                mPosition--;
 
61
                mEditorWidgets->clear();
 
62
                mEditorWidgets->loadxmlDocument(mOperations[mPosition]);
 
63
        }
 
64
 
 
65
        void UndoManager::addValue(int _property)
 
66
        {
 
67
                setUnsaved(true);
 
68
 
 
69
                if ((_property != PR_DEFAULT) && (_property == mLastProperty))
 
70
                {
 
71
                        delete mOperations.Front();
 
72
                        mOperations.PopFirst();
 
73
                        mOperations.Push( mEditorWidgets->savexmlDocument() );
 
74
                        return;
 
75
                }
 
76
 
 
77
                mLastProperty = _property;
 
78
 
 
79
                if ( mPosition != 0 )
 
80
                {
 
81
                        mLastProperty = PR_DEFAULT;
 
82
                        while (mPosition)
 
83
                        {
 
84
                                delete mOperations.Front();
 
85
                                mOperations.PopFirst();
 
86
                                mPosition--;
 
87
                        }
 
88
                }
 
89
 
 
90
                if ( mOperations.IsFull() ) delete mOperations.Back();
 
91
                mOperations.Push( mEditorWidgets->savexmlDocument() );
 
92
                mPosition = 0;
 
93
        }
 
94
 
 
95
        void UndoManager::commandUndo(const MyGUI::UString& _commandName, bool& _result)
 
96
        {
 
97
                undo();
 
98
                WidgetSelectorManager::getInstance().setSelectedWidget(nullptr);
 
99
 
 
100
                _result = true;
 
101
        }
 
102
 
 
103
        void UndoManager::commandRedo(const MyGUI::UString& _commandName, bool& _result)
 
104
        {
 
105
                redo();
 
106
                WidgetSelectorManager::getInstance().setSelectedWidget(nullptr);
 
107
 
 
108
                _result = true;
 
109
        }
 
110
 
 
111
        void UndoManager::setUnsaved(bool _value)
 
112
        {
 
113
                if (mUnsaved != _value)
 
114
                {
 
115
                        mUnsaved = _value;
 
116
                        eventChanges(mUnsaved);
 
117
                }
 
118
        }
 
119
 
 
120
}