diff --git a/src/Spec2-Adapters-Morphic/SpMorphicTextInputFieldAdapter.class.st b/src/Spec2-Adapters-Morphic/SpMorphicTextInputFieldAdapter.class.st index 9b94f09bddf..32522a6a93c 100644 --- a/src/Spec2-Adapters-Morphic/SpMorphicTextInputFieldAdapter.class.st +++ b/src/Spec2-Adapters-Morphic/SpMorphicTextInputFieldAdapter.class.st @@ -50,6 +50,8 @@ SpMorphicTextInputFieldAdapter >> buildWidget [ newWidget encrypted: isPassword ]. self presenter whenMaxLengthChangedDo: [ :length | newWidget maxLength: length ]. + self presenter whenEditableChangedDo: [ :value | + self setEditable: value to: newWidget ]. ^ newWidget ] @@ -98,6 +100,12 @@ SpMorphicTextInputFieldAdapter >> isPassword [ ^ self widget font isKindOf: FixedFaceFont ] +{ #category : #private } +SpMorphicTextInputFieldAdapter >> setEditable: aBoolean to: aWidget [ + + aWidget textArea readOnly: aBoolean not +] + { #category : #accessing } SpMorphicTextInputFieldAdapter >> text: aString [ diff --git a/src/Spec2-Core/SpTextInputFieldPresenter.class.st b/src/Spec2-Core/SpTextInputFieldPresenter.class.st index 4d680163fbf..15acf5eb441 100644 --- a/src/Spec2-Core/SpTextInputFieldPresenter.class.st +++ b/src/Spec2-Core/SpTextInputFieldPresenter.class.st @@ -8,6 +8,7 @@ Class { #instVars : [ '#entryCompletion => SpObservableSlot', '#isPassword => SpObservableSlot', + '#editable => SpObservableSlot', '#maxLength => SpObservableSlot' ], #category : #'Spec2-Core-Widgets' @@ -19,6 +20,20 @@ SpTextInputFieldPresenter class >> adapterName [ ^ #TextInputFieldAdapter ] +{ #category : #api } +SpTextInputFieldPresenter >> beEditable [ + "Allow edition (deny readonly)." + + self editable: true +] + +{ #category : #api } +SpTextInputFieldPresenter >> beNotEditable [ + "Set content text as not editable (readonly)" + + self editable: false +] + { #category : #api } SpTextInputFieldPresenter >> bePassword [ "Set this input text as a password editor." @@ -39,6 +54,12 @@ SpTextInputFieldPresenter >> beText [ self bePassword: false ] +{ #category : #private } +SpTextInputFieldPresenter >> editable: aBoolean [ + + editable := aBoolean +] + { #category : #api } SpTextInputFieldPresenter >> entryCompletion [ "Return an entry completion used to suggest text while typing" @@ -72,7 +93,16 @@ SpTextInputFieldPresenter >> initialize [ super initialize. maxLength := 0. - isPassword := false + isPassword := false. + self beEditable. + +] + +{ #category : #testing } +SpTextInputFieldPresenter >> isEditable [ + "Answer true if edition is allowed (component is NOT readonly)" + + ^ editable ] { #category : #testing } @@ -122,6 +152,17 @@ SpTextInputFieldPresenter >> updateText [ self text: self text. ] +{ #category : #'api-events' } +SpTextInputFieldPresenter >> whenEditableChangedDo: aBlock [ + "Inform when editable property has changed. + `aBlock` has three optional arguments: + - new value + - old value + - the announcement triggering this action" + + self property: #editable whenChangedDo: aBlock +] + { #category : #'api-events' } SpTextInputFieldPresenter >> whenEntryCompletionChangedDo: aBlock [ "Inform when entryCompletion property has changed.