Skip to content

Commit

Permalink
- Fix Pharo issue pharo-project/pharo#16356
Browse files Browse the repository at this point in the history
- Register keys to have escape for cancel and enter for accept
- Add a label to report errors on validateAnswer
- validateAnswerBlock receives the text and the presenter
- After validateAnswerBlock the focus
  • Loading branch information
tesonep committed Mar 29, 2024
1 parent d0f1eee commit 6f0ab7e
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions src/Spec2-Dialogs/SpRequestDialog.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Class {
'initialExtent',
'acceptLabel',
'cancelLabel',
'validateBlock'
'validateBlock',
'errorLabel'
],
#category : 'Spec2-Dialogs',
#package : 'Spec2-Dialogs'
Expand All @@ -20,7 +21,7 @@ Class {
{ #category : 'accessing' }
SpRequestDialog class >> defaultExtent [

^ 450@160
^ 450@170
]

{ #category : 'layout' }
Expand All @@ -37,6 +38,7 @@ SpRequestDialog class >> defaultLayout [
yourself)
expand: false;
add: #textInput expand: false;
add: #errorLabel;
yourself
]

Expand Down Expand Up @@ -108,6 +110,20 @@ SpRequestDialog >> cancelLabel: aString [
cancelLabel := aString
]

{ #category : 'initialization' }
SpRequestDialog >> connectPresenters [

super connectPresenters.

textInput
bindKeyCombination: Character cr asKeyCombination
toAction: [ self accept ];

bindKeyCombination: Character escape asKeyCombination
toAction: [ self cancel ].

]

{ #category : 'api' }
SpRequestDialog >> extent [

Expand Down Expand Up @@ -141,7 +157,8 @@ SpRequestDialog >> initializePresenters [

image := self newImage image: self defaultIcon.
label := self newLabel.
textInput := self newTextInput
textInput := self newTextInput.
errorLabel := self newLabel.
]

{ #category : 'initialization' }
Expand Down Expand Up @@ -169,6 +186,12 @@ SpRequestDialog >> openModal [
ifFalse: [ nil ]
]

{ #category : 'initialization' }
SpRequestDialog >> setErrorText: aText [

errorLabel label: aText.
]

{ #category : 'api' }
SpRequestDialog >> text [

Expand Down Expand Up @@ -196,8 +219,13 @@ SpRequestDialog >> title: aString [
{ #category : 'private' }
SpRequestDialog >> validateAnswer [

| result |

validateBlock ifNotNil: [
^ validateBlock value: textInput text].
result := validateBlock cull: textInput text cull: self.
result ifFalse: [ textInput takeKeyboardFocus ].
^ result].


^ true
]
Expand Down

0 comments on commit 6f0ab7e

Please sign in to comment.