parent previous next question (Smalltalk Textbook 22)

EngiChoiceModel

'DialogView' is used to prompt for character string input.


Program-22-1: (DialogView; request:)
------------------------------------------------------------------
DialogView request: 'What is your name?'
DialogView request: 'What is your name?' initialAnswer: 'Atsushi Aoki'
------------------------------------------------------------------

'EngiTextModel' also supports 'request:' and 'request:default:'. For example:


Program-22-2: (EngiTextModel; request:)
------------------------------------------------------------------
EngiTextModel request: 'What is your name?'
EngiTextModel request: 'What is your name?' default: 'Atsushi Aoki'
------------------------------------------------------------------

'DialogView' accepts one character string terminated by the return key. 'EngiTextModel' accepts several lines of strings and is terminated by a mouse click on the 'accept' or 'cancel' button. Also, the title is not limited to text. The following expression prompts the user for an image from the screen, then prompts the user for a string using the given image as "title".

-----------------------------------------
EngiTextModel request: Image fromUser
-----------------------------------------

Three models support the selection of items from a list:

  1. 'EngiFileChoiceModel'
  2. 'EngiMultipleChoiceModel'
  3. 'EngiSingleChoiceModel'

They have the same interface as 'EngiTextModel'. Please 'file in' Appendix 11 and execute the examples.


Program-22-3: (EngiFileChoiceModel, EngiMultipleChoiceModel, 
EngiSingleChoiceModel; example)
-------------------------------------
EngiFileChoiceModel example1
EngiMultipleChoiceModel example1
EngiSingleChoiceModel example1
-------------------------------------

'EngiFileChoiceModel' prompts for files, 'EngiMultipleChoiceModel' prompts for multiple items out of a list, and 'EngiSingleChoiceModel' prompts for one item out of a list. The examples open two windows just so you can confirm that multiple views are getting updated from a single model.

These expressions return a filename:


Program-22-4: (EngiFileChoiceModel; request:)
---------------------------------------------------------
EngiFileChoiceModel request: 'Please select a file.'
EngiFileChoiceModel request: 'Please select a file.' default: '*'
---------------------------------------------------------

Notice the 'default:' value in this example:


Program-22-5: (EngiMultipleChoiceModel; request:list:default:)
---------------------------------------------------------
| aCollection |
aCollection := OrderedCollection new.
aCollection add: 'VisualWorks'.
aCollection add: 'ObjectWorks'.
aCollection add: 'Smalltalk/V'.
aCollection add: 'SmalltalkAgents'.
aCollection add: 'GNU Smalltalk'.
aCollection add: 'Little Smalltalk'.
aCollection add: 'Smalltalk-80'.
EngiMultipleChoiceModel
        request: 'Please select some items.'
        list: aCollection
        default: #('VisualWorks' 'ObjectWorks' )
---------------------------------------------------------

You don't have to provide a default, but if you do, make it an array or a set. In other words, if the default is just one item, you still need to specify it as an array of one item ...default: #('Default item') rather than just ...default: 'Default item'. The above code is from 'EngiMultipleChoiceModel class>example3'.

This code is taken from 'EngiSingleChoiceModel class>example3':


Program-22-6: (EngiSingleChoiceModel; request:list:default:)
-------------------------------------------
| aCollection |
aCollection := OrderedCollection new.
aCollection add: 'VisualWorks'.
aCollection add: 'ObjectWorks'.
aCollection add: 'Smalltalk/V'.
aCollection add: 'SmalltalkAgents'.
aCollection add: 'GNU Smalltalk'.
aCollection add: 'Little Smalltalk'.
aCollection add: 'Smalltalk-80'.
EngiSingleChoiceModel
        request: 'Please select one item.'
        list: aCollection
        default: 'VisualWorks'
-------------------------------------------

And here, too, you need not supply a default at all.

'SelectionSetInListView' is used to create pluggableMVC for multi selection and 'SelectionInListView' is used to create pluggableMVC for single selection. Examine the messages in 'adaptor' and 'defaults' to understand the internals of these classes.


parent previous next question
Copyright (C) 1994-1996 by Atsushi Aoki
Translated by Kaoru Rin Hayashi & Brent N. Reeves