From VisualWorks®, 7.6 of February 1, 2008 on February 1, 2008 at 12:47:01 pm (Dialog confirm: 'You are filing-in a Parcel source file!\\While this is possible it will not have\the same effect as loading the parcel.\None of the Parcel''s prerequisites will\be loaded and none of its load actions\will be performed.\\Are you sure you want to file-in?' withCRs) ifFalse: [self error: 'Parcel file-in abandoned. Choose terminate or close.'] <class> <name>DialogExample</name> <environment>Examples</environment> <super>UI.ApplicationModel</super> <private>false</private> none returnedValue memoryZones dialogBuilder <imports></imports> <category>Examples-Help</category> <attributes> <package>Dialog-Example</package> </attributes> </class> <comment> Examples.DialogExample
DialogExample demonstrates the creation and usage of both prebuilt and custom-crafted dialogs. Instance Variables: returnedValue <ValueHolder on: Object> This is the model for the text field that displays the value returned by the dialog. memoryZones <MultiSelectionInList> This is the model for the list view that is used in the custom dialogs. dialogBuilder <UIBuilder> This is the builder that is used to create the custom dialogs. In a typical application, the reason for holding onto such a dialog builder is so the application can access the widgets in the dialog, to disable them or adjust their properties.
</comment> <methods> Examples.DialogExample <category>actions</category>
askMultiChoice | returnVal | returnVal := Dialog choose: 'Which memory would you like to review first?' labels: #( 'Swimming the Channel' 'Triumph at the Coliseum' 'Love & War #47') values: #(#swim #triumph #love47) default: #triumph for: ScheduledControllers activeController view. self returnedValue value: returnVal printString.
confirm | returnVal | returnVal := Dialog confirm: 'Really erase all memories\of adolescent period?\' withCRs initialAnswer: false for: ScheduledControllers activeController view. "Update the text field in the main window." self returnedValue value: returnVal printString.
getFilename | returnVal | returnVal := Dialog requestFileName: 'Open memory file named...' default: 'heroism01.mem' version: #mustBeOld ifFail: [Transcript show: 'Memory file access canceled'. '']. "Update the text field in the main window." self returnedValue value: returnVal printString.
getText | returnVal | returnVal := Dialog request: 'Find all memories associated with...' initialAnswer: 'friend' onCancel: [self defaultRuminationTopic]. "Update the text field in the main window." self returnedValue value: returnVal printString.
openDialogCanvas | returnVal | returnVal := self openDialogInterface: #memoryZonesDialog. "Update the text field in the main window." self returnedValue value: returnVal printString.
openDialogStoreBuilder | returnVal dialogModel | dialogModel := SimpleDialog new. self dialogBuilder: dialogModel builder. returnVal := dialogModel openFor: self interface: #memoryZonesDialog. "Update the text field in the main window." self returnedValue value: returnVal printString.
openTempModelDialog | returnVal dialogModel list | dialogModel := SimpleDialog new. dialogBuilder := dialogModel builder. "Since the simple model does not respond to a #memoryZones message, its builder must be pre-loaded with a multi-list." list := MultiSelectionInList new list: self memoryZones list copy. dialogBuilder aspectAt: #memoryZones put: list. "Open the interface." returnVal := dialogModel openFor: self interface: #memoryZonesDialog. "Update the text field in the main window." self returnedValue value: returnVal printString.
warn | returnVal | returnVal := Dialog warn: 'The memory named\''FirstKiss''\was not found.\' withCRs. "Update the text field in the main window." self returnedValue value: returnVal printString.
</methods> <methods> Examples.DialogExample <category>private</category>
defaultMemoryZones ^MultiSelectionInList with: #( 'Adventures' 'Books & Films' 'Current Events' 'Fundamental Flaws' 'Gossip' 'Love & War' 'Money' 'Personal Triumphs' 'Relatives' 'Work' ).
defaultRuminationTopic "Answer the topic we're most fond of churning about." ^'money'
dialogMenu "Create a menu for the example Launcher." | mb | mb := MenuBuilder new. "Multi-choice submenu" mb beginSubMenuLabeled: 'Multiple choice'. mb add: 'Warn or notify'->[DialogExample new warn]; add: 'Confirm intention'->[DialogExample new confirm]; add: 'Ask multiple-choice question'->[DialogExample new askMultiChoice]; endSubMenu. "Fill-in-the-blank submenu" mb beginSubMenuLabeled: 'Fill in the blank'. mb add: 'Get text'->[DialogExample new getText]; add: 'Get file name'->[DialogExample new getFilename]; endSubMenu. "Custom submenu" mb beginSubMenuLabeled: 'Custom'. mb add: 'Open dialog canvas'->[DialogExample new openDialogCanvas]; add: 'Open dialog, store its builder'->[DialogExample new openDialogStoreBuilder]; add: 'Open dialog with temp model'->[DialogExample new openTempModelDialog]; endSubMenu. "Launcher example" mb add: 'Launcher'->[DialogExample new createLauncher]. ^mb menu
</methods> <methods> Examples.DialogExample <category>aspects</category>
dialogBuilder ^dialogBuilder
dialogBuilder: aBuilder dialogBuilder := aBuilder
memoryZones ^memoryZones
returnedValue ^returnedValue
</methods> <methods> Examples.DialogExample <category>initialize-release</category>
initialize returnedValue := nil asValue. memoryZones := self defaultMemoryZones.
</methods> <methods> Examples.DialogExample class <category>interface specs</category>
memoryZonesDialog "UIPainter new openOnClass: self andSelector: #memoryZonesDialog" <resource: #canvas> ^#(#FullSpec #window: #(#WindowSpec #label: 'Custom Dialog #1' #min: #(#Point 50 50 ) #bounds: #(#Rectangle 445 257 672 537 ) ) #component: #(#SpecCollection #collection: #( #(#SequenceViewSpec #layout: #(#LayoutFrame 1 0 65 0 -1 1 -30 1 ) #model: #memoryZones #multipleSelections: true #useModifierKeys: true ) #(#LabelSpec #layout: #(#AlignmentOrigin 0 0.5 20 0 0.5 0.5 ) #label: 'Memory Preferences' #style: #large ) #(#LabelSpec #layout: #(#AlignmentOrigin 0 0.5 50 0 0.5 0.5 ) #label: 'Choose preferred topic areas' #style: #small ) #(#DividerSpec #layout: #(#LayoutFrame -50 0.5 35 0 50 0.5 39 0 ) ) #(#ActionButtonSpec #layout: #(#LayoutFrame -25 0.5 -25 1 25 0.5 -5 1 ) #model: #accept #label: 'OK' #defaultable: true ) ) ) )
windowSpec "UIPainter new openOnClass: self andSelector: #windowSpec" <resource: #canvas> ^#(#FullSpec #window: #(#WindowSpec #label: 'DialogExample' #min: #(#Point 529 276 ) #max: #(#Point 529 326 ) #bounds: #(#Rectangle 333 308 862 634 ) ) #component: #(#SpecCollection #collection: #( #(#InputFieldSpec #layout: #(#Rectangle 119 289 411 313 ) #isOpaque: true #colors: #(#LookPreferences #setBackgroundColor: #(#ColorValue #white ) #setHiliteColor: #(#ColorValue #gray ) #setShadowColor: #(#ColorValue #black ) ) #model: #returnedValue #alignment: #center #isReadOnly: true ) #(#LabelSpec #layout: #(#LayoutOrigin -89 0.5 262 0 ) #label: 'Value returned by dialog' #style: #small ) #(#LabelSpec #layout: #(#AlignmentOrigin 0 0.500945 12 0 0.5 0.5 ) #colors: #(#LookPreferences #setForegroundColor: #(#ColorValue #black ) ) #label: 'Memory Browser' #style: #large ) #(#RegionSpec #layout: #(#LayoutFrame 6 0 31 0 -3 0.5 180 0 ) #isOpaque: true #colors: #(#LookPreferences #setBackgroundColor: #(#ColorValue #white ) #setHiliteColor: #(#ColorValue #gray ) #setShadowColor: #(#ColorValue #black ) ) #lineWidth: 1 ) #(#LabelSpec #layout: #(#Point 16 41 ) #label: 'Multiple-choice dialogs' #style: #small ) #(#RegionSpec #layout: #(#LayoutFrame 3 0.5 31 0 -6 1 180 0 ) #isOpaque: true #colors: #(#LookPreferences #setBackgroundColor: #(#ColorValue #white ) #setHiliteColor: #(#ColorValue #gray ) #setShadowColor: #(#ColorValue #black ) ) #lineWidth: 1 ) #(#LabelSpec #layout: #(#LayoutOrigin 12 0.5 41 0 ) #label: 'Custom dialogs' #style: #small ) #(#RegionSpec #layout: #(#LayoutFrame 6 0 185 0 -6 1 255 0 ) #isOpaque: true #colors: #(#LookPreferences #setBackgroundColor: #(#ColorValue #white ) #setHiliteColor: #(#ColorValue #gray ) #setShadowColor: #(#ColorValue #black ) ) #lineWidth: 1 ) #(#LabelSpec #layout: #(#LayoutOrigin 0 0.340265 188 0 ) #label: 'Fill-in-the-blank dialogs' #style: #small ) #(#ActionButtonSpec #layout: #(#Point 15 134 ) #model: #askMultiChoice #label: 'Ask multiple-choice question' #style: #small #defaultable: true ) #(#ActionButtonSpec #layout: #(#Point 16 101 ) #model: #confirm #label: 'Confirm intention' #style: #small #defaultable: true ) #(#ActionButtonSpec #layout: #(#Point 16 68 ) #colors: #(#LookPreferences #setSelectionBackgroundColor: #(#ColorValue #black ) ) #model: #warn #label: 'Warn or notify' #style: #small #defaultable: true ) #(#ActionButtonSpec #layout: #(#Point 277 68 ) #model: #openDialogCanvas #label: 'Open dialog canvas' #style: #small #defaultable: true ) #(#ActionButtonSpec #layout: #(#Point 277 101 ) #model: #openDialogStoreBuilder #label: 'Open dialog, store its builder' #style: #small #defaultable: true ) #(#ActionButtonSpec #layout: #(#Point 277 134 ) #model: #openTempModelDialog #label: 'Open dialog with temp model' #style: #small #defaultable: true ) #(#ActionButtonSpec #layout: #(#Point 268 211 ) #model: #getFilename #label: 'Get file name' #style: #small #defaultable: true ) #(#ActionButtonSpec #layout: #(#Point 176 211 ) #model: #getText #label: 'Get text' #style: #small #defaultable: true ) ) ) )
</methods> "Imported Classes:" self error: 'Attempting to file-in parcel imports. Choose terminate or close' <class> <name>ApplicationModel</name> <environment>UI</environment> <super>UI.Model</super> <private>false</private> none builder uiSession eventHandlers savedWindowInformation <imports></imports> <category>UIBuilder-Framework</category> <attributes> <package>UIBuilder-Framework</package> </attributes> </class>