-rw-r--r-- | kaddressbook/undo.cpp | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/kaddressbook/undo.cpp b/kaddressbook/undo.cpp new file mode 100644 index 0000000..4442087 --- a/dev/null +++ b/kaddressbook/undo.cpp | |||
@@ -0,0 +1,119 @@ | |||
1 | /* | ||
2 | This file is part of KAddressBook. | ||
3 | Copyright (C) 1999 Don Sanders <sanders@kde.org> | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software | ||
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
18 | |||
19 | As a special exception, permission is given to link this program | ||
20 | with any edition of Qt, and distribute the resulting executable, | ||
21 | without including the source code for Qt in the source distribution. | ||
22 | */ | ||
23 | |||
24 | #include "undo.h" | ||
25 | |||
26 | /////////////////////////////// | ||
27 | // StackBase | ||
28 | |||
29 | void StackBase::push(Command *c) | ||
30 | { | ||
31 | mCommandStack.push(c); | ||
32 | emit changed(); | ||
33 | } | ||
34 | |||
35 | bool StackBase::isEmpty() | ||
36 | { | ||
37 | return mCommandStack.isEmpty(); | ||
38 | } | ||
39 | |||
40 | Command *StackBase::top() | ||
41 | { | ||
42 | return mCommandStack.top(); | ||
43 | } | ||
44 | |||
45 | void StackBase::clear() | ||
46 | { | ||
47 | mCommandStack.clear(); | ||
48 | emit changed(); | ||
49 | } | ||
50 | |||
51 | Command *StackBase::pop() | ||
52 | { | ||
53 | Command *c = mCommandStack.pop(); | ||
54 | if (c) | ||
55 | emit changed(); | ||
56 | |||
57 | return c; | ||
58 | } | ||
59 | |||
60 | /////////////////////////////// | ||
61 | // UndoStack | ||
62 | |||
63 | UndoStack* UndoStack::instance_ = 0; | ||
64 | |||
65 | UndoStack::UndoStack() | ||
66 | : StackBase() | ||
67 | { | ||
68 | // setAutoDelete( true ); | ||
69 | } | ||
70 | |||
71 | UndoStack* UndoStack::instance() | ||
72 | { | ||
73 | if (!instance_) | ||
74 | instance_ = new UndoStack(); | ||
75 | return instance_; | ||
76 | } | ||
77 | |||
78 | void UndoStack::undo() | ||
79 | { | ||
80 | if (isEmpty()) | ||
81 | return; | ||
82 | |||
83 | Command *command = pop(); | ||
84 | command->undo(); | ||
85 | |||
86 | RedoStack::instance()->push( command ); | ||
87 | } | ||
88 | |||
89 | //////////////////// | ||
90 | // RedoStack | ||
91 | |||
92 | RedoStack* RedoStack::instance_ = 0; | ||
93 | |||
94 | RedoStack::RedoStack() | ||
95 | { | ||
96 | mCommandStack.setAutoDelete( true ); | ||
97 | } | ||
98 | |||
99 | RedoStack* RedoStack::instance() | ||
100 | { | ||
101 | if (!instance_) | ||
102 | instance_ = new RedoStack(); | ||
103 | return instance_; | ||
104 | } | ||
105 | |||
106 | void RedoStack::redo() | ||
107 | { | ||
108 | Command *command; | ||
109 | if (isEmpty()) | ||
110 | return; | ||
111 | |||
112 | command = pop(); | ||
113 | command->redo(); | ||
114 | UndoStack::instance()->push( command ); | ||
115 | } | ||
116 | |||
117 | #ifndef KAB_EMBEDDED | ||
118 | #include "undo.moc" | ||
119 | #endif //KAB_EMBEDDED | ||