OptionBox.st
changeset 97 cbf495fe3b64
parent 95 7535cfca9509
child 110 eb59f6e31e84
--- a/OptionBox.st	Tue Feb 28 22:52:21 1995 +0100
+++ b/OptionBox.st	Mon Mar 06 20:29:54 1995 +0100
@@ -21,7 +21,7 @@
 COPYRIGHT (c) 1991 by Claus Gittinger
 	     All Rights Reserved
 
-$Header: /cvs/stx/stx/libwidg/OptionBox.st,v 1.13 1995-02-27 10:40:16 claus Exp $
+$Header: /cvs/stx/stx/libwidg/OptionBox.st,v 1.14 1995-03-06 19:29:08 claus Exp $
 '!
 
 !OptionBox class methodsFor:'documentation'!
@@ -42,7 +42,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libwidg/OptionBox.st,v 1.13 1995-02-27 10:40:16 claus Exp $
+$Header: /cvs/stx/stx/libwidg/OptionBox.st,v 1.14 1995-03-06 19:29:08 claus Exp $
 "
 !
 
@@ -51,9 +51,9 @@
     OptionBoxes are like YesNoBoxes but with as many buttons as you like;
     this will finally be a superclass of WarnBox and YesNoBox - or maybe merged
     all into DialogBox..
-    Used for multiway questions.
+    Use them for multiway questions.
     For a consistent user interface, the rightmost button is the default return
-    button.
+    button (i.e. pressing return in the box performs this buttons function).
 
     examples:
 
@@ -63,10 +63,37 @@
 	box showAtPointer
 
 
+
 	|box|
 	box := OptionBox title:'hello' numberOfOptions:3.
 	box buttonTitles:#('one' 'two' 'three').
 	box showAtPointer
+
+
+     performing an action:
+
+	|box|
+	box := OptionBox title:'hello' numberOfOptions:3.
+	box buttonTitles:#('one' 'two' 'three').
+	box action:[:which | Transcript show:'button ';
+					show: which;
+					showCr:' was pressed'].
+	box showAtPointer
+
+
+     returning a value:
+
+	|what|
+	what := OptionBox 
+		      request:('text has not been accepted.\\Your modifications will be lost when continuing.') withCRs
+		      label:' Attention'
+		      form:(WarningBox iconBitmap)
+		      buttonLabels:#('abort' 'accept' 'continue')
+		      values:#(#abort #accept #continue).
+
+	...
+	someObject perform:what.
+	...
 "
 ! !
 
@@ -86,7 +113,7 @@
     ^ nil
 
     "
-     OptionBox request:'select'
+     OptionBox request:'please select'
 	       label:'select any'
 	       form:(WarningBox iconBitmap)
 	       buttonLabels:#('one' 'two' 'three')
@@ -110,27 +137,24 @@
 
 !OptionBox methodsFor:'accessing'!
 
-title:aString numberOfOptions:nOptions
-    "set the boxes title and number of options"
-
-    aString ~= textLabel label ifTrue:[
-	textLabel label:aString.
-	textLabel resize.
-    ].
-    buttons grow:nOptions.
-    actions grow:nOptions
-!
-
 title:aString
     "set the boxes title"
 
     aString ~= textLabel label ifTrue:[
 	textLabel label:aString withoutSeparators.
 	textLabel resize.
-	self resize
+	shown ifTrue:[self resize]
     ]
 !
 
+title:aString numberOfOptions:nOptions
+    "set the boxes title and number of options"
+
+    self title:aString.
+    buttons grow:nOptions.
+    actions grow:nOptions
+!
+
 formLabel
     "return the label-view which displays a bitmap"
 
@@ -165,17 +189,13 @@
 buttonTitles:titles
     "set the button titles"
 
-    |index|
+    titles keysAndValuesDo:[:index :aString |
+	|b|
 
-    index := 1.
-    titles do:[:aString |
-	(buttons at:index) label:aString.
-	(buttons at:index) resize.
-	index := index + 1
+	(b := buttons at:index) label:aString.
+	b resize.
     ].
-    shown ifTrue:[
-	self resize
-    ]
+    shown ifTrue:[self resize]
 !
 
 actions:actionBlocks
@@ -188,12 +208,9 @@
     "define a single the action for all buttons.
      The action will be evaluated with the button index as argument."
 
-    1 to:buttons size do:[:index |
-	|button|
-
-	button := buttons at:index.
+    buttons keysAndValuesDo:[:index :button |
 	button action:[
-		       (buttons at:index) turnOffWithoutRedraw.
+		       button turnOffWithoutRedraw.
 		       self hide.
 		       actionBlock value:index
 		      ]
@@ -205,9 +222,6 @@
 
     self buttonTitles:titles.
     actions := actionBlocks.
-    shown ifTrue:[
-	self resize
-    ]
 ! !
 
 !OptionBox methodsFor:'initializing'!
@@ -292,10 +306,11 @@
     prefPanel := buttonPanel preferedExtent.
     w := w1 max:prefPanel x.
 
-    maxH := 0.
-    buttons do:[:button |
-	maxH := maxH max:(button preferedExtent y)
-    ].
+"/    maxH := 0.
+"/    buttons do:[:button |
+"/        maxH := maxH max:(button preferedExtent y)
+"/    ].
+    maxH := prefPanel y.
 
     h := ViewSpacing
 	 + ((formLabel height) max:(textLabel height))