From 6f0ab7e8a2197ffc7217a7161625706bcf8b3f5e Mon Sep 17 00:00:00 2001 From: Pablo Tesone Date: Fri, 29 Mar 2024 15:33:18 +0100 Subject: [PATCH] - Fix Pharo issue https://github.com/pharo-project/pharo/issues/16356 - 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 --- src/Spec2-Dialogs/SpRequestDialog.class.st | 36 +++++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/Spec2-Dialogs/SpRequestDialog.class.st b/src/Spec2-Dialogs/SpRequestDialog.class.st index 03abd3c5..e9cf5414 100644 --- a/src/Spec2-Dialogs/SpRequestDialog.class.st +++ b/src/Spec2-Dialogs/SpRequestDialog.class.st @@ -11,7 +11,8 @@ Class { 'initialExtent', 'acceptLabel', 'cancelLabel', - 'validateBlock' + 'validateBlock', + 'errorLabel' ], #category : 'Spec2-Dialogs', #package : 'Spec2-Dialogs' @@ -20,7 +21,7 @@ Class { { #category : 'accessing' } SpRequestDialog class >> defaultExtent [ - ^ 450@160 + ^ 450@170 ] { #category : 'layout' } @@ -37,6 +38,7 @@ SpRequestDialog class >> defaultLayout [ yourself) expand: false; add: #textInput expand: false; + add: #errorLabel; yourself ] @@ -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 [ @@ -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' } @@ -169,6 +186,12 @@ SpRequestDialog >> openModal [ ifFalse: [ nil ] ] +{ #category : 'initialization' } +SpRequestDialog >> setErrorText: aText [ + + errorLabel label: aText. +] + { #category : 'api' } SpRequestDialog >> text [ @@ -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 ]