DialogBox.st
changeset 307 d3fe810390cb
parent 302 d7fb38f963ae
child 310 4bbc8deffc8c
equal deleted inserted replaced
306:6a6a1513b713 307:d3fe810390cb
     7  inclusion of the above copyright notice.   This software may not
     7  inclusion of the above copyright notice.   This software may not
     8  be provided or otherwise made available to, or used by, any
     8  be provided or otherwise made available to, or used by, any
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 
       
    13 'From Smalltalk/X, Version:2.10.8 on 10-jan-1996 at 15:47:31'                   !
       
    14 
    12 
    15 ModalBox subclass:#DialogBox
    13 ModalBox subclass:#DialogBox
    16 	instanceVariableNames:'buttonPanel okButton okAction abortButton abortAction
    14 	instanceVariableNames:'buttonPanel okButton okAction abortButton abortAction
    17 		acceptReturnAsOK yPosition leftIndent rightIndent bindings
    15 		acceptReturnAsOK yPosition leftIndent rightIndent bindings
    18 		addedComponents inputFieldGroup acceptOnLeave acceptValue
    16 		addedComponents inputFieldGroup acceptOnLeave acceptValue
   106 "
   104 "
   107 !
   105 !
   108 
   106 
   109 examples
   107 examples
   110 "
   108 "
   111     mostly, DialogBox is used as an abstract class as a base for InfoBox, 
   109     historically, DialogBox was used as an abstract class as a base for InfoBox, 
   112     YesNoBox etc.
   110     YesNoBox etc. However, the programmatic construction protocol (addComponent)
       
   111     now allows those classes to be easily replaced and future versions may
       
   112     do this and make those subclasses obsolete.
       
   113 
   113     For most simple standard dialogs, there are ready to use
   114     For most simple standard dialogs, there are ready to use
   114     methods in the class protocol.
   115     methods in the class protocol.
       
   116 
   115     For example:
   117     For example:
   116 
   118 
   117       info & warnings:
   119       info & warnings:
   118 
   120 
   119 	Dialog information:'hi there'
   121         Dialog information:'hi there'
   120 
   122 
   121 	Dialog warn:'oops'
   123         Dialog warn:'oops'
   122 
   124 
   123 
   125 
   124       yes/no questions:
   126       yes/no questions:
   125 
   127 
   126 	(Dialog confirm:'is this simple ?')
   128         (Dialog confirm:'is this simple ?')
   127 	ifTrue:[
   129         ifTrue:[
   128 	    Transcript showCr:'thats what I expected'
   130             Transcript showCr:'thats what I expected'
   129 	] ifFalse:[
   131         ] ifFalse:[
   130 	    Transcript showCr:'read more examples and documentation'
   132             Transcript showCr:'read more examples and documentation'
   131 	]
   133         ]
   132 
   134 
   133 
   135 
   134       yes/no question with cancel option:
   136       yes/no question with cancel option:
   135 
   137 
   136 	|answer|
   138         |answer|
   137 
   139 
   138 	answer := Dialog confirmWithCancel:'is this simple ?'.
   140         answer := Dialog confirmWithCancel:'is this simple ?'.
   139 	answer isNil ifTrue:[
   141         answer isNil ifTrue:[
   140 	    Transcript showCr:'no easy decision'
   142             Transcript showCr:'no easy decision'
   141 	] ifFalse:[
   143         ] ifFalse:[
   142 	    answer ifTrue:[
   144             answer ifTrue:[
   143 		Transcript showCr:'thats what I expected'
   145                 Transcript showCr:'thats what I expected'
   144 	    ] ifFalse:[
   146             ] ifFalse:[
   145 		Transcript showCr:'read more examples and documentation'
   147                 Transcript showCr:'read more examples and documentation'
   146 	    ]
   148             ]
   147 	]
   149         ]
   148 
   150 
   149 
   151 
   150       asking for a string:
   152       asking for a string:
   151 
   153 
   152 	|s|
   154         |s|
   153 
   155 
   154 	s := Dialog request:'enter your name, please:'.
   156         s := Dialog request:'enter your name, please:'.
   155 	s notEmpty ifTrue:[
   157         s notEmpty ifTrue:[
   156 	    Transcript showCr:'you entered: ' , s.
   158             Transcript showCr:'you entered: ' , s.
   157 	]
   159         ]
   158 
   160 
   159 
   161 
   160       asking for a string with given default:
   162       asking for a string with given default:
   161 
   163 
   162 	|s|
   164         |s|
   163 
   165 
   164 	s := Dialog 
   166         s := Dialog 
   165 		request:'enter your name, please:'
   167                 request:'enter your name, please:'
   166 		initialAnswer:(OperatingSystem getLoginName).
   168                 initialAnswer:(OperatingSystem getLoginName).
   167 	s notEmpty ifTrue:[
   169         s notEmpty ifTrue:[
   168 	    Transcript showCr:'you entered: ' , s.
   170             Transcript showCr:'you entered: ' , s.
   169 	]
   171         ]
   170 
   172 
   171 
   173 
   172       asking for a filename:
   174       asking for a filename:
   173 
   175 
   174 	|s|
   176         |s|
   175 
   177 
   176 	s := Dialog 
   178         s := Dialog 
   177 		requestFileName:'select a file, please:'
   179                 requestFileName:'select a file, please:'
   178 		default:''.
   180                 default:''.
   179 	Transcript show:'you entered: '; showCr:s.
   181         Transcript show:'you entered: '; showCr:s.
   180 
   182 
   181 
   183 
   182       with changed button label and pattern:
   184       with changed button label and pattern:
   183 
   185 
   184 	|s|
   186         |s|
   185 
   187 
   186 	s := Dialog 
   188         s := Dialog 
   187 		requestFileName:'select a file, please:'
   189                 requestFileName:'select a file, please:'
   188 		default:''
   190                 default:''
   189 		ok:'show'
   191                 ok:'show'
   190 		abort:'cancel'
   192                 abort:'cancel'
   191 		pattern:'*.rc'.
   193                 pattern:'*.rc'.
   192 	Transcript show:'you entered: '; showCr:s.
   194         Transcript show:'you entered: '; showCr:s.
   193 
   195 
   194 
   196 
   195       asking for a password:
   197       asking for a password:
   196 
   198 
   197 	|s|
   199         |s|
   198 
   200 
   199 	s := Dialog 
   201         s := Dialog 
   200 		requestPassword:'enter your secret, please:'.
   202                 requestPassword:'enter your secret, please:'.
   201 	Transcript show:'you entered: '; showCr:s.
   203         Transcript show:'you entered: '; showCr:s.
   202 
   204 
   203 
   205 
   204 
   206 
   205     However, you can construct dialogs programmatically, as shown in
   207     However, you can construct dialogs programmatically, as shown in
   206     the following examples:
   208     the following examples:
   207 
   209 
   208     basic (unusable) example:
   210     basic (unusable) example:
   209 
   211 
   210 	DialogBox new open
   212         DialogBox new open
   211 
   213 
   212     still unusable - only an ok-button:
   214     still unusable - only an ok-button:
   213 
   215 
   214 	DialogBox new addOkButton; open
   216         DialogBox new addOkButton; open
   215 
   217 
   216     both ok- and abortButtons:
   218     both ok- and abortButtons:
   217 
   219 
   218 	DialogBox new addAbortButton; addOkButton; open
   220         DialogBox new addAbortButton; addOkButton; open
   219 
   221 
   220     with different ok-label:
   222     with different ok-label:
   221 
   223 
   222 	DialogBox new addAbortButton; addOkButtonLabelled:'yeah'; open
   224         DialogBox new addAbortButton; addOkButtonLabelled:'yeah'; open
   223 
   225 
   224     adding a textlabel gives an infoBox:
   226     adding a textlabel gives an infoBox:
   225 
   227 
   226 	DialogBox new
   228         DialogBox new
   227 	    addTextLabel:'hello';
   229             addTextLabel:'hello';
   228 	    addOkButton; 
   230             addOkButton; 
   229 	    open
   231             open
   230 
   232 
   231     a textlabel with abort- and okButton gives a yesNoBox:
   233     a textlabel with abort- and okButton gives a yesNoBox:
   232 
   234 
   233 	DialogBox new
   235         DialogBox new
   234 	    addTextLabel:'hello';
   236             addTextLabel:'hello';
   235 	    addAbortButton; 
   237             addAbortButton; 
   236 	    addOkButton; 
   238             addOkButton; 
   237 	    open
   239             open
   238 
   240 
   239     the same, adjusting the labels contents to the left:
   241     the same, adjusting the labels contents to the left:
   240 
   242 
   241 	|box|
   243         |box|
   242 
   244 
   243 	box := DialogBox new.
   245         box := DialogBox new.
   244 	(box addTextLabel:'hello') adjust:#left.
   246         (box addTextLabel:'hello') adjust:#left.
   245 	box addAbortButton; 
   247         box addAbortButton; 
   246 	    addOkButton; 
   248             addOkButton; 
   247 	    open
   249             open
   248 
   250 
   249     with modified buttons:
   251     with modified buttons:
   250 
   252 
   251 	|box|
   253         |box|
   252 
   254 
   253 	box := DialogBox new.
   255         box := DialogBox new.
   254 	(box addTextLabel:'are you certain ?') adjust:#left.
   256         (box addTextLabel:'are you certain ?') adjust:#left.
   255 	box addAbortButtonLabelled:'not really'. 
   257         box addAbortButtonLabelled:'not really'. 
   256 	(box addOkButtonLabelled:'yes, absolutely') 
   258         (box addOkButtonLabelled:'yes, absolutely') 
   257 		activeBackgroundColor:Color red. 
   259                 activeBackgroundColor:Color red. 
   258 	box open
   260         box open
   259 
   261 
   260 
   262 
   261     mswindows style:
   263     mswindows style:
   262 
   264 
   263 	|b box|
   265         |b box|
   264 
   266 
   265 	box := DialogBox new.
   267         box := DialogBox new.
   266 	(box addTextLabel:'are you certain ?') adjust:#left.
   268         (box addTextLabel:'are you certain ?') adjust:#left.
   267 	b := Button new.
   269         b := Button new.
   268 	b activeLogo:(Image fromFile:'bitmaps/cancel_down.bmp').
   270         b activeLogo:(Image fromFile:'bitmaps/cancel_down.bmp').
   269 	b passiveLogo:(Image fromFile:'bitmaps/cancel_up.bmp').
   271         b passiveLogo:(Image fromFile:'bitmaps/cancel_up.bmp').
   270 	b focusLogo:(Image fromFile:'bitmaps/cancel_focus.bmp').
   272         b focusLogo:(Image fromFile:'bitmaps/cancel_focus.bmp').
   271 	b beImageButton.
   273         b beImageButton.
   272 	box addAbortButton:b.
   274         box addAbortButton:b.
   273 
   275 
   274 	b := Button new.
   276         b := Button new.
   275 	b activeLogo:(Image fromFile:'bitmaps/ok_down.bmp').
   277         b activeLogo:(Image fromFile:'bitmaps/ok_down.bmp').
   276 	b passiveLogo:(Image fromFile:'bitmaps/ok_up.bmp').
   278         b passiveLogo:(Image fromFile:'bitmaps/ok_up.bmp').
   277 	b focusLogo:(Image fromFile:'bitmaps/ok_focus.bmp').
   279         b focusLogo:(Image fromFile:'bitmaps/ok_focus.bmp').
   278 	b beImageButton.
   280         b beImageButton.
   279 	box addOkButton:b.
   281         box addOkButton:b.
   280 	box open
   282         box open
   281 
   283 
   282 
   284 
   283     two textlabels:
   285     two textlabels:
   284 
   286 
   285 	DialogBox new
   287         DialogBox new
   286 	    addTextLabel:'hello';
   288             addTextLabel:'hello';
   287 	    addTextLabel:'world';
   289             addTextLabel:'world';
   288 	    addAbortButton; 
   290             addAbortButton; 
   289 	    addOkButton; 
   291             addOkButton; 
   290 	    open
   292             open
   291 
   293 
   292     fixing the dialogs size (suppres it calculating its size from the
   294     fixing the dialogs size (suppres it calculating its size from the
   293     preferredExtents of its components):
   295     preferredExtents of its components):
   294 
   296 
   295 	DialogBox new
   297         DialogBox new
   296 	    label:'a simple dialog';
   298             label:'a simple dialog';
   297 	    addTextLabel:'hello';
   299             addTextLabel:'hello';
   298 	    addAbortButton; 
   300             addAbortButton; 
   299 	    addOkButton; 
   301             addOkButton; 
   300 	    extent:200@200;
   302             extent:200@200;
   301 	    sizeFixed:true;
   303             sizeFixed:true;
   302 	    open
   304             open
   303 
   305 
   304     asking the box if it was closed via ok:
   306     asking the box if it was closed via ok:
   305 
   307 
   306 	(DialogBox new
   308         (DialogBox new
   307 	    label:'a simple dialog';
   309             label:'a simple dialog';
   308 	    addTextLabel:'hello';
   310             addTextLabel:'hello';
   309 	    addAbortButton; 
   311             addAbortButton; 
   310 	    addOkButton; 
   312             addOkButton; 
   311 	    extent:200@200;
   313             extent:200@200;
   312 	    sizeFixed:true;
   314             sizeFixed:true;
   313 	    open
   315             open
   314 	) accepted ifTrue:[
   316         ) accepted ifTrue:[
   315 	    Transcript showCr:'yes'
   317             Transcript showCr:'yes'
   316 	] ifFalse:[
   318         ] ifFalse:[
   317 	    Transcript showCr:'no'
   319             Transcript showCr:'no'
   318 	]
   320         ]
   319 
   321 
   320     textLabels are not limited to strings (although, the name which is
   322     textLabels are not limited to strings (although, the name which is
   321     used for ST-80 compatibility, suggests it):
   323     used for ST-80 compatibility, suggests it):
   322 
   324 
   323 	DialogBox new
   325         DialogBox new
   324 	    addTextLabel:(Image fromFile:'bitmaps/garfield.gif');
   326             addTextLabel:(Image fromFile:'bitmaps/garfield.gif');
   325 	    addOkButton; 
   327             addOkButton; 
   326 	    open
   328             open
   327 
   329 
   328 	DialogBox new
   330         DialogBox new
   329 	    addTextLabel:'hello';
   331             addTextLabel:'hello';
   330 	    addTextLabel:((Image fromFile:'bitmaps/garfield.gif')
   332             addTextLabel:((Image fromFile:'bitmaps/garfield.gif')
   331 				magnifiedTo:200@150);
   333                                 magnifiedTo:200@150);
   332 	    addTextLabel:'world';
   334             addTextLabel:'world';
   333 	    addAbortButton; 
   335             addAbortButton; 
   334 	    addOkButton; 
   336             addOkButton; 
   335 	    open
   337             open
   336 
   338 
   337     adding an input field (on a string model):
   339     adding an input field (on a string model):
   338 
   340 
   339 	|stringModel|
   341         |stringModel|
   340 
   342 
   341 	stringModel := '' asValue.
   343         stringModel := '' asValue.
   342 	(DialogBox new
   344         (DialogBox new
   343 	    addTextLabel:'Please enter a string:';
   345             addTextLabel:'Please enter a string:';
   344 	    addInputFieldOn:stringModel; 
   346             addInputFieldOn:stringModel; 
   345 	    addAbortButton; 
   347             addAbortButton; 
   346 	    addOkButton; 
   348             addOkButton; 
   347 	    open
   349             open
   348 	) accepted ifTrue:[
   350         ) accepted ifTrue:[
   349 	    Transcript showCr:'entered: ', stringModel value
   351             Transcript showCr:'entered: ', stringModel value
   350 	]
   352         ]
   351 
   353 
   352 
   354 
   353     multiple input fields (notice, that the dialog connects the fields
   355     multiple input fields (notice, that the dialog connects the fields
   354     in a group, so stepping is allowed via Cursor and Return keys):
   356     in a group, so stepping is allowed via Cursor and Return keys):
   355 
   357 
   356 	|firstName lastName|
   358         |firstName lastName|
   357 
   359 
   358 	firstName := '' asValue.
   360         firstName := '' asValue.
   359 	lastName := '' asValue.
   361         lastName := '' asValue.
   360 	(DialogBox new
   362         (DialogBox new
   361 	    addTextLabel:'Please enter your name:';
   363             addTextLabel:'Please enter your name:';
   362 	    addInputFieldOn:firstName; 
   364             addInputFieldOn:firstName; 
   363 	    addVerticalSpace;
   365             addVerticalSpace;
   364 	    addInputFieldOn:lastName; 
   366             addInputFieldOn:lastName; 
   365 	    addAbortButton; 
   367             addAbortButton; 
   366 	    addOkButton; 
   368             addOkButton; 
   367 	    open
   369             open
   368 	) accepted ifTrue:[
   370         ) accepted ifTrue:[
   369 	    Transcript showCr:'entered: ', firstName value , ' ' , lastName value
   371             Transcript showCr:'entered: ', firstName value , ' ' , lastName value
   370 	]
   372         ]
   371 
   373 
   372 
   374 
   373     of course, the model may contain a value initially:
   375     of course, the model may contain a value initially:
   374 
   376 
   375 	|firstName lastName p line i name|
   377         |firstName lastName p line i name|
   376 
   378 
   377 	firstName := '' asValue.
   379         firstName := '' asValue.
   378 	lastName := '' asValue.
   380         lastName := '' asValue.
   379 	p := PipeStream readingFrom:'finger ' , OperatingSystem getLoginName.
   381         p := PipeStream readingFrom:'finger ' , OperatingSystem getLoginName.
   380 	p notNil ifTrue:[
   382         p notNil ifTrue:[
   381 	    line := p nextLine.
   383             line := p nextLine.
   382 	    (i := line findString:'Name:') ~~ 0 ifTrue:[
   384             (i := line findString:'Name:') ~~ 0 ifTrue:[
   383 		name := line copyFrom:(i + 'Name:' size).
   385                 name := line copyFrom:(i + 'Name:' size).
   384 	    ] ifFalse:[
   386             ] ifFalse:[
   385 		(i := line findString:'real life:') == 0 ifTrue:[
   387                 (i := line findString:'real life:') == 0 ifTrue:[
   386 		    line := p nextLine.
   388                     line := p nextLine.
   387 		].
   389                 ].
   388 		(i := line findString:'real life:') ~~ 0 ifTrue:[
   390                 (i := line findString:'real life:') ~~ 0 ifTrue:[
   389 		    name := line copyFrom:(i + 'real life:' size).
   391                     name := line copyFrom:(i + 'real life:' size).
   390 		]
   392                 ]
   391 	    ].
   393             ].
   392 	    name notNil ifTrue:[
   394             name notNil ifTrue:[
   393 		firstName value: name asCollectionOfWords first.
   395                 firstName value: name asCollectionOfWords first.
   394 		lastName  value: name asCollectionOfWords last.
   396                 lastName  value: name asCollectionOfWords last.
   395 		Transcript showCr:'initially ' , firstName value , ' ' , lastName value.
   397                 Transcript showCr:'initially ' , firstName value , ' ' , lastName value.
   396 	    ].
   398             ].
   397 	    p close.
   399             p close.
   398 	].
   400         ].
   399 
   401 
   400 	(DialogBox new
   402         (DialogBox new
   401 	    addTextLabel:'Please enter your name:';
   403             addTextLabel:'Please enter your name:';
   402 	    addInputFieldOn:firstName; 
   404             addInputFieldOn:firstName; 
   403 	    addVerticalSpace;
   405             addVerticalSpace;
   404 	    addInputFieldOn:lastName; 
   406             addInputFieldOn:lastName; 
   405 	    addAbortButton; 
   407             addAbortButton; 
   406 	    addOkButton;
   408             addOkButton;
   407 	    open
   409             open
   408 	) accepted ifTrue:[
   410         ) accepted ifTrue:[
   409 	    Transcript showCr:'entered: ', firstName value , ' ' , lastName value
   411             Transcript showCr:'entered: ', firstName value , ' ' , lastName value
   410 	]
   412         ]
   411 
   413 
   412 
   414 
   413     validated password entry:
   415     validated password entry:
   414 
   416 
   415 	|box firstEntry secondEntry|
   417         |box firstEntry secondEntry|
   416 
   418 
   417 	firstEntry := '' asValue.
   419         firstEntry := '' asValue.
   418 	secondEntry := '' asValue.
   420         secondEntry := '' asValue.
   419 
   421 
   420 	box := DialogBox new.
   422         box := DialogBox new.
   421 	(box addTextLabel:'Please enter your secret:') adjust:#left.
   423         (box addTextLabel:'Please enter your secret:') adjust:#left.
   422 	(box addInputFieldOn:firstEntry) passwordCharacter:$*. 
   424         (box addInputFieldOn:firstEntry) passwordCharacter:$*. 
   423 	box addVerticalSpace.
   425         box addVerticalSpace.
   424 	(box addInputFieldOn:secondEntry) passwordCharacter:$*. 
   426         (box addInputFieldOn:secondEntry) passwordCharacter:$*. 
   425 	box addAbortButton. 
   427         box addAbortButton. 
   426 	box addOkButton. 
   428         box addOkButton. 
   427 	box open.
   429         box open.
   428 	box accepted ifTrue:[
   430         box accepted ifTrue:[
   429 	    firstEntry value ~= secondEntry value ifTrue:[
   431             firstEntry value ~= secondEntry value ifTrue:[
   430 		Transcript showCr:'wrong input - try again'
   432                 Transcript showCr:'wrong input - try again'
   431 	    ] ifFalse:[
   433             ] ifFalse:[
   432 		Transcript showCr:'entered: ', firstEntry value
   434                 Transcript showCr:'entered: ', firstEntry value
   433 	    ]
   435             ]
   434 	]
   436         ]
   435 
   437 
   436 
   438 
   437    constructing a dialog from other elements:
   439    constructing a dialog from other elements:
   438 
   440 
   439      adding a fileSelectionList:
   441      adding a fileSelectionList:
   440      (since the dialog adds the component with its preferred extent,
   442      (since the dialog adds the component with its preferred extent,
   441       ignoring the 300-height, this looks ugly ... 
   443       ignoring the 300-height, this looks ugly ... 
   442       ... especially when resized vertically)
   444       ... especially when resized vertically)
   443 
   445 
   444 	|top l scr fileName|
   446         |top l scr fileName|
   445 
   447 
   446 	fileName := '' asValue.
   448         fileName := '' asValue.
   447 
   449 
   448 	top := DialogBox new.
   450         top := DialogBox new.
   449 
   451 
   450 	l := FileSelectionList new.
   452         l := FileSelectionList new.
   451 	l useIndex:false.
   453         l useIndex:false.
   452 	l doubleClickAction:[:name | top okPressed].
   454         l doubleClickAction:[:name | top okPressed].
   453 	l action:[:name | fileName value:name].
   455         l action:[:name | fileName value:name].
   454 	scr := ScrollableView forView:l.
   456         scr := ScrollableView forView:l.
   455 	scr extent:(1.0 @ 300).
   457         scr extent:(1.0 @ 300).
   456 
   458 
   457 	top addComponent:scr.
   459         top addComponent:scr.
   458 	top addAbortButton; addOkButton.
   460         top addAbortButton; addOkButton.
   459 	top openModal.
   461         top openModal.
   460 
   462 
   461 	top accepted ifTrue:[
   463         top accepted ifTrue:[
   462 	    Transcript show:'fileName: '; showCr:fileName value storeString.
   464             Transcript show:'fileName: '; showCr:fileName value storeString.
   463 	]
   465         ]
   464 
   466 
   465     same, looks better, since the height is made larger (not using 
   467     same, looks better, since the height is made larger (not using 
   466     fileLists preferredExtent):
   468     fileLists preferredExtent):
   467 
   469 
   468 	|top l scr fileName|
   470         |top l scr fileName|
   469 
   471 
   470 	fileName := '' asValue.
   472         fileName := '' asValue.
   471 
   473 
   472 	top := DialogBox new.
   474         top := DialogBox new.
   473 
   475 
   474 	l := FileSelectionList new.
   476         l := FileSelectionList new.
   475 	l useIndex:false.
   477         l useIndex:false.
   476 	l doubleClickAction:[:name | top okPressed].
   478         l doubleClickAction:[:name | top okPressed].
   477 	l action:[:name | fileName value:name].
   479         l action:[:name | fileName value:name].
   478 	scr := ScrollableView forView:l.
   480         scr := ScrollableView forView:l.
   479 
   481 
   480 	top addComponent:scr withExtent:300@300.
   482         top addComponent:scr withExtent:300@300.
   481 	top addAbortButton; addOkButton.
   483         top addAbortButton; addOkButton.
   482 	top openModal.
   484         top openModal.
   483 
   485 
   484 	top accepted ifTrue:[
   486         top accepted ifTrue:[
   485 	    Transcript show:'fileName: '; showCr:fileName value storeString.
   487             Transcript show:'fileName: '; showCr:fileName value storeString.
   486 	]
   488         ]
   487 
   489 
   488 
   490 
   489     again, setting the boxes initial size and fixing it
   491     again, setting the boxes initial size and fixing it
   490     (let it ignore the components' preferredExtent):
   492     (let it ignore the components' preferredExtent):
   491 
   493 
   492 	|top fixFrame l scr fileName|
   494         |top fixFrame l scr fileName|
   493 
   495 
   494 	fileName := '' asValue.
   496         fileName := '' asValue.
   495 
   497 
   496 	top := DialogBox new.
   498         top := DialogBox new.
   497 	top extent:300@300.
   499         top extent:300@300.
   498 
   500 
   499 	fixFrame := View new.
   501         fixFrame := View new.
   500 	fixFrame extent:(1.0 @ 300).
   502         fixFrame extent:(1.0 @ 300).
   501 
   503 
   502 	l := FileSelectionList new.
   504         l := FileSelectionList new.
   503 	l useIndex:false.
   505         l useIndex:false.
   504 	l doubleClickAction:[:name | top okPressed].
   506         l doubleClickAction:[:name | top okPressed].
   505 	l action:[:name | fileName value:name].
   507         l action:[:name | fileName value:name].
   506 	scr := ScrollableView forView:l.
   508         scr := ScrollableView forView:l.
   507 	scr origin:0.0@0.0 corner:1.0@1.0.
   509         scr origin:0.0@0.0 corner:1.0@1.0.
   508 	fixFrame add:scr.
   510         fixFrame add:scr.
   509 
   511 
   510 	top addComponent:fixFrame.
   512         top addComponent:fixFrame.
   511 	top addAbortButton; addOkButton.
   513         top addAbortButton; addOkButton.
   512 	top openModal.
   514         top openModal.
   513 
   515 
   514 	top accepted ifTrue:[
   516         top accepted ifTrue:[
   515 	    Transcript show:'fileName: '; showCr:fileName value storeString.
   517             Transcript show:'fileName: '; showCr:fileName value storeString.
   516 	]
   518         ]
   517 
   519 
   518 
   520 
   519    adding a panel with checkBoxes:
   521    adding a panel with checkBoxes:
   520 
   522 
   521 	|top panel b value1 value2 value3 value4|
   523         |top panel b value1 value2 value3 value4|
   522 
   524 
   523 	value1 := true asValue.
   525         value1 := true asValue.
   524 	value2 := false asValue.
   526         value2 := false asValue.
   525 	value3 := false asValue.
   527         value3 := false asValue.
   526 	value4 := true asValue.
   528         value4 := true asValue.
   527 
   529 
   528 	top := DialogBox new.
   530         top := DialogBox new.
   529 	top extent:200@300.
   531         top extent:200@300.
   530 
   532 
   531 	panel := VerticalPanelView new.
   533         panel := VerticalPanelView new.
   532 
   534 
   533 	b := CheckBox on:value1. b label:'check1'.
   535         b := CheckBox on:value1. b label:'check1'.
   534 	panel addSubView:b.
   536         panel addSubView:b.
   535 
   537 
   536 	b := CheckBox on:value2. b label:'check2'.
   538         b := CheckBox on:value2. b label:'check2'.
   537 	panel addSubView:b.
   539         panel addSubView:b.
   538 
   540 
   539 	b := CheckBox on:value3. b label:'check3'.
   541         b := CheckBox on:value3. b label:'check3'.
   540 	panel addSubView:b.
   542         panel addSubView:b.
   541 
   543 
   542 	b := CheckBox on:value4. b label:'check4'.
   544         b := CheckBox on:value4. b label:'check4'.
   543 	panel addSubView:b.
   545         panel addSubView:b.
   544 
   546 
   545 	top addComponent:panel.
   547         top addComponent:panel.
   546 	top addAbortButton; addOkButton.
   548         top addAbortButton; addOkButton.
   547 	top open.
   549         top open.
   548 
   550 
   549 	top accepted ifTrue:[
   551         top accepted ifTrue:[
   550 	    Transcript show:'value1: '; showCr:value1 value.
   552             Transcript show:'value1: '; showCr:value1 value.
   551 	    Transcript show:'value2: '; showCr:value2 value.
   553             Transcript show:'value2: '; showCr:value2 value.
   552 	    Transcript show:'value3: '; showCr:value3 value.
   554             Transcript show:'value3: '; showCr:value3 value.
   553 	    Transcript show:'value4: '; showCr:value4 value.
   555             Transcript show:'value4: '; showCr:value4 value.
   554 	]
   556         ]
   555 
   557 
   556    same, using a more convenient interface:
   558    same, using a more convenient interface:
   557 
   559 
   558 	|box value1 value2 value3 value4|
   560         |box value1 value2 value3 value4|
   559 
   561 
   560 	value1 := true asValue.
   562         value1 := true asValue.
   561 	value2 := false asValue.
   563         value2 := false asValue.
   562 	value3 := false asValue.
   564         value3 := false asValue.
   563 	value4 := true asValue.
   565         value4 := true asValue.
   564 
   566 
   565 	box := DialogBox new.
   567         box := DialogBox new.
   566 	box extent:200@300.
   568         box extent:200@300.
   567 
   569 
   568 	box addCheckBox:'check1' on:value1.
   570         box addCheckBox:'check1' on:value1.
   569 	box addVerticalSpace.
   571         box addVerticalSpace.
   570 	box addCheckBox:'check2' on:value2.
   572         box addCheckBox:'check2' on:value2.
   571 	box addVerticalSpace.
   573         box addVerticalSpace.
   572 	box addCheckBox:'check3' on:value3.
   574         box addCheckBox:'check3' on:value3.
   573 	box addVerticalSpace.
   575         box addVerticalSpace.
   574 	box addCheckBox:'check4' on:value4.
   576         box addCheckBox:'check4' on:value4.
   575 
   577 
   576 	box addAbortButton; addOkButton.
   578         box addAbortButton; addOkButton.
   577 	box open.
   579         box open.
   578 
   580 
   579 	box accepted ifTrue:[
   581         box accepted ifTrue:[
   580 	    Transcript show:'value1: '; showCr:value1 value.
   582             Transcript show:'value1: '; showCr:value1 value.
   581 	    Transcript show:'value2: '; showCr:value2 value.
   583             Transcript show:'value2: '; showCr:value2 value.
   582 	    Transcript show:'value3: '; showCr:value3 value.
   584             Transcript show:'value3: '; showCr:value3 value.
   583 	    Transcript show:'value4: '; showCr:value4 value.
   585             Transcript show:'value4: '; showCr:value4 value.
   584 	]
   586         ]
   585 
   587 
   586 
   588 
   587     adding two panels in a frame:
   589     adding two panels in a frame:
   588 
   590 
   589 	|box frame vPanel1 vPanel2 m1 m2 m3 m4 chk ef|
   591         |box frame vPanel1 vPanel2 m1 m2 m3 m4 chk ef|
   590 
   592 
   591 	box := Dialog new.
   593         box := Dialog new.
   592 	box label:'example'.
   594         box label:'example'.
   593 
   595 
   594 	frame := FramedBox label:'frame'.
   596         frame := FramedBox label:'frame'.
   595 
   597 
   596 	vPanel1 := VerticalPanelView origin:0.0@0.0 corner:0.5@1.0 in:frame.
   598         vPanel1 := VerticalPanelView origin:0.0@0.0 corner:0.5@1.0 in:frame.
   597 	vPanel1 horizontalLayout:#leftSpace.
   599         vPanel1 horizontalLayout:#leftSpace.
   598 	vPanel1 verticalLayout:#top.
   600         vPanel1 verticalLayout:#top.
   599 
   601 
   600 	vPanel2 := VerticalPanelView origin:0.5@0.0 corner:1.0@1.0 in:frame.
   602         vPanel2 := VerticalPanelView origin:0.5@0.0 corner:1.0@1.0 in:frame.
   601 	vPanel2 horizontalLayout:#leftSpace.
   603         vPanel2 horizontalLayout:#leftSpace.
   602 	vPanel2 verticalLayout:#top.
   604         vPanel2 verticalLayout:#top.
   603 
   605 
   604 	m1 := true asValue.
   606         m1 := true asValue.
   605 	m2 := true asValue.
   607         m2 := true asValue.
   606 	m3 := true asValue.
   608         m3 := true asValue.
   607 	m4 := 'hello' asValue.
   609         m4 := 'hello' asValue.
   608 
   610 
   609 	vPanel1 add:(Label label:'check1').
   611         vPanel1 add:(Label label:'check1').
   610 	vPanel1 add:(Label label:'m2').
   612         vPanel1 add:(Label label:'m2').
   611 	vPanel1 add:(Label label:'m3').
   613         vPanel1 add:(Label label:'m3').
   612 	vPanel1 add:(Label label:'enter').
   614         vPanel1 add:(Label label:'enter').
   613 	vPanel1 add:(Label label:'lbl1').
   615         vPanel1 add:(Label label:'lbl1').
   614 	vPanel1 add:(Label label:'lbl2').
   616         vPanel1 add:(Label label:'lbl2').
   615 
   617 
   616 	vPanel2 add:(chk := CheckToggle on:m1). 
   618         vPanel2 add:(chk := CheckToggle on:m1). 
   617 	box makeTabable:chk.
   619         box makeTabable:chk.
   618 
   620 
   619 	vPanel2 add:(chk := CheckToggle on:m2). 
   621         vPanel2 add:(chk := CheckToggle on:m2). 
   620 	box makeTabable:chk.
   622         box makeTabable:chk.
   621 
   623 
   622 	vPanel2 add:(chk := CheckToggle on:m3). 
   624         vPanel2 add:(chk := CheckToggle on:m3). 
   623 	box makeTabable:chk.
   625         box makeTabable:chk.
   624 
   626 
   625 	vPanel2 add:(chk := CheckToggle on:m3). 
   627         vPanel2 add:(chk := CheckToggle on:m3). 
   626 	box makeTabable:chk.
   628         box makeTabable:chk.
   627 
   629 
   628 	vPanel2 add:(chk := CheckToggle on:m3). 
   630         vPanel2 add:(chk := CheckToggle on:m3). 
   629 	box makeTabable:chk.
   631         box makeTabable:chk.
   630 
   632 
   631 	vPanel2 add:(ef := EditField on:m4). 
   633         vPanel2 add:(ef := EditField on:m4). 
   632 	ef immediateAccept:true.
   634         ef immediateAccept:true.
   633 	box makeTabable:ef.
   635         box makeTabable:ef.
   634 
   636 
   635 	box addComponent:frame.
   637         box addComponent:frame.
   636 
   638 
   637 	box addAbortButton; addOkButton.
   639         box addAbortButton; addOkButton.
   638 	box openModal.
   640         box openModal.
   639 	box accepted ifTrue:[
   641         box accepted ifTrue:[
   640 	    Transcript showCr:'accepted with:'.
   642             Transcript showCr:'accepted with:'.
   641 	    Transcript showCr:'   m1: ' , m1 value printString.
   643             Transcript showCr:'   m1: ' , m1 value printString.
   642 	    Transcript showCr:'   m2: ' , m2 value printString.
   644             Transcript showCr:'   m2: ' , m2 value printString.
   643 	    Transcript showCr:'   m3: ' , m3 value printString.
   645             Transcript showCr:'   m3: ' , m3 value printString.
   644 	    Transcript showCr:'   m4: ' , m4 value printString.
   646             Transcript showCr:'   m4: ' , m4 value printString.
   645 	]
   647         ]
   646 
   648 
   647 
   649 
   648 
   650 
   649     a full example:
   651     a full example:
   650 
   652 
   651 	|box warnSTX allowUnderscore immutableArrays logDoits
   653         |box warnSTX allowUnderscore immutableArrays logDoits
   652 	 listOfLanguages listOfStyles styleNames 
   654          listOfLanguages listOfStyles styleNames 
   653 	 frame panel c resourceDir dir |
   655          frame panel c resourceDir dir |
   654 
   656 
   655 	warnSTX := Compiler warnSTXSpecials asValue.
   657         warnSTX := Compiler warnSTXSpecials asValue.
   656 	allowUnderscore := Compiler allowUnderscoreInIdentifier asValue.
   658         allowUnderscore := Compiler allowUnderscoreInIdentifier asValue.
   657 	immutableArrays := Compiler arraysAreImmutable asValue.
   659         immutableArrays := Compiler arraysAreImmutable asValue.
   658 
   660 
   659 	logDoits := Smalltalk logDoits asValue.
   661         logDoits := Smalltalk logDoits asValue.
   660 
   662 
   661 	listOfLanguages := SelectionInList with:#('english'
   663         listOfLanguages := SelectionInList with:#('english'
   662 						  'french'
   664                                                   'french'
   663 						  'german'
   665                                                   'german'
   664 						  'italian'
   666                                                   'italian'
   665 						  'spanish'
   667                                                   'spanish'
   666 						 ).
   668                                                  ).
   667 	listOfLanguages selection:(Language asString).
   669         listOfLanguages selection:(Language asString).
   668 
   670 
   669 
   671 
   670 	resourceDir := Smalltalk getSystemFileName:'resources'.
   672         resourceDir := Smalltalk getSystemFileName:'resources'.
   671 	dir := FileDirectory directoryNamed:resourceDir.
   673         dir := FileDirectory directoryNamed:resourceDir.
   672 
   674 
   673 	styleNames := dir select:[:aFileName | aFileName endsWith:'.style'].
   675         styleNames := dir select:[:aFileName | aFileName endsWith:'.style'].
   674 	styleNames := styleNames collect:[:aFileName | aFileName copyWithoutLast:6].
   676         styleNames := styleNames collect:[:aFileName | aFileName copyWithoutLast:6].
   675 	listOfStyles := SelectionInList with:styleNames sort.
   677         listOfStyles := SelectionInList with:styleNames sort.
   676 	listOfStyles selection:(View defaultStyle asString).
   678         listOfStyles selection:(View defaultStyle asString).
   677 
   679 
   678 	box := Dialog new.
   680         box := Dialog new.
   679 	box label:'Settings'.
   681         box label:'Settings'.
   680 
   682 
   681 	frame := FramedBox label:'Compiler'.
   683         frame := FramedBox label:'Compiler'.
   682 	panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:frame.
   684         panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:frame.
   683 	panel horizontalLayout:#leftSpace.
   685         panel horizontalLayout:#leftSpace.
   684 
   686 
   685 	panel add:((CheckBox on:warnSTX) label:'warn about ST/X language extensions'; resize).
   687         panel add:((CheckBox on:warnSTX) label:'warn about ST/X language extensions'; resize).
   686 	panel add:((CheckBox on:allowUnderscore) label:'allow underscore in identifiers'; resize).
   688         panel add:((CheckBox on:allowUnderscore) label:'allow underscore in identifiers'; resize).
   687 	panel add:((CheckBox on:immutableArrays) label:'literal arrays are immutable'; resize).
   689         panel add:((CheckBox on:immutableArrays) label:'literal arrays are immutable'; resize).
   688 	box addComponent:frame.
   690         box addComponent:frame.
   689 
   691 
   690 	frame := FramedBox label:'Misc'.
   692         frame := FramedBox label:'Misc'.
   691 	panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:frame.
   693         panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:frame.
   692 	panel horizontalLayout:#leftSpace.
   694         panel horizontalLayout:#leftSpace.
   693 
   695 
   694 	panel add:((CheckBox on:logDoits) label:'log doIts in changes file'; resize).
   696         panel add:((CheckBox on:logDoits) label:'log doIts in changes file'; resize).
   695 	box addComponent:frame.
   697         box addComponent:frame.
   696 
   698 
   697 	frame := FramedBox label:'Language'.
   699         frame := FramedBox label:'Language'.
   698 	panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:frame.
   700         panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:frame.
   699 	panel horizontalLayout:#leftSpace.
   701         panel horizontalLayout:#leftSpace.
   700 
   702 
   701 	panel add:((PopUpList on:listOfLanguages) width:0.5).
   703         panel add:((PopUpList on:listOfLanguages) width:0.5).
   702 	box addComponent:frame.
   704         box addComponent:frame.
   703 
   705 
   704 	frame := FramedBox label:'Style'.
   706         frame := FramedBox label:'Style'.
   705 	panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:frame.
   707         panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:frame.
   706 	panel horizontalLayout:#leftSpace.
   708         panel horizontalLayout:#leftSpace.
   707 
   709 
   708 	panel add:((PopUpList on:listOfStyles) width:0.5).
   710         panel add:((PopUpList on:listOfStyles) width:0.5).
   709 	box addComponent:frame.
   711         box addComponent:frame.
   710 
   712 
   711 	box addAbortButton; addOkButton.
   713         box addAbortButton; addOkButton.
   712 	box showAtPointer.
   714         box showAtPointer.
   713 
   715 
   714 	box accepted ifTrue:[
   716         box accepted ifTrue:[
   715 	    Transcript topView withCursor:Cursor wait do:[
   717             Transcript topView withCursor:Cursor wait do:[
   716 		Compiler warnSTXSpecials:warnSTX value.
   718                 Compiler warnSTXSpecials:warnSTX value.
   717 		Compiler allowUnderscoreInIdentifier:allowUnderscore value.
   719                 Compiler allowUnderscoreInIdentifier:allowUnderscore value.
   718 		Compiler arraysAreImmutable:immutableArrays value.
   720                 Compiler arraysAreImmutable:immutableArrays value.
   719 
   721 
   720 		Smalltalk logDoits:logDoits value.
   722                 Smalltalk logDoits:logDoits value.
   721 
   723 
   722 		Transcript showCr:'change language to ' , listOfLanguages selection , ' ...'.
   724                 Transcript showCr:'change language to ' , listOfLanguages selection , ' ...'.
   723 		Smalltalk at:#Language put:listOfLanguages selection asSymbol.
   725                 Smalltalk at:#Language put:listOfLanguages selection asSymbol.
   724 		Smalltalk changed:#Language.
   726                 Smalltalk changed:#Language.
   725 		ResourcePack flushCachedResourcePacks.
   727                 ResourcePack flushCachedResourcePacks.
   726 
   728 
   727 		Transcript showCr:'change style to ' , listOfStyles selection , ' ...'.
   729                 Transcript showCr:'change style to ' , listOfStyles selection , ' ...'.
   728 		View defaultStyle:listOfStyles selection asSymbol.
   730                 View defaultStyle:listOfStyles selection asSymbol.
   729 	    ]
   731             ]
   730 	]
   732         ]
   731 "
   733 "
   732 ! !
   734 ! !
   733 
   735 
   734 !DialogBox class methodsFor:'common dialogs'!
   736 !DialogBox class methodsFor:'common dialogs'!
   735 
   737 
   736 choose:aString labels:buttonLabels values:values default:default
   738 information:aString
   737     "launch a Dialog, which allows user to enter any of buttonLabels.
   739     "launch a Dialog to tell user something"
   738      Returning a corresponding value from the values-array."
   740 
   739 
   741     (InfoBox title:aString) showAtPointer
   740     |box answer idx|
   742 
   741 
   743     "
   742     box := OptionBox title:aString numberOfOptions:buttonLabels size. 
   744      Dialog information:'help'
   743     box buttonTitles:(self classResources array:buttonLabels)
   745     "
   744 	     actions:(values collect:[:val | [answer := val]]).
   746 !
   745     answer := default.
   747 
   746     box buttons last isReturnButton:false.
   748 warn:aString
   747     idx := values indexOf:default.
   749     "launch a Dialog to warn user"
   748     idx ~~ 0 ifTrue:[box defaultButtonIndex:idx].
   750 
   749     box showAtPointer.
   751     (WarningBox title:aString) showAtPointer
   750     box actions:nil.
   752 
   751     ^ answer
   753     "
   752 
   754      Dialog warn:'help'
   753     "
   755     "
   754      Dialog 
   756 ! !
   755 	choose:'choose any' 
   757 
   756 	labels:#('one' 'two' 'three' 'four') 
   758 !DialogBox class methodsFor:'confirmation dialogs'!
   757 	values:#(1 2 3 4) 
       
   758 	default:2 
       
   759     "
       
   760     "
       
   761      Dialog 
       
   762 	choose:'choose any' 
       
   763 	labels:#('one' 'two' 'three' 'four') 
       
   764 	values:#(1 2 3 4) 
       
   765 	default:nil 
       
   766     "
       
   767 !
       
   768 
   759 
   769 confirm:aString
   760 confirm:aString
   770     "launch a Dialog, which allows user to enter yes or no.
   761     "launch a Dialog, which allows user to enter yes or no.
   771      return true for yes, false for no"
   762      return true for yes, false for no"
   772 
   763 
   777     box showAtPointer.
   768     box showAtPointer.
   778     box yesAction:nil noAction:nil.
   769     box yesAction:nil noAction:nil.
   779     ^ answer
   770     ^ answer
   780 
   771 
   781     " 
   772     " 
   782      Dialog confirm:'really ?'
   773      Dialog confirm:'really ?' 
   783     "
   774 
       
   775      Transcript showCr:(
       
   776         Dialog confirm:'are you certain ?'
       
   777      )
       
   778     "
       
   779 
       
   780     "Modified: 27.1.1996 / 14:19:39 / cg"
   784 !
   781 !
   785 
   782 
   786 confirm:aString initialAnswer:what
   783 confirm:aString initialAnswer:what
   787     "launch a Dialog, which allows user to enter yes or no.
   784     "launch a Dialog, which allows user to enter yes or no.
   788      return true for yes, false for no"
   785      return true for yes, false for no.
       
   786      InitialAnswer must be true or false and defines which button is to be
       
   787      the default (i.e. return-) button"
   789 
   788 
   790     |box answer|
   789     |box answer|
   791 
   790 
   792     box := YesNoBox title:aString.
   791     box := YesNoBox title:aString.
   793     box yesAction:[answer := true] noAction:[answer := false].
   792     box yesAction:[answer := true] noAction:[answer := false].
   794     what == false ifTrue:[
   793     what == false ifTrue:[
   795 	box okButton isReturnButton:false.
   794         box okButton isReturnButton:false.
   796 	box acceptReturnAsOK:false.
   795         box acceptReturnAsOK:false.
       
   796         box noButton beReturnButton.
   797     ].
   797     ].
   798     box showAtPointer.
   798     box showAtPointer.
   799     box yesAction:nil noAction:nil.
   799     box yesAction:nil noAction:nil.
   800     ^ answer
   800     ^ answer
   801 
   801 
   802     " 
   802     " 
   803      Dialog confirm:'really ?' initialAnswer:false
   803      Dialog confirm:'really ?' initialAnswer:false
   804     "
   804 
       
   805      Transcript showCr:(
       
   806         Dialog confirm:'are you certain ?' initialAnswer:false
       
   807      )
       
   808 
       
   809      Transcript showCr:(
       
   810         Dialog confirm:'are you certain ?' initialAnswer:true 
       
   811      )
       
   812     "
       
   813 
       
   814     "Modified: 27.1.1996 / 14:24:39 / cg"
   805 !
   815 !
   806 
   816 
   807 confirm:aString yesLabel:yesText noLabel:noText
   817 confirm:aString yesLabel:yesText noLabel:noText
   808     "launch a Dialog, which allows user to enter yes or no.
   818     "launch a Dialog, which allows user to enter yes or no.
   809      return true for yes, false for no.
   819      return true for yes, false for no.
   831 
   841 
   832     |box answer|
   842     |box answer|
   833 
   843 
   834     box := OptionBox title:aString numberOfOptions:3. 
   844     box := OptionBox title:aString numberOfOptions:3. 
   835     box buttonTitles:(self classResources array:
   845     box buttonTitles:(self classResources array:
   836 			#('cancel' 
   846                         #('cancel' 
   837 			  'no' 
   847                           'no' 
   838 			  'yes')
   848                           'yes')
   839 		     )
   849                      )
   840 	     actions:(Array with:[answer := nil]
   850              actions:(Array with:[answer := nil]
   841 			    with:[answer := false] 
   851                             with:[answer := false] 
   842 			    with:[answer := true]
   852                             with:[answer := true]
   843 		     ).
   853                      ).
   844     box showAtPointer.
   854     box showAtPointer.
   845     box actions:nil.
   855     box actions:nil.
   846     ^ answer
   856     ^ answer
   847 
   857 
   848     "
   858     "
   849      Dialog confirmWithCancel:'really ?' nil
   859      Dialog confirmWithCancel:'really ?' 
   850     "
   860 
   851 !
   861      Transcript showCr:(
   852 
   862         Dialog confirmWithCancel:'really ?'
   853 information:aString
   863      )
   854     "launch a Dialog to tell user something"
   864     "
   855 
   865 
   856     (InfoBox title:aString) showAtPointer
   866     "Modified: 27.1.1996 / 14:25:49 / cg"
   857 
   867 ! !
   858     "
   868 
   859      Dialog information:'help'
   869 !DialogBox class methodsFor:'file name dialogs'!
   860     "
   870 
   861 !
   871 requestFileName:titleString
   862 
   872     "launch a Dialog, which allows user to enter a filename.
   863 request:aString 
   873      The box will not allow pressing 'ok' without an entered string.
   864     "launch a Dialog, which allows user to enter something.
   874      Return the pathname string consisting of the full pathname of the filename,
   865      Return the entered string (may be empty string) 
   875      or an empty string (if cancel was pressed)."
   866      or nil (if cancel was pressed)"
   876 
   867 
   877     ^ self requestFileName:titleString 
   868     ^ self 
   878                    default:'file.ext' 
   869 	request:aString 
   879                    version:nil 
   870 	displayAt:nil 
   880                     ifFail:''
   871 	centered:true 
   881 
   872 	action:nil 
   882     "
   873 	initialAnswer:''
   883      Dialog requestFileName:'enter a fileName:' 
   874 
   884      Dialog requestFileName:'enter a fileName:' 
   875     "
   885     "
   876      Dialog 
   886 
   877 	 request:'enter a string:'
   887     "Created: 27.1.1996 / 13:24:35 / cg"
   878     "
       
   879 !
       
   880 
       
   881 request:aString displayAt:aPoint centered:centered action:resultAction initialAnswer:initial
       
   882     "launch a Dialog, which allows user to enter a string.
       
   883      Return the string (may be empty string) or nil (if cancel was pressed)"
       
   884 
       
   885     |box|
       
   886 
       
   887     box := EnterBox title:aString.
       
   888     box initialText:initial.
       
   889     box abortAction:[:val | ^ nil].
       
   890     resultAction isNil ifTrue:[
       
   891 	box action:[:val | ^ val]
       
   892     ] ifFalse:[
       
   893 	box action:[:val | ^ resultAction value:val]
       
   894     ].
       
   895     aPoint notNil ifTrue:[
       
   896 	box showAt:aPoint
       
   897     ] ifFalse:[
       
   898 	box showAtPointer
       
   899     ].
       
   900     ^ ''  "/ used to be nil - but that is incompatible to ST-80
       
   901 
       
   902     "
       
   903      Dialog request:'enter a string:'
       
   904 	      displayAt:0@0
       
   905 	       centered:true
       
   906 		 action:[:result | result printNewline]
       
   907 	  initialAnswer:'the default'
       
   908     "
       
   909 
       
   910     "Created: 7.12.1995 / 23:14:10 / cg"
       
   911 !
       
   912 
       
   913 request:aString displayAt:aPoint initialAnswer:initial
       
   914     "launch a Dialog, which allows user to enter something.
       
   915      Return the entered string (may be empty string) or nil (if cancel was pressed)"
       
   916 
       
   917     ^ self 
       
   918 	request:aString 
       
   919 	displayAt:aPoint 
       
   920 	centered:true 
       
   921 	action:nil 
       
   922 	initialAnswer:initial
       
   923 
       
   924     "
       
   925      Dialog 
       
   926 	 request:'enter a string:' 
       
   927 	 displayAt:(50 @ 50) 
       
   928 	 initialAnswer:'the default' 
       
   929     "
       
   930 !
       
   931 
       
   932 request:aString initialAnswer:initial
       
   933     "launch a Dialog, which allows user to enter something.
       
   934      Return the entered string (may be empty string) or nil (if cancel was pressed)"
       
   935 
       
   936     ^ self 
       
   937 	request:aString 
       
   938 	displayAt:nil 
       
   939 	centered:true 
       
   940 	action:nil 
       
   941 	initialAnswer:initial
       
   942 
       
   943     "
       
   944      Dialog 
       
   945 	 request:'enter a string:' 
       
   946 	 initialAnswer:'the default'  
       
   947     "
       
   948 !
       
   949 
       
   950 request:aString initialAnswer:initial onCancel:cancelAction
       
   951     "launch a Dialog, which allows user to enter something.
       
   952      Return the entered string (may be empty string) 
       
   953      or cancelValue (if cancel was pressed)"
       
   954 
       
   955     |val|
       
   956 
       
   957     val :=self 
       
   958 	request:aString 
       
   959 	displayAt:nil 
       
   960 	centered:true 
       
   961 	action:[:result | ^ result] 
       
   962 	initialAnswer:initial.
       
   963 
       
   964     ^ cancelAction value
       
   965 
       
   966     "
       
   967      Dialog 
       
   968 	 request:'enter a string:' 
       
   969 	 initialAnswer:'the default'  
       
   970 	 onCancel:['foooo']   
       
   971     "
       
   972 !
   888 !
   973 
   889 
   974 requestFileName:titleString default:defaultName
   890 requestFileName:titleString default:defaultName
   975     "launch a Dialog, which allows user to enter a filename.
   891     "launch a Dialog, which allows user to enter a filename.
   976      The box will not allow pressing 'ok' without an entered string.
   892      The box will not allow pressing 'ok' without an entered string.
  1018 
   934 
  1019 requestFileName:titleString default:defaultName version:versionSymbol
   935 requestFileName:titleString default:defaultName version:versionSymbol
  1020     "launch a Dialog, which allows user to enter a filename.
   936     "launch a Dialog, which allows user to enter a filename.
  1021      The box will not allow pressing 'ok' without an entered string.
   937      The box will not allow pressing 'ok' without an entered string.
  1022      Return the pathname string or the empty string if cancel was pressed.
   938      Return the pathname string or the empty string if cancel was pressed.
  1023      The version argument is ignored on Unix, but may at some time in the
   939      The version argument allows validation of the files existance;
  1024      future be used on systems like VMS (which support file versioning)."
   940      it may be any of:
       
   941         #mustBeNew      - fail (return empty string) if the file exists
       
   942         #new            - confirm if the file exists
       
   943         #mustBeOld      - fail if the file does not exist
       
   944         #old            - confirm if the file does not exist
       
   945         #any (other)    - no validation
       
   946     "
  1025 
   947 
  1026     ^ self requestFileName:titleString 
   948     ^ self requestFileName:titleString 
  1027 		   default:defaultName 
   949                    default:defaultName 
  1028 		   version:versionSymbol 
   950                    version:versionSymbol 
  1029 		    ifFail:''
   951                     ifFail:''
  1030 
   952 
  1031     "
   953     "
  1032      Dialog requestFileName:'enter a fileName:'
   954      Dialog requestFileName:'enter a fileName:'
  1033 			default:''
   955                         default:''
  1034 			version:nil
   956                         version:nil   
  1035     "
   957 
       
   958      Dialog requestFileName:'enter a fileName:'
       
   959                         default:''
       
   960                         version:#mustBeNew 
       
   961 
       
   962      Dialog requestFileName:'enter a fileName:'
       
   963                         default:''
       
   964                         version:#new   
       
   965     "
       
   966 
       
   967     "Modified: 27.1.1996 / 13:42:16 / cg"
  1036 !
   968 !
  1037 
   969 
  1038 requestFileName:titleString default:defaultName version:versionSymbol ifFail:failBlock
   970 requestFileName:titleString default:defaultName version:versionSymbol ifFail:failBlock
  1039     "launch a Dialog, which allows user to enter a filename.
   971     "launch a Dialog, which allows user to enter a filename.
  1040      The box will not allow pressing 'ok' without an entered string.
   972      The box will not allow pressing 'ok' without an entered string.
  1041      Return the string or the value of failBlock if cancel was pressed.
   973      Return the string or the value of failBlock if cancel was pressed.
  1042      The version argument is ignored on Unix, but may at some time in the
   974      The version argument allows validation of the files existance;
  1043      future be used on systems like VMS (which support file versioning)."
   975      it may be any of:
       
   976         #mustBeNew      - fail (return empty string) if the file exists
       
   977         #new            - confirm if the file exists
       
   978         #mustBeOld      - fail if the file does not exist
       
   979         #old            - confirm if the file does not exist
       
   980         #any (other)    - no validation
       
   981     "
  1044 
   982 
  1045     |box|
   983     |box|
  1046 
   984 
  1047     box := FileSelectionBox title:titleString.
   985     box := FileSelectionBox title:titleString.
  1048     box initialText:defaultName.
   986     box initialText:defaultName.
  1049     box action:[:name | ^ name].
   987     box action:[:name | 
       
   988         versionSymbol == #mustBeNew ifTrue:[
       
   989             "/ file may not exist
       
   990             name asFilename exists ifTrue:[^ ''].
       
   991         ].
       
   992         versionSymbol == #new ifTrue:[
       
   993             "/ file may not exist
       
   994             name asFilename exists ifTrue:[
       
   995                 (self confirm:(ClassResources string:'''%1'' exists.\\Continue anyway ?' with:box fileName) withCRs)
       
   996                 ifFalse:[^ ''].
       
   997             ].
       
   998         ].
       
   999         versionSymbol == #mustBeOld ifTrue:[
       
  1000             name asFilename exists ifFalse:[^ ''].
       
  1001         ].
       
  1002         versionSymbol == #old ifTrue:[
       
  1003             "/ file may not exist
       
  1004             name asFilename exists ifFalse:[
       
  1005                 (self confirm:(ClassResources string:'''%1'' does not exist yet.\\Continue anyway ?' with:box fileName) withCRs)
       
  1006                 ifFalse:[^ ''].
       
  1007             ].
       
  1008         ].
       
  1009         
       
  1010         ^ name
       
  1011     ].
  1050     box showAtPointer.
  1012     box showAtPointer.
  1051     box action:nil.
  1013     box action:nil.
  1052     ^ failBlock value
  1014     ^ failBlock value
  1053 
  1015 
  1054     "
  1016     "
  1055      Dialog requestFileName:'enter a fileName:'
  1017      Dialog requestFileName:'enter a fileName:'
  1056 			default:''
  1018                         default:''
  1057 			version:nil
  1019                         version:nil
  1058 			 ifFail:['none']   
  1020                          ifFail:['none']   
  1059     "
  1021     "
       
  1022     "
       
  1023      Dialog requestFileName:'enter a fileName:'
       
  1024                         default:''
       
  1025                         version:#old 
       
  1026                          ifFail:['none']   
       
  1027     "
       
  1028 
       
  1029     "Modified: 27.1.1996 / 13:35:37 / cg"
       
  1030 !
       
  1031 
       
  1032 requestNewFileName:titleString default:defaultName
       
  1033     "launch a Dialog, which allows user to enter a filename.
       
  1034      We expect a new files (i.e. nonexisting) name to be enterred,
       
  1035      and confirm if it already exists.
       
  1036      The box will not allow pressing 'ok' without an entered string.
       
  1037      Return the pathname string consisting of the full pathname of the filename,
       
  1038      or an empty string (if cancel was pressed)."
       
  1039 
       
  1040     ^ self requestFileName:titleString 
       
  1041                    default:defaultName 
       
  1042                    version:#new 
       
  1043                     ifFail:''
       
  1044 
       
  1045     "
       
  1046      Dialog requestNewFileName:'enter a fileName:' default:''  
       
  1047     "
       
  1048 
       
  1049     "Modified: 27.1.1996 / 13:44:13 / cg"
       
  1050 ! !
       
  1051 
       
  1052 !DialogBox class methodsFor:'fill in the blank dialogs'!
       
  1053 
       
  1054 request:aString 
       
  1055     "launch a Dialog, which allows user to enter something.
       
  1056      Return the entered string (may be empty string) 
       
  1057      or the empty string (if cancel was pressed)"
       
  1058 
       
  1059     ^ self 
       
  1060         request:aString 
       
  1061         displayAt:nil 
       
  1062         centered:false 
       
  1063         action:nil 
       
  1064         initialAnswer:''
       
  1065 
       
  1066     "
       
  1067      Dialog 
       
  1068          request:'enter a string:' 
       
  1069     "
       
  1070 
       
  1071     "Modified: 27.1.1996 / 14:44:30 / cg"
       
  1072 !
       
  1073 
       
  1074 request:aString displayAt:aPoint centered:centered action:resultAction initialAnswer:initial
       
  1075     "launch a Dialog, which allows user to enter a string.
       
  1076      If aPoint is nonNil, the box is shown there, optionally centered.
       
  1077      If it is nil, it is shown at the current pointer position or at the screen center.
       
  1078      Return the string or an empty string (if cancel was pressed)"
       
  1079 
       
  1080     ^ self
       
  1081         request:aString 
       
  1082         displayAt:aPoint 
       
  1083         centered:centered 
       
  1084         action:resultAction 
       
  1085         initialAnswer:initial
       
  1086         onCancel:''
       
  1087 
       
  1088     "
       
  1089      centered around 200@200:
       
  1090 
       
  1091          Dialog 
       
  1092             request:'enter a string:'
       
  1093             displayAt:200@200
       
  1094             centered:true
       
  1095             action:[:result | result printNewline]
       
  1096             initialAnswer:'the default'
       
  1097 
       
  1098 
       
  1099      origin at 200@200:
       
  1100 
       
  1101          Dialog 
       
  1102             request:'enter a string:'
       
  1103             displayAt:200@200
       
  1104             centered:false 
       
  1105             action:[:result | result printNewline]
       
  1106             initialAnswer:'the default'
       
  1107 
       
  1108      under mouse pointer:
       
  1109 
       
  1110          Dialog 
       
  1111             request:'enter a string:'
       
  1112             displayAt:nil
       
  1113             centered:false 
       
  1114             action:[:result | result printNewline]
       
  1115             initialAnswer:'the default'
       
  1116 
       
  1117      centered on the screen:
       
  1118 
       
  1119          Dialog 
       
  1120             request:'enter a string:'
       
  1121             displayAt:nil
       
  1122             centered:true 
       
  1123             action:[:result | result printNewline]
       
  1124             initialAnswer:'the default'
       
  1125     "
       
  1126 
       
  1127     "Created: 7.12.1995 / 23:14:10 / cg"
       
  1128     "Modified: 27.1.1996 / 14:44:08 / cg"
       
  1129 !
       
  1130 
       
  1131 request:aString displayAt:aPoint centered:centered action:resultAction initialAnswer:initial onCancel:cancelValue
       
  1132     "launch a Dialog, which allows user to enter a string.
       
  1133      If aPoint is nonNil, the box is shown there, optionally centered.
       
  1134      If it is nil, it is shown at the current pointer position or at the screen center.
       
  1135      Return the string or the value of cancelValue (if cancel was pressed)"
       
  1136 
       
  1137     |box|
       
  1138 
       
  1139     box := EnterBox title:aString.
       
  1140     box initialText:initial.
       
  1141     box abortAction:[:val | ^ cancelValue value].
       
  1142     resultAction isNil ifTrue:[
       
  1143         box action:[:val | ^ val]
       
  1144     ] ifFalse:[
       
  1145         box action:[:val | ^ resultAction value:val]
       
  1146     ].
       
  1147     aPoint notNil ifTrue:[
       
  1148         box showAt:aPoint center:centered
       
  1149     ] ifFalse:[
       
  1150         centered ifTrue:[
       
  1151             box showAtCenter
       
  1152         ] ifFalse:[
       
  1153             box showAtPointer
       
  1154         ]
       
  1155     ].
       
  1156     ^ cancelValue value.
       
  1157 
       
  1158     "
       
  1159      at topLeft (centering is suppressed, to make the box fully visible)    
       
  1160          Dialog 
       
  1161             request:'enter a string:'
       
  1162             displayAt:0@0
       
  1163             centered:true
       
  1164             action:[:result | result printNewline]
       
  1165             initialAnswer:'the default'
       
  1166             onCancel:#foo
       
  1167 
       
  1168      centered around 200@200:
       
  1169 
       
  1170          Dialog 
       
  1171             request:'enter a string:'
       
  1172             displayAt:200@200
       
  1173             centered:true
       
  1174             action:[:result | result printNewline]
       
  1175             initialAnswer:'the default'
       
  1176             onCancel:#foo
       
  1177 
       
  1178      topLeft of box at 200@200:
       
  1179 
       
  1180          Dialog 
       
  1181             request:'enter a string:'
       
  1182             displayAt:200@200
       
  1183             centered:false 
       
  1184             action:[:result | result printNewline]
       
  1185             initialAnswer:'the default'
       
  1186             onCancel:#foo
       
  1187 
       
  1188      under mouse pointer:
       
  1189 
       
  1190          Dialog 
       
  1191             request:'enter a string:'
       
  1192             displayAt:nil
       
  1193             centered:false 
       
  1194             action:[:result | result printNewline]
       
  1195             initialAnswer:'the default'
       
  1196             onCancel:#foo
       
  1197 
       
  1198      centered on the screen:
       
  1199 
       
  1200          Dialog 
       
  1201             request:'enter a string:'
       
  1202             displayAt:nil
       
  1203             centered:true 
       
  1204             action:[:result | result printNewline]
       
  1205             initialAnswer:'the default'
       
  1206             onCancel:#foo
       
  1207     "
       
  1208 
       
  1209     "Created: 7.12.1995 / 23:14:10 / cg"
       
  1210     "Modified: 27.1.1996 / 14:41:40 / cg"
       
  1211 !
       
  1212 
       
  1213 request:aString displayAt:aPoint initialAnswer:initial
       
  1214     "launch a Dialog, which allows user to enter something.
       
  1215      The boxes topLeft is placed at aPoint, or under the mouse pointer (if aPoint is nil).
       
  1216      Return the entered string (may be empty string) or nil (if cancel was pressed)"
       
  1217 
       
  1218     ^ self 
       
  1219         request:aString 
       
  1220         displayAt:aPoint 
       
  1221         centered:false 
       
  1222         action:nil 
       
  1223         initialAnswer:initial
       
  1224 
       
  1225     "
       
  1226      Dialog 
       
  1227          request:'enter a string:' 
       
  1228          displayAt:(250 @ 250) 
       
  1229          initialAnswer:'the default' 
       
  1230     "
       
  1231 
       
  1232     "Modified: 27.1.1996 / 14:45:47 / cg"
       
  1233 !
       
  1234 
       
  1235 request:aString initialAnswer:initial
       
  1236     "launch a Dialog, which allows user to enter something.
       
  1237      Return the entered string (may be empty string) or nil (if cancel was pressed)"
       
  1238 
       
  1239     ^ self 
       
  1240         request:aString 
       
  1241         displayAt:nil 
       
  1242         centered:false 
       
  1243         action:nil 
       
  1244         initialAnswer:initial
       
  1245 
       
  1246     "
       
  1247      Dialog 
       
  1248          request:'enter a string:' 
       
  1249          initialAnswer:'the default'  
       
  1250     "
       
  1251 
       
  1252     "Modified: 27.1.1996 / 14:44:22 / cg"
       
  1253 !
       
  1254 
       
  1255 request:aString initialAnswer:initial onCancel:cancelAction
       
  1256     "launch a Dialog, which allows user to enter something.
       
  1257      Return the entered string (may be empty string) 
       
  1258      or cancelValue (if cancel was pressed)"
       
  1259 
       
  1260     self 
       
  1261         request:aString 
       
  1262         displayAt:nil 
       
  1263         centered:false 
       
  1264         action:[:result | ^ result] 
       
  1265         initialAnswer:initial.
       
  1266 
       
  1267     ^ cancelAction value
       
  1268 
       
  1269     "
       
  1270      Dialog 
       
  1271          request:'enter a string:' 
       
  1272          initialAnswer:'the default'  
       
  1273          onCancel:['foooo']   
       
  1274     "
       
  1275 
       
  1276     "Modified: 27.1.1996 / 14:46:00 / cg"
       
  1277 !
       
  1278 
       
  1279 request:aString onCancel:cancelAction
       
  1280     "launch a Dialog, which allows user to enter something.
       
  1281      Return the entered string (may be empty string) 
       
  1282      or the value of cancelAction (if cancel was pressed)."
       
  1283 
       
  1284     self 
       
  1285         request:aString 
       
  1286         displayAt:nil 
       
  1287         centered:false 
       
  1288         action:[:result | ^ result] 
       
  1289         initialAnswer:''.
       
  1290 
       
  1291     ^ cancelAction value
       
  1292 
       
  1293     "
       
  1294      Dialog 
       
  1295          request:'enter a string:'
       
  1296          onCancel:nil       
       
  1297     "
       
  1298 
       
  1299     "Created: 27.1.1996 / 14:31:45 / cg"
       
  1300     "Modified: 27.1.1996 / 14:46:10 / cg"
  1060 !
  1301 !
  1061 
  1302 
  1062 requestPassword:aString 
  1303 requestPassword:aString 
  1063     "launch a Dialog, which allows user to enter something invisibly.
  1304     "launch a Dialog, which allows user to enter something invisibly.
  1064      Return the entered string (may be empty string) 
  1305      Return the entered string (may be empty string) 
  1070      Dialog 
  1311      Dialog 
  1071 	 requestPassword:'enter secret:'
  1312 	 requestPassword:'enter secret:'
  1072     "
  1313     "
  1073 
  1314 
  1074     "Created: 17.11.1995 / 09:45:21 / cg"
  1315     "Created: 17.11.1995 / 09:45:21 / cg"
  1075 !
  1316 ! !
  1076 
  1317 
  1077 warn:aString
  1318 !DialogBox class methodsFor:'multiple choice dialogs'!
  1078     "launch a Dialog to warn user"
  1319 
  1079 
  1320 choose:aString fromList:list values:listValues buttons:buttonLabels values:buttonValues lines:maxLines cancel:cancelBlock
  1080     (WarningBox title:aString) showAtPointer
  1321     "launch a Dialog showing the message and list.
  1081 
  1322      The user can select an item and click ok; in this case, the corresponding value
  1082     "
  1323      from listValues is returned (doubleclick works as well). 
  1083      Dialog warn:'help'
  1324      The list may be suppressed (if the list arg is nil).
  1084     "
  1325      Below the list, an optional row of buttons is shown, which can also be
       
  1326      clicked upon, and a corresponding value from buttonValues is returned.
       
  1327      If cancel is pressed, the value of cancelBlock is returned.
       
  1328      Pressing ok without a selection is treated like cancel."
       
  1329 
       
  1330     |box listView panel answer idx|
       
  1331 
       
  1332     box := Dialog new.
       
  1333     (box addTextLabel:aString) adjust:#left.
       
  1334 
       
  1335     list notNil ifTrue:[
       
  1336         listView := ScrollableView for:SelectionInListView.
       
  1337         listView list:list.
       
  1338         listView doubleClickAction:[:line | box hide. ^ listValues at:line].
       
  1339 "/        list height:(list font height * maxLines).
       
  1340         box addComponent:listView.
       
  1341     ].
       
  1342 
       
  1343     buttonLabels notNil ifTrue:[
       
  1344         panel := HorizontalPanelView new.
       
  1345         panel horizontalLayout:#fit.
       
  1346         buttonLabels keysAndValuesDo:[:index :label |
       
  1347             |b|
       
  1348 
       
  1349             b := Button label:label.
       
  1350             b action:[box hide. ^ buttonValues at:index].
       
  1351             panel add:b.
       
  1352         ].
       
  1353         box addComponent:panel.
       
  1354     ].
       
  1355     box addAbortButton.
       
  1356     list notNil ifTrue:[box addOkButton].
       
  1357     box showAtPointer.
       
  1358     box accepted ifTrue:[
       
  1359         (answer := listView selection) notNil ifTrue:[
       
  1360             ^ listValues at:answer
       
  1361         ]
       
  1362     ].
       
  1363     ^ cancelBlock value
       
  1364 
       
  1365     "
       
  1366      full example:
       
  1367 
       
  1368          Transcript showCr:(
       
  1369              Dialog 
       
  1370                 choose:'choose any' 
       
  1371                 fromList:#('one' 'two' 'three' 'four') 
       
  1372                 values:#(1 2 3 4) 
       
  1373                 buttons:#('five' 'six' 'seven')
       
  1374                 values:#(5 6 7)
       
  1375                 lines:4
       
  1376                 cancel:nil
       
  1377          )
       
  1378 
       
  1379 
       
  1380      no buttons:
       
  1381 
       
  1382          Transcript showCr:(
       
  1383              Dialog 
       
  1384                 choose:'choose any' 
       
  1385                 fromList:#('one' 'two' 'three' 'four') 
       
  1386                 values:#(1 2 3 4) 
       
  1387                 buttons:nil
       
  1388                 values:nil
       
  1389                 lines:4
       
  1390                 cancel:nil
       
  1391          )
       
  1392 
       
  1393 
       
  1394      no list:
       
  1395 
       
  1396          Transcript showCr:(
       
  1397              Dialog 
       
  1398                 choose:'choose any' 
       
  1399                 fromList:nil
       
  1400                 values:nil
       
  1401                 buttons:#('one' 'two' 'three' 'four') 
       
  1402                 values:#(1 2 3 4) 
       
  1403                 lines:4
       
  1404                 cancel:nil
       
  1405          )
       
  1406 
       
  1407 
       
  1408       full including cancel value:
       
  1409 
       
  1410          Transcript showCr:(
       
  1411              Dialog 
       
  1412                 choose:'choose example' 
       
  1413                 fromList:#('one' 'two' 'three' 'four') 
       
  1414                 values:#(1 2 3 4) 
       
  1415                 buttons:#('five' 'six' 'seven')
       
  1416                 values:#(5 6 7)
       
  1417                 lines:4
       
  1418                 cancel:[Transcript flash. #aborted]
       
  1419          )
       
  1420 
       
  1421 
       
  1422      degenerated:
       
  1423 
       
  1424          Transcript showCr:(
       
  1425              Dialog 
       
  1426                 choose:'choose any' 
       
  1427                 fromList:nil
       
  1428                 values:nil
       
  1429                 buttons:nil
       
  1430                 values:nil
       
  1431                 lines:nil 
       
  1432                 cancel:nil
       
  1433          )
       
  1434 
       
  1435 
       
  1436     "
       
  1437 
       
  1438     "Modified: 27.1.1996 / 14:17:27 / cg"
       
  1439 !
       
  1440 
       
  1441 choose:aString fromList:list values:listValues lines:maxLines cancel:cancelBlock
       
  1442     "launch a Dialog showing the message and list.
       
  1443      The user can select an item and click ok; in this case, the corresponding value
       
  1444      from listValues is returned (doubleclick works as well).
       
  1445      If cancel is pressed, the value of cancelBlock is returned.
       
  1446      Pressing ok without a selection is treated like cancel."
       
  1447 
       
  1448     ^ self
       
  1449         choose:aString 
       
  1450         fromList:list 
       
  1451         values:listValues
       
  1452         buttons:nil
       
  1453         values:nil
       
  1454         lines:maxLines
       
  1455         cancel:cancelBlock
       
  1456 
       
  1457     "
       
  1458      Transcript showCr:(
       
  1459          Dialog 
       
  1460             choose:'choose any' 
       
  1461             fromList:#('one' 'two' 'three' 'four') 
       
  1462             values:#(1 2 3 4) 
       
  1463             lines:4
       
  1464             cancel:nil
       
  1465      )
       
  1466 
       
  1467      Transcript showCr:(
       
  1468          Dialog 
       
  1469             choose:'choose example' 
       
  1470             fromList:#('one' 'two' 'three' 'four') 
       
  1471             values:#(1 2 3 4) 
       
  1472             lines:4
       
  1473             cancel:[Transcript flash. #aborted]
       
  1474      )
       
  1475     "
       
  1476 
       
  1477     "Modified: 27.1.1996 / 14:17:07 / cg"
       
  1478 !
       
  1479 
       
  1480 choose:aString labels:buttonLabels values:values default:default
       
  1481     "launch a Dialog, which allows user to enter any of buttonLabels.
       
  1482      Returning a corresponding value from the values-array.
       
  1483      The default entries button is marked as a return button and entering
       
  1484      return will choose that value.
       
  1485      For a good userInterface style, we recommend this being the last
       
  1486      entry (to make the right-most button the default button)."
       
  1487 
       
  1488     |box answer idx|
       
  1489 
       
  1490     box := OptionBox title:aString numberOfOptions:buttonLabels size. 
       
  1491     box buttonTitles:(self classResources array:buttonLabels)
       
  1492              actions:(values collect:[:val | [answer := val]]).
       
  1493     answer := default.
       
  1494     box buttons last isReturnButton:false.
       
  1495     idx := values indexOf:default.
       
  1496     idx ~~ 0 ifTrue:[box defaultButtonIndex:idx].
       
  1497     box showAtPointer.
       
  1498     box actions:nil.
       
  1499     ^ answer
       
  1500 
       
  1501     "no good style (default button is not the rightmost one)
       
  1502 
       
  1503      Dialog 
       
  1504         choose:'choose any' 
       
  1505         labels:#('one' 'two' 'three' 'four') 
       
  1506         values:#(1 2 3 4) 
       
  1507         default:2 
       
  1508 
       
  1509      Dialog 
       
  1510         choose:'choose any' 
       
  1511         labels:#('cancel' 'foo' 'bar' 'baz') 
       
  1512         values:#(nil foo bar baz) 
       
  1513         default:#baz     
       
  1514 
       
  1515       Dialog 
       
  1516         choose:'choose any' 
       
  1517         labels:#('one' 'two' 'three' 'four') 
       
  1518         values:#(1 2 3 4) 
       
  1519         default:nil 
       
  1520     "
       
  1521 
       
  1522     "Modified: 27.1.1996 / 13:48:17 / cg"
  1085 ! !
  1523 ! !
  1086 
  1524 
  1087 !DialogBox methodsFor:'accessing'!
  1525 !DialogBox methodsFor:'accessing'!
  1088 
  1526 
  1089 abortText:aString
  1527 abortText:aString
  2022 !
  2460 !
  2023 
  2461 
  2024 keyPress:aKey x:x y:y
  2462 keyPress:aKey x:x y:y
  2025     "return-key dublicates ok-function if acceptReturnAsOK is true"
  2463     "return-key dublicates ok-function if acceptReturnAsOK is true"
  2026 
  2464 
  2027     acceptReturnAsOK ifTrue:[
  2465     (aKey == #Return) ifTrue:[
  2028 	(aKey == #Return) ifTrue:[^ self okPressed]
  2466         (okButton notNil and:[okButton isReturnButton]) ifTrue:[
       
  2467             ^ self okPressed
       
  2468         ].
       
  2469         (abortButton notNil and:[abortButton isReturnButton]) ifTrue:[
       
  2470             ^ self abortPressed
       
  2471         ].
  2029     ].
  2472     ].
  2030     super keyPress:aKey x:x y:y
  2473     super keyPress:aKey x:x y:y
       
  2474 
       
  2475     "Modified: 27.1.1996 / 14:23:16 / cg"
  2031 !
  2476 !
  2032 
  2477 
  2033 lastFieldLeft
  2478 lastFieldLeft
  2034     "if the dialog involves input fields, this is called
  2479     "if the dialog involves input fields, this is called
  2035      when the last field is left by Return-key or NextField-key"
  2480      when the last field is left by Return-key or NextField-key"
  2062 ! !
  2507 ! !
  2063 
  2508 
  2064 !DialogBox class methodsFor:'documentation'!
  2509 !DialogBox class methodsFor:'documentation'!
  2065 
  2510 
  2066 version
  2511 version
  2067     ^ '$Header: /cvs/stx/stx/libwidg/DialogBox.st,v 1.35 1996-01-26 13:04:47 ah Exp $'
  2512     ^ '$Header: /cvs/stx/stx/libwidg/DialogBox.st,v 1.36 1996-01-27 14:16:15 cg Exp $'
  2068 ! !
  2513 ! !