author | Claus Gittinger <cg@exept.de> |
Fri, 25 Feb 2005 12:00:07 +0100 | |
changeset 1525 | 6384f91af636 |
parent 1522 | 7a569eca4d68 |
child 1526 | f980a40d3c69 |
permissions | -rw-r--r-- |
1522 | 1 |
" |
2 |
COPYRIGHT (c) 2004 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
1454 | 13 |
"{ Package: 'stx:libbasic2' }" |
14 |
||
15 |
Object subclass:#UndoSupport |
|
1525
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
16 |
instanceVariableNames:'actionPerformer transaction undoList redoList |
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
17 |
infoOfCurrentTransaction' |
1454 | 18 |
classVariableNames:'' |
19 |
poolDictionaries:'' |
|
20 |
category:'Views-Text' |
|
21 |
! |
|
22 |
||
23 |
Object subclass:#CompoundAction |
|
1525
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
24 |
instanceVariableNames:'actions userFriendlyInfo' |
1454 | 25 |
classVariableNames:'' |
26 |
poolDictionaries:'' |
|
27 |
privateIn:UndoSupport |
|
28 |
! |
|
29 |
||
30 |
!UndoSupport class methodsFor:'documentation'! |
|
31 |
||
1522 | 32 |
copyright |
33 |
" |
|
34 |
COPYRIGHT (c) 2004 by eXept Software AG |
|
35 |
All Rights Reserved |
|
36 |
||
37 |
This software is furnished under a license and may be used |
|
38 |
only in accordance with the terms of that license and with the |
|
39 |
inclusion of the above copyright notice. This software may not |
|
40 |
be provided or otherwise made available to, or used by, any |
|
41 |
other person. No title to or ownership of the software is |
|
42 |
hereby transferred. |
|
43 |
" |
|
44 |
! |
|
45 |
||
1454 | 46 |
documentation |
47 |
" |
|
48 |
Framework for undo & redo. |
|
49 |
See concrete usage in EditTextView. |
|
50 |
||
51 |
[author:] |
|
52 |
(cg@betti) |
|
53 |
||
54 |
[instance variables:] |
|
55 |
||
56 |
[class variables:] |
|
57 |
||
58 |
[see also:] |
|
59 |
||
60 |
" |
|
61 |
! |
|
62 |
||
63 |
examples |
|
64 |
" |
|
65 |
See usage in EditTextView |
|
66 |
" |
|
67 |
! ! |
|
68 |
||
69 |
!UndoSupport class methodsFor:'instance creation'! |
|
70 |
||
71 |
for:anActionPerformer |
|
72 |
^ self new actionPerformer:anActionPerformer. |
|
73 |
! |
|
74 |
||
75 |
new |
|
76 |
^ self basicNew initialize. |
|
77 |
! ! |
|
78 |
||
1525
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
79 |
!UndoSupport methodsFor:'accessing'! |
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
80 |
|
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
81 |
actionInfo:aString |
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
82 |
infoOfCurrentTransaction := aString |
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
83 |
! ! |
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
84 |
|
1454 | 85 |
!UndoSupport methodsFor:'initialization'! |
86 |
||
87 |
actionPerformer:something |
|
88 |
actionPerformer := something. |
|
89 |
! |
|
90 |
||
91 |
initialize |
|
92 |
self resetHistories. |
|
93 |
! |
|
94 |
||
95 |
resetHistories |
|
96 |
transaction := nil. |
|
97 |
undoList := OrderedCollection new. |
|
98 |
redoList := OrderedCollection new. |
|
99 |
! ! |
|
100 |
||
101 |
!UndoSupport methodsFor:'undo & again'! |
|
102 |
||
103 |
addUndo:action |
|
104 |
transaction notNil ifTrue:[ |
|
105 |
transaction add:action |
|
106 |
]. |
|
107 |
! |
|
108 |
||
109 |
closeTransactionAndAddTo:aList |
|
1525
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
110 |
|actionToAdd| |
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
111 |
|
1454 | 112 |
transaction notEmptyOrNil ifTrue:[ |
1525
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
113 |
(transaction size == 1 and:[infoOfCurrentTransaction isNil]) ifTrue:[ |
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
114 |
actionToAdd := transaction first |
1454 | 115 |
] ifFalse:[ |
1525
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
116 |
actionToAdd := (CompoundAction new actions:transaction). |
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
117 |
actionToAdd info:infoOfCurrentTransaction. |
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
118 |
]. |
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
119 |
aList add:actionToAdd. |
1454 | 120 |
]. |
1525
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
121 |
infoOfCurrentTransaction := nil. |
1454 | 122 |
transaction := nil |
123 |
! |
|
124 |
||
125 |
executeActionFrom:doList addUndoTo:unDoList |
|
126 |
|action trans| |
|
127 |
||
128 |
doList notEmptyOrNil ifTrue:[ |
|
129 |
action := doList removeLast. |
|
130 |
||
131 |
trans := transaction. |
|
132 |
transaction := OrderedCollection new. |
|
133 |
||
134 |
action executeIn:actionPerformer. |
|
135 |
||
136 |
self closeTransactionAndAddTo:unDoList. |
|
137 |
||
138 |
transaction := trans. |
|
139 |
] |
|
140 |
! |
|
141 |
||
142 |
hasRedoAction |
|
143 |
^ redoList size > 0 |
|
144 |
! |
|
145 |
||
146 |
hasUndoAction |
|
147 |
^ undoList size > 0 |
|
148 |
! |
|
149 |
||
150 |
lastRedoAction |
|
151 |
^ redoList removeLast |
|
152 |
! |
|
153 |
||
154 |
lastUndoAction |
|
155 |
^ undoList removeLast |
|
156 |
! |
|
157 |
||
158 |
nonUndoableDo:aBlock |
|
159 |
|prev| |
|
160 |
||
161 |
prev := transaction. |
|
162 |
transaction := nil. |
|
163 |
aBlock |
|
164 |
ensure:[ |
|
165 |
transaction := prev. |
|
166 |
]. |
|
167 |
! |
|
168 |
||
169 |
redo |
|
170 |
self executeActionFrom:redoList addUndoTo:undoList |
|
171 |
! |
|
172 |
||
173 |
undo |
|
174 |
self executeActionFrom:undoList addUndoTo:redoList |
|
175 |
! |
|
176 |
||
1500 | 177 |
undoActionInfo |
178 |
^ undoList last info |
|
179 |
! |
|
180 |
||
1454 | 181 |
undoableDo:aBlock |
182 |
transaction notNil ifTrue:[ |
|
183 |
aBlock value. |
|
184 |
] ifFalse:[ |
|
185 |
transaction := OrderedCollection new. |
|
186 |
aBlock |
|
187 |
ensure:[ |
|
188 |
self closeTransactionAndAddTo:undoList. |
|
189 |
]. |
|
190 |
]. |
|
191 |
! ! |
|
192 |
||
1525
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
193 |
!UndoSupport::CompoundAction methodsFor:'accessing'! |
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
194 |
|
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
195 |
info |
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
196 |
^ userFriendlyInfo |
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
197 |
! |
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
198 |
|
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
199 |
info:aString |
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
200 |
userFriendlyInfo := aString |
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
201 |
! ! |
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
202 |
|
1454 | 203 |
!UndoSupport::CompoundAction methodsFor:'adding'! |
204 |
||
205 |
actions:aCollection |
|
206 |
actions := aCollection |
|
207 |
! |
|
208 |
||
209 |
add:action |
|
210 |
actions isNil ifTrue:[ |
|
211 |
actions := OrderedCollection new. |
|
212 |
]. |
|
213 |
actions add:action |
|
214 |
! ! |
|
215 |
||
216 |
!UndoSupport::CompoundAction methodsFor:'execution'! |
|
217 |
||
218 |
executeIn:editor |
|
219 |
actions reverseDo:[:each | each executeIn:editor ] |
|
220 |
! ! |
|
221 |
||
222 |
!UndoSupport class methodsFor:'documentation'! |
|
223 |
||
224 |
version |
|
1525
6384f91af636
better info of replace action (compound-undo-action has info, too)
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
225 |
^ '$Header: /cvs/stx/stx/libbasic2/UndoSupport.st,v 1.4 2005-02-25 11:00:07 cg Exp $' |
1454 | 226 |
! ! |