Skip to content
Permalink
Browse files

Merge pull request #708 from jecisc/617-TextPresenter-Add-a-placeHolder

617-TextPresenter-Add-a-placeHolder
  • Loading branch information...
jecisc committed Aug 13, 2019
2 parents 4ac485a + bc3f022 commit 7b7d4b53176e138f0a8cc60b63c0a67fe39a44d3
@@ -66,6 +66,7 @@ SpMorphicTextAdapter >> buildWidget [
getSelectionSelector: #readSelection;
menuProvider: self selector: #codePaneMenu:shifted:;
setSelectionSelector: #setSelection:;
ghostText: self placeholder;
beWrapped;
enabled: self enabled;
askBeforeDiscardingEdits: self askBeforeDiscardingEdits;
@@ -80,6 +81,7 @@ SpMorphicTextAdapter >> buildWidget [
self setEditingModeFor: newWidget.
self model additionalKeyBindings ifNotNil: [ :bindings | bindings keysAndValuesDo: [ :shortcut :action | newWidget bindKeyCombination: shortcut toAction: action ] ].
self presenter whenTextChangedDo: [ :text | newWidget setText: text ].
self presenter whenPlaceholderChangedDo: [ :text | newWidget ghostText: text ].
^ newWidget
]

@@ -155,6 +157,16 @@ SpMorphicTextAdapter >> pendingText: aText [
w hasUnacceptedEdits: true ]
]

