forked from bonzini/gst-visualgst
-
Notifications
You must be signed in to change notification settings - Fork 2
/
GtkListModel.st
98 lines (68 loc) · 1.52 KB
/
GtkListModel.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
88
89
90
91
92
93
94
95
96
97
Object subclass: GtkListModel [
GtkListModel class >> on: aGtkListStore [
<category: 'instance creation'>
^ super new
initialize;
gtkModel: aGtkListStore;
yourself
]
| contentsBlock item model |
initialize [
<category: 'initialization'>
]
gtkModel: aGtkListStore [
<category: 'accessing'>
model := aGtkListStore
]
item: anObject [
<category: 'accessing'>
item := anObject
]
item [
<category: 'accessing'>
^ item
]
contentsBlock: aBlock [
<category: 'accessing'>
contentsBlock := aBlock
]
contentsBlock [
<category: 'accessing'>
^ contentsBlock
]
append: anItem [
<category: 'model'>
model appendItem: ((self contentsBlock value: anItem) copyWith: anItem)
]
remove: anObject [
<category: 'model'>
| iter |
(iter := self findIter: anObject) ifNil: [ self error: 'item not found' ].
model remove: iter
]
clear [
<category: 'model'>
model clear
]
refresh [
<category: 'model'>
self clear.
self item ifNil: [ ^ self ].
self item do: [ :each | self append: each ]
]
hasItem: anObject [
<category: 'item selection'>
self findIter: anObject ifAbsent: [ ^ false ].
^ true
]
findIter: anObject ifAbsent: aBlock [
<category: 'item selection'>
model do: [ :elem :iter |
elem last = anObject ifTrue: [ ^ iter ] ].
aBlock value
]
findIter: anObject [
<category: 'item selection'>
^ self findIter: anObject ifAbsent: [ self error: 'Item not found' ]
]
]