167 (see ListEntry classes) |
167 (see ListEntry classes) |
168 [exBegin] |
168 [exBegin] |
169 |p l| |
169 |p l| |
170 p := PopUpList label:'dummy'. |
170 p := PopUpList label:'dummy'. |
171 l := OrderedCollection new. |
171 l := OrderedCollection new. |
172 l add:('apples' asText emphasizeAllWith:#color->Color red). |
172 l add:(ColoredListEntry string:'apples' color:Color red). |
173 l add:('bananas' asText emphasizeAllWith:#color->Color red). |
173 l add:(ColoredListEntry string:'bananas' color:Color red). |
174 l add:('grape' asText emphasizeAllWith:#color->Color red). |
174 l add:(ColoredListEntry string:'grape' color:Color red). |
175 l add:('lemon' asText emphasizeAllWith:#color->Color red). |
175 l add:(ColoredListEntry string:'lemon' color:Color red). |
176 l add:'='. |
176 l add:'='. |
177 l add:(ColoredListEntry string:'margaritas' color:Color green darkened darkened). |
177 l add:(ColoredListEntry string:'margaritas' color:Color green darkened darkened). |
178 l add:(ColoredListEntry string:'pina colada' color:Color green darkened darkened). |
178 l add:(ColoredListEntry string:'pina colada' color:Color green darkened darkened). |
179 l add:'='. |
179 l add:'='. |
180 l add:(ColoredListEntry string:'smalltalk' color:Color blue). |
180 l add:(ColoredListEntry string:'smalltalk' color:Color blue). |
203 p action:[:what | Transcript show:'you selected: '; showCR:what]. |
203 p action:[:what | Transcript show:'you selected: '; showCR:what]. |
204 p open |
204 p open |
205 [exEnd] |
205 [exEnd] |
206 |
206 |
207 |
207 |
208 with a model (see in the inspector, how the valueHolders index-value changes) |
208 with a model (see in the inspector, how the index-holders value changes) |
209 the defaults are setup to allow a SelectionInList directly as model: |
209 the defaults are setup to allow a SelectionInList directly as model: |
210 [exBegin] |
210 [exBegin] |
211 |p model| |
211 |p model| |
212 |
212 |
213 model := SelectionInList with:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
213 model := SelectionInList with:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
225 |
225 |
226 model := SelectionInList with:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
226 model := SelectionInList with:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
227 model selection:'apples'. |
227 model selection:'apples'. |
228 |
228 |
229 p := PopUpList on:model. |
229 p := PopUpList on:model. |
230 p useIndex:true; aspect:#selectionIndex; change:#selectionIndex:. |
|
231 p open. |
230 p open. |
232 |
231 |
233 slv := SelectionInListView on:model. |
232 slv := SelectionInListView on:model. |
234 slv open. |
233 slv open. |
235 |
234 [exEnd] |
236 model inspect |
235 |
237 [exEnd] |
236 |
238 |
237 dynamically changing the list (click button(s) to change): |
239 |
238 [exBegin] |
240 using another listMessage |
239 |p slv model b| |
241 (the example uses a plug - this would be your applications data model): |
240 |
242 [exBegin] |
241 model := SelectionInList with:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
243 |p model selection| |
242 model selection:'apples'. |
244 |
243 |
245 model := Plug new. |
244 p := PopUpList on:model. |
246 model respondTo:#menu with:[#('lasagne' 'spaghetti' 'risotto')]. |
|
247 model respondTo:#menuSelection with:[selection]. |
|
248 model respondTo:#menuSelection: with:[:val | selection := val]. |
|
249 selection := 1. |
|
250 |
|
251 p := PopUpList label:'eat'. |
|
252 p aspectMessage:#menuSelection; changeMessage:#menuSelection:; listMessage:#menu. |
|
253 p model:model. |
|
254 |
|
255 p open. |
245 p open. |
256 [exEnd] |
246 |
|
247 slv := SelectionInListView on:model. |
|
248 slv open. |
|
249 |
|
250 b := Button label:'long list' action:[model list:#('1' '2' '3' '4' '5' '6')]. |
|
251 b open. |
|
252 b := Button label:'short list' action:[model list:#('1' '2' '3')]. |
|
253 b open. |
|
254 |
|
255 [exEnd] |
|
256 |
257 |
257 |
258 |
258 |
259 two PopUpLists on the same model, different aspects: |
259 two PopUpLists on the same model, different aspects: |
260 (the example uses a plug - this would be your applications data model): |
|
261 [exBegin] |
260 [exBegin] |
262 |top panel p model| |
261 |top panel p model| |
263 |
262 |
264 model := Plug new. |
263 model := Plug new. |
265 model respondTo:#eat: with:[:val | Transcript showCR:'eat: ' , val]. |
264 model respondTo:#eat: with:[:val | Transcript showCR:'eat: ' , val]. |
291 listHolder := #('apples' 'bananas' 'grape' 'lemon' 'margaritas') asValue. |
290 listHolder := #('apples' 'bananas' 'grape' 'lemon' 'margaritas') asValue. |
292 selectionHolder := 'apples' asValue. |
291 selectionHolder := 'apples' asValue. |
293 |
292 |
294 p := PopUpList label:'healthy fruit'. |
293 p := PopUpList label:'healthy fruit'. |
295 p listHolder:listHolder. |
294 p listHolder:listHolder. |
296 p model:selectionHolder; aspect:#value; change:#value:. |
295 p selectionHolder:selectionHolder. |
297 p open. |
296 p open. |
298 selectionHolder inspect |
297 selectionHolder inspect |
299 [exEnd] |
298 [exEnd] |
300 |
299 |
301 same, using index: |
300 same, using index: |
305 listHolder := #('apples' 'bananas' 'grape' 'lemon' 'margaritas') asValue. |
304 listHolder := #('apples' 'bananas' 'grape' 'lemon' 'margaritas') asValue. |
306 selectionIndexHolder := 3 asValue. |
305 selectionIndexHolder := 3 asValue. |
307 |
306 |
308 p := PopUpList new. |
307 p := PopUpList new. |
309 p listHolder:listHolder. |
308 p listHolder:listHolder. |
310 p model:selectionIndexHolder; aspect:#value; change:#value:. |
309 p selectionHolder:selectionIndexHolder. |
311 p useIndex:true. |
310 p useIndex:true. |
312 p open. |
311 p open. |
313 selectionIndexHolder inspect |
312 selectionIndexHolder inspect |
314 [exEnd] |
313 [exEnd] |
315 |
314 |