1 /*
2  *  Copyright (c) 2011 Dmitry Kazakov <dimula73@gmail.com>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #include "kis_undo_stores.h"
20 
21 #include <kundo2stack.h>
22 
23 
24 /*****************************************************************/
25 /*                KisSurrogateUndoStore                           */
26 /*****************************************************************/
27 
KisSurrogateUndoStore()28 KisSurrogateUndoStore::KisSurrogateUndoStore()
29     : m_undoStack(new KUndo2Stack)
30 {
31 }
32 
~KisSurrogateUndoStore()33 KisSurrogateUndoStore::~KisSurrogateUndoStore()
34 {
35     delete m_undoStack;
36 }
37 
presentCommand()38 const KUndo2Command* KisSurrogateUndoStore::presentCommand()
39 {
40     return m_undoStack->command(m_undoStack->index() - 1);
41 }
42 
undoLastCommand()43 void KisSurrogateUndoStore::undoLastCommand()
44 {
45     m_undoStack->undo();
46 }
47 
addCommand(KUndo2Command * command)48 void KisSurrogateUndoStore::addCommand(KUndo2Command *command)
49 {
50     if(!command) return;
51     m_undoStack->push(command);
52 }
53 
beginMacro(const KUndo2MagicString & macroName)54 void KisSurrogateUndoStore::beginMacro(const KUndo2MagicString& macroName)
55 {
56     m_undoStack->beginMacro(macroName);
57 }
58 
endMacro()59 void KisSurrogateUndoStore::endMacro()
60 {
61     m_undoStack->endMacro();
62 }
63 
undo()64 void KisSurrogateUndoStore::undo()
65 {
66     m_undoStack->undo();
67 }
68 
redo()69 void KisSurrogateUndoStore::redo()
70 {
71     m_undoStack->redo();
72 }
73 
purgeRedoState()74 void KisSurrogateUndoStore::purgeRedoState()
75 {
76     m_undoStack->purgeRedoState();
77 }
78 
clear()79 void KisSurrogateUndoStore::clear()
80 {
81     m_undoStack->clear();
82 }
83 
undoAll()84 void KisSurrogateUndoStore::undoAll()
85 {
86     while(m_undoStack->canUndo()) {
87         m_undoStack->undo();
88     }
89 }
90 
redoAll()91 void KisSurrogateUndoStore::redoAll()
92 {
93     while(m_undoStack->canRedo()) {
94         m_undoStack->redo();
95     }
96 }
97 
98 
99 /*****************************************************************/
100 /*                KisDumbUndoStore                               */
101 /*****************************************************************/
102 
presentCommand()103 const KUndo2Command* KisDumbUndoStore::presentCommand()
104 {
105     return 0;
106 }
107 
undoLastCommand()108 void KisDumbUndoStore::undoLastCommand()
109 {
110     /**
111      * Ermm.. Do we actually have one? We are dumb! ;)
112      */
113 }
114 
addCommand(KUndo2Command * command)115 void KisDumbUndoStore::addCommand(KUndo2Command *command)
116 {
117     /**
118      * Ermm.. Done with it! :P
119      */
120     command->redo();
121     delete command;
122 }
123 
beginMacro(const KUndo2MagicString & macroName)124 void KisDumbUndoStore::beginMacro(const KUndo2MagicString& macroName)
125 {
126     /**
127      * Yes, sir! >:)
128      */
129     Q_UNUSED(macroName);
130 }
131 
endMacro()132 void KisDumbUndoStore::endMacro()
133 {
134     /**
135      * Roger that! :)
136      */
137 }
138 
purgeRedoState()139 void KisDumbUndoStore::purgeRedoState()
140 {
141     /**
142      * Erm... what? %)
143      */
144 }
145