54
|
1 |
Object subclass:#Transaction
|
|
2 |
instanceVariableNames:'type text actions'
|
|
3 |
classVariableNames:''
|
|
4 |
poolDictionaries:''
|
|
5 |
privateIn:UIObjectView::UndoHistory
|
|
6 |
!
|
|
7 |
|
|
8 |
!UIObjectView::UndoHistory::Transaction class methodsFor:'instance creation'!
|
|
9 |
|
|
10 |
type:aType text:aTextOrNil
|
|
11 |
^ self new type:aType text:aTextOrNil
|
|
12 |
|
|
13 |
|
|
14 |
! !
|
|
15 |
|
|
16 |
!UIObjectView::UndoHistory::Transaction methodsFor:'accessing'!
|
|
17 |
|
|
18 |
asString
|
|
19 |
"returns printable string
|
|
20 |
"
|
|
21 |
|string|
|
|
22 |
|
|
23 |
string := type asString.
|
|
24 |
|
59
|
25 |
text notNil ifTrue:[^ string, ' ', text ]
|
54
|
26 |
ifFalse:[^ string ]
|
|
27 |
!
|
|
28 |
|
|
29 |
text
|
|
30 |
"returns text or nil assigned to transition
|
|
31 |
"
|
|
32 |
^ text
|
|
33 |
!
|
|
34 |
|
|
35 |
type
|
|
36 |
"returns type assigned to transition
|
|
37 |
"
|
|
38 |
^ type
|
|
39 |
!
|
|
40 |
|
|
41 |
type:aType
|
|
42 |
"change type assigned to transition
|
|
43 |
"
|
|
44 |
type := aType
|
|
45 |
! !
|
|
46 |
|
|
47 |
!UIObjectView::UndoHistory::Transaction methodsFor:'add & undo'!
|
|
48 |
|
|
49 |
add:anUndoBlock
|
|
50 |
"add an undo action to the transition
|
|
51 |
"
|
|
52 |
actions isNil ifTrue:[
|
|
53 |
actions := anUndoBlock
|
|
54 |
] ifFalse:[
|
|
55 |
actions isCollection ifFalse:[
|
|
56 |
|temp|
|
|
57 |
|
|
58 |
temp := OrderedCollection new.
|
|
59 |
temp add:actions.
|
|
60 |
actions := temp.
|
47
|
61 |
].
|
54
|
62 |
actions add:anUndoBlock.
|
|
63 |
]
|
|
64 |
!
|
|
65 |
|
|
66 |
undo
|
|
67 |
"undo transition
|
|
68 |
"
|
|
69 |
actions notNil ifTrue:[
|
|
70 |
actions isCollection ifFalse:[
|
|
71 |
actions value
|
|
72 |
] ifTrue:[
|
|
73 |
actions reverseDo:[:anUndoBlock| anUndoBlock value ]
|
|
74 |
]
|
47
|
75 |
]
|
54
|
76 |
! !
|
|
77 |
|
|
78 |
!UIObjectView::UndoHistory::Transaction methodsFor:'initialization'!
|
|
79 |
|
|
80 |
type:aType text:aTextOrNil
|
|
81 |
"initialize transition
|
|
82 |
"
|
|
83 |
type := aType.
|
|
84 |
text := aTextOrNil.
|
|
85 |
! !
|
|
86 |
|
|
87 |
!UIObjectView::UndoHistory::Transaction methodsFor:'testing'!
|
|
88 |
|
|
89 |
isEmpty
|
|
90 |
"returns true if no undo action is registered
|
|
91 |
"
|
|
92 |
^ actions isNil
|
|
93 |
!
|
|
94 |
|
|
95 |
notEmpty
|
|
96 |
"returns true if any undo action is registered
|
|
97 |
"
|
|
98 |
^ actions notNil
|
47
|
99 |
! !
|
|
100 |
|