forked from bonzini/gst-visualgst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HistoryStack.st
88 lines (63 loc) · 1.91 KB
/
HistoryStack.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
Object subclass: HistoryStack [
| previousStack nextStack browser |
initialize: aGtkClassBrowserWidget [
<category: 'initialization'>
previousStack := OrderedCollection new.
nextStack := OrderedCollection new.
browser := aGtkClassBrowserWidget.
]
clear [
<category: 'stack'>
previousStack empty.
nextStack empty.
]
current [
<category: 'stack'>
^previousStack isEmpty ifTrue: [ nil ] ifFalse: [ previousStack first ]
]
push: aClass [
<category: 'stack'>
(aClass isNil or: [self current == aClass]) ifTrue: [ ^ self ].
nextStack empty.
previousStack addFirst: aClass
]
size [
<category: 'iteration'>
^nextStack size + previousStack size
]
do: aBlock [
<category: 'iteration'>
nextStack reverseDo: aBlock.
previousStack do: aBlock.
]
selectedIndex [
<category: 'undo-redo'>
^nextStack size + 1
]
selectItem: anInteger [
<category: 'undo-redo'>
| n |
(anInteger between: 1 and: self size)
ifFalse: [self error: 'index out of range'].
[ self selectedIndex < anInteger ] whileTrue: [
nextStack addFirst: previousStack removeFirst ].
[ self selectedIndex > anInteger ] whileTrue: [
previousStack addFirst: nextStack removeFirst ].
browser selectANamespace: self current environment.
browser selectAClass: self current
]
previous [
<category: 'undo-redo'>
previousStack size <= 1 ifTrue: [ ^ self ].
nextStack addFirst: previousStack removeFirst.
browser selectANamespace: self current environment.
browser selectAClass: self current
]
next [
<category: 'undo-redo'>
nextStack isEmpty ifTrue: [ ^ self ].
previousStack addFirst: nextStack removeFirst.
browser selectANamespace: self current environment.
browser selectAClass: self current
]
]