Skip to content

Commit

Permalink
Merge pull request #1360 from colorow/Pharo11
Browse files Browse the repository at this point in the history
Adding textChanged notification to SpStringTableColumn
  • Loading branch information
estebanlm authored Apr 12, 2024
2 parents 6186563 + 57a0256 commit 6909e9e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/Spec2-Adapters-Morphic/SpMorphicTableCellBuilder.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,13 @@ SpMorphicTableCellBuilder >> visitStringColumnEditable: aTableColumn on: content
text: content;
yourself.

aTableColumn acceptAction ifNotNil: [ :valuable |
aTableColumn acceptAction ifNotNil: [ :valuable |
presenter whenSubmitDo: [ :aString |
valuable cull: self item cull: aString ] ].


aTableColumn textChanged ifNotNil: [ :valuable |
presenter whenTextChangedDo: [ :aString |
valuable cull: self item cull: aString ] ].
"add cell"
morph := presenter build.
presenter adapter applyStyle.
Expand Down
21 changes: 19 additions & 2 deletions src/Spec2-Core/SpStringTableColumn.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ Class {
#instVars : [
'editable',
'acceptAction',
'sortable'
'sortable',
'textChanged'
],
#category : 'Spec2-Core-Widgets-Table',
#package : 'Spec2-Core',
Expand Down Expand Up @@ -124,7 +125,17 @@ SpStringTableColumn >> onAcceptEdition: aBlock [
acceptAction := aBlock
]

{ #category : 'api' }
{ #category : #api }
SpStringTableColumn >> onTextChanged: aBlock [
"Set the block to execute when cell edition is edited.
`aBlock` receives two arguments:
- the element of the table (See `SpAbstractListPresenter>>#items:`)
- the string entered while editing"

textChanged := aBlock
]

{ #category : #api }
SpStringTableColumn >> sortFunction [

^ super sortFunction ifNil: [ self evaluation ascending ]
Expand All @@ -144,3 +155,9 @@ SpStringTableColumn >> sortFunction: aBlockOrSortFunction [
super sortFunction: aBlockOrSortFunction asSortFunction.
self isSortable: aBlockOrSortFunction isNotNil
]

{ #category : #accessing }
SpStringTableColumn >> textChanged [

^ textChanged
]
7 changes: 4 additions & 3 deletions src/Spec2-Examples/SpTablePresenter.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,18 @@ SpTablePresenter class >> exampleWithoutColumnHeaders [

{ #category : '*Spec2-Examples' }
SpTablePresenter class >> exampleWriteableTable [
"The selector names are NOT stored, but serves merely to have something one can edit"
"The selector names are NOT stored, but serves merely to have something one can edit. this will also test text changes"
| items |

items := String methods.
^ self new
addColumn: (SpStringTableColumn new
addColumn: (SpStringTableColumn new
title: 'Editable selector name';
evaluated: [ :m | m selector ];
displayBold: [ :m | m selector isKeyword ];
beEditable ;
onAcceptEdition: [ :m :t | Transcript nextPutAll: t;cr;endEntry ];
onTextChanged: [ :m :t | Transcript nextPutAll: t;cr;endEntry ];
yourself);
addColumn: (SpStringTableColumn title: 'Size' evaluated: #size) beSortable;
showColumnHeaders;
Expand Down

0 comments on commit 6909e9e

Please sign in to comment.