--- a/DialogBox.st Fri May 12 20:25:18 1995 +0200
+++ b/DialogBox.st Wed May 17 14:26:27 1995 +0200
@@ -14,8 +14,8 @@
ModalBox subclass:#DialogBox
instanceVariableNames:'buttonPanel okButton okAction abortButton abortAction
- acceptReturnAsOK yPosition leftIndent addedComponents
- inputFieldGroup acceptOnLeave accepted tabableElements'
+ acceptReturnAsOK yPosition leftIndent rightIndent bindings addedComponents
+ inputFieldGroup acceptOnLeave acceptValue tabableElements'
classVariableNames:''
poolDictionaries:''
category:'Views-DialogBoxes'
@@ -25,7 +25,7 @@
version
"
-$Header: /cvs/stx/stx/libwidg/DialogBox.st,v 1.13 1995-05-10 02:29:19 claus Exp $
+$Header: /cvs/stx/stx/libwidg/DialogBox.st,v 1.14 1995-05-17 12:24:44 claus Exp $
"
!
@@ -64,7 +64,9 @@
yPosisition <Integer> current y position when adding components
- leftIndent <Integer> x position to use when adding components
+ leftIndent <Integer> left inset to use when adding components
+
+ rightIndent <Integer> right inset to use when adding components
addedComponents <Collection> programmatically added components
@@ -76,8 +78,10 @@
the last field is left. If false, the ok
button must be pressed to close the box.
- accepted <Boolean> after close: true if box was accepted
- (i.e. ok-Button was pressed)
+ acceptedValue v(<Boolean>) valueHolder on a boolean
+ after close: holds true if box was accepted
+ (i.e. ok-Button was pressed), false if box was
+ closed via cancel or window manager.
For compatibility with ST-80, this class is also available under
@@ -508,10 +512,10 @@
logDoits := Smalltalk logDoits asValue.
listOfLanguages := SelectionInList with:#('english'
+ 'french'
'german'
- 'french'
+ 'italian'
'spanish'
- 'italian'
).
listOfLanguages selection:(Language asString).
@@ -521,7 +525,7 @@
styleNames := dir select:[:aFileName | aFileName endsWith:'.style'].
styleNames := styleNames collect:[:aFileName | aFileName copyWithoutLast:6].
- listOfStyles := SelectionInList with:styleNames.
+ listOfStyles := SelectionInList with:styleNames sort.
listOfStyles selection:(View defaultStyle asString).
box := Dialog new.
@@ -547,14 +551,14 @@
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:frame.
panel horizontalLayout:#leftSpace.
- panel add:(PopUpList on:listOfLanguages).
+ panel add:((PopUpList on:listOfLanguages) width:0.5).
box addComponent:frame.
frame := FramedBox label:'Style'.
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:frame.
panel horizontalLayout:#leftSpace.
- panel add:(PopUpList on:listOfStyles).
+ panel add:((PopUpList on:listOfStyles) width:0.5).
box addComponent:frame.
box addAbortButton; addOkButton.
@@ -577,7 +581,6 @@
View defaultStyle:listOfStyles selection asSymbol.
]
]
-
"
!
@@ -595,7 +598,7 @@
"
! !
-!DialogBox class methodsFor:'startup'!
+!DialogBox class methodsFor:'common dialogs'!
request:aString
"launch a Dialog, which allows user to enter something.
@@ -857,8 +860,12 @@
!DialogBox methodsFor:'user actions'!
-accept
- "let all components accept (i.e. update their model from the values)"
+doAccept
+ "let all components accept (i.e. update their model from the values),
+ then set my accept value to true.
+ This is confusing: this method was originally called #accept,
+ but renamed for compatibility with ST-80, where #accept returns the
+ accept-valueHolder (which looks like a bad name to me ...)."
addedComponents notNil ifTrue:[
addedComponents do:[:aComponent |
@@ -867,7 +874,7 @@
]
].
].
- accepted := true.
+ acceptValue value:true.
!
lastFieldLeft
@@ -875,25 +882,26 @@
when the last field is left by Return-key or NextField-key"
acceptOnLeave ifTrue:[
- accepted := true.
+ acceptValue value:true.
self okPressed
].
!
okPressed
- "user pressed ok-button; make myself invisible and if an action was
- specified do it"
+ "sent by the okButton; user pressed ok-button
+ - make myself invisible and if an action was specified do it"
okButton notNil ifTrue:[okButton turnOffWithoutRedraw].
- self accept.
+ self doAccept.
self hideAndEvaluate:okAction.
!
abortPressed
- "user pressed abort button - hide myself and evaluate okAction"
+ "sent by the cancel button; user pressed abort button
+ - hide myself and evaluate okAction"
abortButton turnOffWithoutRedraw.
- accepted := false.
+ acceptValue value:false.
self hideAndEvaluate:abortAction
!
@@ -933,17 +941,6 @@
^ self addButton:okButton.
!
-XXaddOkButton:action
- "create an okButton - to be sent from redefined initialize
- methods in subclasses or when creating a box programmatically."
-
- okButton := Button okButton.
- action notNil ifTrue:[okButton action:action].
- okButton model:self; change:#okPressed.
- okButton isReturnButton:acceptReturnAsOK.
- ^ self addButton:okButton.
-!
-
addOkButton
"create an okButton - to be sent from redefined initialize
methods in subclasses or when creating a box programmatically.
@@ -987,8 +984,8 @@
aComponent height:height.
aComponent origin:0.0@yPosition;
width:1.0;
- leftInset:leftIndent+ViewSpacing;
- rightInset:ViewSpacing.
+ leftInset:leftIndent;
+ rightInset:rightIndent.
yPosition := yPosition + aComponent height.
^ aComponent
!
@@ -1001,7 +998,7 @@
aComponent extent:ext.
aComponent origin:0.0@yPosition;
leftInset:leftIndent;
- rightInset:ViewSpacing.
+ rightInset:rightIndent.
yPosition := yPosition + aComponent height.
^ aComponent
!
@@ -1170,6 +1167,12 @@
"
!
+addHorizontalLine
+ "add a horizontal line as separator"
+
+ self addComponent:(Separator new extent:1.0 @ 5).
+!
+
addVerticalSpace
"add a default vertical space (1 mm)"
@@ -1201,6 +1204,12 @@
will be located)."
leftIndent := aNumber.
+!
+
+rightIndent:aNumber
+ "set the right indent"
+
+ rightIndent := aNumber.
! !
!DialogBox methodsFor:'initialization'!
@@ -1211,7 +1220,7 @@
super initialize.
label := 'Dialog'.
- accepted := false.
+ acceptValue := false asValue.
mm := ViewSpacing.
@@ -1227,7 +1236,7 @@
layout:#spread.
yPosition := ViewSpacing.
- leftIndent := 0.
+ leftIndent := rightIndent := ViewSpacing.
"
|b|
@@ -1294,10 +1303,10 @@
!DialogBox methodsFor:'queries'!
accepted
- "after the box has closed: return true if accepted,
- false if canceled"
+ "after the box has closed:
+ return true if accepted, false if canceled"
- ^ accepted
+ ^ acceptValue value
!
positionOffset
@@ -1379,22 +1388,35 @@
aBlock notNil ifTrue:[aBlock value]
! !
-!DialogBox methodsFor:'accessing'!
+!DialogBox methodsFor:'accessing-elements'!
-okText:aString
- "define the text in the ok-button"
+name:element as:name
+ bindings isNil ifTrue:[
+ bindings := IdentityDictionary new.
+ ].
+ bindings at:name put:element
+!
- |oldSize|
+componentAt:name
+ bindings isNil ifTrue:[^ nil].
+ ^ bindings at:name ifAbsent:nil
+! !
- aString ~= okButton label ifTrue:[
- oldSize := okButton extent.
- okButton label:aString.
- okButton resize.
- okButton extent ~= oldSize ifTrue:[
- shown ifTrue:[self resize]
- ]
- ]
-!
+!DialogBox methodsFor:'accessing-models'!
+
+accept
+ "return the valueHolder holding true when the box
+ is accepted, false if closed via the windowManager or
+ the cancel button.
+ This is confusing: this method was originally called #acceptValue,
+ but renamed for compatibility with ST-80.
+ This looks like a bad name to me, since in most other situations, #accept
+ is used to force an accept, not to return some valueHolder ...)."
+
+ ^ acceptValue
+! !
+
+!DialogBox methodsFor:'accessing-behavior'!
okAction:aBlock
"define the action to be performed when ok is pressed"
@@ -1402,6 +1424,12 @@
okAction := aBlock
!
+abortAction:aBlock
+ "define the action to be performed when abort is pressed"
+
+ abortAction := aBlock
+!
+
action:aBlock
"set the action to be performed when user presses ok-button;
aBlock must be nil or a block. This method simply
@@ -1419,18 +1447,39 @@
okButton notNil ifTrue:[
okButton isReturnButton:aBoolean.
]
-!
+! !
+
+!DialogBox methodsFor:'accessing-components'!
okButton
- "return the okButton"
+ "return the okButton - this access is provided to allow
+ setting the buttons look (for example: colors or font)"
^ okButton
!
-abortAction:aBlock
- "define the action to be performed when abort is pressed"
+abortButton
+ "return the abortButton - this access is provided to allow
+ setting the buttons look (for example: colors or font)"
+
+ ^ abortButton
+! !
+
+!DialogBox methodsFor:'accessing'!
- abortAction := aBlock
+okText:aString
+ "define the text in the ok-button"
+
+ |oldSize|
+
+ aString ~= okButton label ifTrue:[
+ oldSize := okButton extent.
+ okButton label:aString.
+ okButton resize.
+ okButton extent ~= oldSize ifTrue:[
+ shown ifTrue:[self resize]
+ ]
+ ]
!
abortText:aString
@@ -1448,12 +1497,6 @@
]
!
-abortButton
- "return the abortButton"
-
- ^ abortButton
-!
-
okText:okString abortText:abortString
"set both texts displayed in the buttons"