-
Notifications
You must be signed in to change notification settings - Fork 6
/
GtkTreeModel.st
141 lines (98 loc) · 2.48 KB
/
GtkTreeModel.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
Object subclass: GtkTreeModel [
GtkTreeModel class >> on: aGtkTreeStore [
<category: 'instance creation'>
^ super new
initialize;
gtkModel: aGtkTreeStore;
yourself
]
| childrenBlock contentsBlock item model |
initialize [
<category: 'initialization'>
]
gtkModel: aGtkTreeStore [
<category: 'accessing'>
model := aGtkTreeStore
]
connectSignal: aString to: anObject selector: aSymbol [
<category: 'events'>
^ model connectSignal: aString to: anObject selector: aSymbol
]
item: anObject [
<category: 'accessing'>
item := anObject
]
item [
<category: 'accessing'>
^ item
]
childrenBlock: aBlock [
<category: 'accessing'>
childrenBlock := aBlock
]
childrenBlock [
<category: 'accessing'>
^ childrenBlock
]
contentsBlock: aBlock [
<category: 'accessing'>
contentsBlock := aBlock
]
contentsBlock [
<category: 'accessing'>
^ contentsBlock
]
append: anObject [
<category:' model'>
self append: anObject with: nil
]
append: anObject parent: aParentObject [
<category:' model'>
self append: anObject with: (self findIter: aParentObject)
]
append: anItem with: aParentIter [
<category:' model'>
| iter |
iter := model append: aParentIter item: ((self contentsBlock value: anItem) copyWith: anItem).
(self childrenBlock value: anItem) do: [ :each | self append: each with: iter ]
]
remove: anObject ifAbsent: aBlock [
<category: 'model'>
| iter |
iter := self findIter: anObject ifAbsent: [ ^ aBlock value ].
model remove: iter
]
remove: anObject [
<category: 'model'>
self remove: anObject ifAbsent: [ self error: 'item not found' ]
]
clear [
<category: 'model'>
model clear
]
refresh [
<category: 'model'>
self clear.
self item ifNil: [ ^ self ].
(self childrenBlock value: self item) do: [ :each | self append: each with: nil ]
]
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' ]
]
includes: anObject [
self findIter: anObject ifAbsent: [ ^ false ].
^ true
]
]