{ #category : #'widget API' }
SpMorphicTextAdapter >> placeholder [
^ self model placeholder
]

{ #category : #'widget API' }
SpMorphicTextAdapter >> placeholder: aText [
^ self model placeholder: aText
]

{ #category : #'widget API' }
SpMorphicTextAdapter >> readSelection [

@@ -83,22 +83,6 @@ SpMorphicTextInputFieldAdapter >> isPassword [
^ self widget font isKindOf: FixedFaceFont
]

{ #category : #accessing }
SpMorphicTextInputFieldAdapter >> placeHolderText [

^ widget ghostText
]

{ #category : #'widget API' }
SpMorphicTextInputFieldAdapter >> placeholder [
^ self model placeholder
]

{ #category : #'widget API' }
SpMorphicTextInputFieldAdapter >> placeholder: aText [
^ self model placeholder: aText
]

{ #category : #accessing }
SpMorphicTextInputFieldAdapter >> text: aString [
widget
@@ -0,0 +1,27 @@
Class {
#name : #SpAbstractTextAdapterTest,
#superclass : #SpAbstractWidgetAdapterTest,
#category : #'Spec2-Backend-Tests'
}

{ #category : #testing }
SpAbstractTextAdapterTest class >> isAbstract [
^ self = SpAbstractTextAdapterTest
]

{ #category : #testing }
SpAbstractTextAdapterTest class >> shouldInheritSelectors [
^ true
]

{ #category : #tests }
SpAbstractTextAdapterTest >> testChangePlaceholderTextUpdatesPresenter [
presenter placeholder: 'some text'.
self assert: self adapter placeHolderText equals: 'some text'
]

{ #category : #tests }
SpAbstractTextAdapterTest >> testPresenterPlaceholderIsSetInWidget [
presenter placeholder: 'something'.
self assert: self adapter placeHolderText equals: 'something'
]
@@ -1,6 +1,6 @@
Class {
#name : #SpTextAdapterTest,
#superclass : #SpAbstractWidgetAdapterTest,
#superclass : #SpAbstractTextAdapterTest,
#category : #'Spec2-Backend-Tests'
}

@@ -1,6 +1,6 @@
Class {
#name : #SpTextInputFieldAdapterTest,
#superclass : #SpAbstractWidgetAdapterTest,
#superclass : #SpAbstractTextAdapterTest,
#category : #'Spec2-Backend-Tests'
}

@@ -9,14 +9,6 @@ SpTextInputFieldAdapterTest >> classToTest [
^ SpTextInputFieldPresenter
]

{ #category : #tests }
SpTextInputFieldAdapterTest >> testChangePlaceholderTextUpdatesPresenter [

presenter placeholder: 'some text'.

self assert: self adapter placeHolderText equals: 'some text'
]

{ #category : #tests }
SpTextInputFieldAdapterTest >> testChangeWidgetTextUpdatesPresenter [

@@ -46,13 +38,6 @@ SpTextInputFieldAdapterTest >> testPasswordIsSetInWidget [
self assert: self adapter isPassword
]

{ #category : #tests }
SpTextInputFieldAdapterTest >> testPresenterPlaceholderIsSetInWidget [

presenter placeholder: 'something'.
self assert: self adapter placeHolderText equals: 'something'
]

{ #category : #tests }
SpTextInputFieldAdapterTest >> testPresenterTextIsSetInWidget [

@@ -11,7 +11,8 @@ Class {
'#text => SpObservableSlot',
'#actionToPerform => SpObservableSlot',
'#readSelection => SpObservableSlot',
'#actionPerformed => SpObservableSlot'
'#actionPerformed => SpObservableSlot',
'#placeholder => SpObservableSlot'
],
#category : #'Spec2-Core-Widgets'
}
@@ -200,6 +201,7 @@ SpAbstractTextPresenter >> initialize [
super initialize.

text := ''.
placeholder := ''.
actionToPerform := [ :txt | ].
readSelection := [ selection ].
actionPerformed := ''.
@@ -238,6 +240,18 @@ SpAbstractTextPresenter >> notify: errorMessage at: position in: sourceCode [
self changed: #notify:at:in: with: { errorMessage . position . sourceCode }
]

{ #category : #api }
SpAbstractTextPresenter >> placeholder [

^ placeholder
]

{ #category : #accessing }
SpAbstractTextPresenter >> placeholder: aText [

placeholder := aText
]

{ #category : #api }
SpAbstractTextPresenter >> readSelection [
^ self readSelectionBlock cull: self text cull: self
@@ -355,6 +369,12 @@ SpAbstractTextPresenter >> whenMenuChangedDo: aBlock [
self property: #contextMenu whenChangedDo: aBlock
]

{ #category : #'api-events' }
SpAbstractTextPresenter >> whenPlaceholderChangedDo: aBlock [

self property: #placeholder whenChangedDo: aBlock
]

{ #category : #'api-events' }
SpAbstractTextPresenter >> whenReadSelectionIsChangedDo: aBlock [
"Set a block to perform when the read selection block changed"
@@ -31,7 +31,6 @@ Class {
'#acceptOnCR => SpObservableSlot',
'#entryCompletion => SpObservableSlot',
'#isPassword => SpObservableSlot',
'#placeholder => SpObservableSlot',
'#maxLength => SpObservableSlot'
],
#category : #'Spec2-Core-Widgets'
@@ -118,7 +117,6 @@ SpTextInputFieldPresenter >> initialize [
super initialize.

maxLength := 0.
placeholder := ''.
acceptOnCR := true.
isPassword := false.
self whenAcceptOnCRChangedDo: [ :bool | self changed: #acceptOnCR: with: {bool} ]
@@ -142,18 +140,6 @@ SpTextInputFieldPresenter >> maxLength: anInteger [
self updateText.
]

{ #category : #api }
SpTextInputFieldPresenter >> placeholder [

^ placeholder
]

{ #category : #accessing }
SpTextInputFieldPresenter >> placeholder: aText [

placeholder := aText
]

{ #category : #api }
SpTextInputFieldPresenter >> removeEntryCompletion [
"< api:#do>"
@@ -204,9 +190,3 @@ SpTextInputFieldPresenter >> whenPasswordChangedDo: aBlockClosure [

self property: #isPassword whenChangedDo: aBlockClosure
]

{ #category : #'api-events' }
SpTextInputFieldPresenter >> whenPlaceholderChangedDo: aBlock [

self property: #placeholder whenChangedDo: aBlock
]
@@ -0,0 +1,6 @@
Extension { #name : #SpMorphicTextAdapter }

{ #category : #'*Spec2-Morphic-Backend-Tests' }
SpMorphicTextAdapter >> placeHolderText [
^ widget ghostText asString
]
@@ -0,0 +1,73 @@
Class {
#name : #SpAbstractTextPresenterTest,
#superclass : #SpSmokeTest,
#category : #'Spec2-Tests-Core-Widgets'
}

{ #category : #testing }
SpAbstractTextPresenterTest class >> isAbstract [
^ self = SpAbstractTextPresenterTest
]

{ #category : #testing }
SpAbstractTextPresenterTest class >> shouldInheritSelectors [
^ true
]

{ #category : #running }
SpAbstractTextPresenterTest >> classToTest [
^ self subclassResponsibility
]

{ #category : #running }
SpAbstractTextPresenterTest >> initializationText [
presenter text: 'Text for tests.'
]

{ #category : #tests }
SpAbstractTextPresenterTest >> testClearContent [
self initializationText.
self denyEmpty: presenter text.
presenter clearContent.
self assertEmpty: presenter text
]

{ #category : #tests }
SpAbstractTextPresenterTest >> testClearSelection [
self initializationText.
self openInstance.
presenter setSelection: (1 to: 10).
self assert: presenter getSelection equals: (1 to: 10).
presenter clearSelection.
self assert: presenter getSelection isEmpty
]

{ #category : #tests }
SpAbstractTextPresenterTest >> testContextMenu [
| menu changed |

self assert: presenter contextMenu isNil.
menu := SpMenuPresenter new.
changed := false.
presenter whenMenuChangedDo: [
changed := true. ].
presenter contextMenu: menu.
self assert: presenter contextMenu equals: menu.
self assert: changed
]

{ #category : #tests }
SpAbstractTextPresenterTest >> testPlaceholderIsSet [

presenter placeholder: 'enter something...'.

self assert: presenter placeholder equals: 'enter something...'
]

{ #category : #tests }
SpAbstractTextPresenterTest >> testSelectAll [
self initializationText.
self openInstance.
presenter selectAll.
self assert: presenter getSelection equals: (1 to: 15)
]
@@ -1,6 +1,6 @@
Class {
#name : #SpTextInputFieldPresenterTest,
#superclass : #SpTextPresenterTest,
#superclass : #SpAbstractTextPresenterTest,
#category : #'Spec2-Tests-Core-Widgets'
}

@@ -79,14 +79,6 @@ SpTextInputFieldPresenterTest >> testMaxLengthTruncatesText [
self assert: presenter text equals: '1234567890'
]

{ #category : #tests }
SpTextInputFieldPresenterTest >> testPlaceholderIsSet [

presenter placeholder: 'enter something...'.

self assert: presenter placeholder equals: 'enter something...'
]

{ #category : #tests }
SpTextInputFieldPresenterTest >> testTextIsSet [

@@ -1,55 +1,10 @@
Class {
#name : #SpTextPresenterTest,
#superclass : #SpSmokeTest,
#superclass : #SpAbstractTextPresenterTest,
#category : #'Spec2-Tests-Core-Widgets'
}

{ #category : #running }
SpTextPresenterTest >> classToTest [
^ SpTextPresenter
]

{ #category : #running }
SpTextPresenterTest >> initializationText [
presenter text: 'Text for tests.'
]

{ #category : #tests }
SpTextPresenterTest >> testClearContent [
self initializationText.
self denyEmpty: presenter text.
presenter clearContent.
self assertEmpty: presenter text
]

{ #category : #tests }
SpTextPresenterTest >> testClearSelection [
self initializationText.
self openInstance.
presenter setSelection: (1 to: 10).
self assert: presenter getSelection equals: (1 to: 10).
presenter clearSelection.
self assert: presenter getSelection isEmpty
]

{ #category : #tests }
SpTextPresenterTest >> testContextMenu [
| menu changed |

self assert: presenter contextMenu isNil.
menu := SpMenuPresenter new.
changed := false.
presenter whenMenuChangedDo: [
changed := true. ].
presenter contextMenu: menu.
self assert: presenter contextMenu equals: menu.
self assert: changed
]

{ #category : #tests }
SpTextPresenterTest >> testSelectAll [
self initializationText.
self openInstance.
presenter selectAll.
self assert: presenter getSelection equals: (1 to: 15)
]

0 comments on commit 7b7d4b5

Please sign in to comment.
You can’t perform that action at this time.