Skip to content

Commit

Permalink
add beEditable property to input texts
Browse files Browse the repository at this point in the history
  • Loading branch information
estebanlm committed Mar 28, 2021
1 parent ce76ee4 commit 04aaa71
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
Expand Up @@ -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
]
Expand Down Expand Up @@ -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 [

Expand Down
43 changes: 42 additions & 1 deletion src/Spec2-Core/SpTextInputFieldPresenter.class.st
Expand Up @@ -8,6 +8,7 @@ Class {
#instVars : [
'#entryCompletion => SpObservableSlot',
'#isPassword => SpObservableSlot',
'#editable => SpObservableSlot',
'#maxLength => SpObservableSlot'
],
#category : #'Spec2-Core-Widgets'
Expand All @@ -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."
Expand All @@ -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"
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 04aaa71

Please sign in to comment.