Skip to content

Commit

Permalink
+ ToSelectChangedEvent, ToSingleSelectChangedEvent is deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
plantec committed Oct 26, 2024
1 parent 643cdb8 commit e37a9b4
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 31 deletions.
6 changes: 5 additions & 1 deletion src/Toplo-Examples/ToSandBox.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1905,6 +1905,10 @@ ToSandBox class >> example_SelectMultiFiltrable [

| select innerWindow newTagFactory |
select := ToMultiSelectElement new.
select
addEventHandlerOn: ToSelectChangedEvent
do: [ :event | event selectedIndexes traceCr ].

select nodeWrapping: true.
select keepPickOrder: true.
select popupListElement selectionOption grouped: false.
Expand Down Expand Up @@ -2602,7 +2606,7 @@ ToSandBox class >> example_ThemeSelect [
select placeholderText:
('Select a Toplo theme' asRopedText foreground: Color lightGray).
select
addEventHandlerOn: ToSingleSelectChangedEvent
addEventHandlerOn: ToSelectChangedEvent
do: [ :event | event selectedData asString traceCr ].
select selecter selectIndex: 4.
select allowDeselection: false.
Expand Down
13 changes: 13 additions & 0 deletions src/Toplo-Widget-Select/ToMultiSelectElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,19 @@ ToMultiSelectElement >> nodeWrapping: aBoolean [
self innerContainer nodeWrapping: aBoolean
]

{ #category : #'accessing - selection' }
ToMultiSelectElement >> onSelectionChangedInPopupListElement: anEvent [

| selectedDataItems changedEvent |
super onSelectionChangedInPopupListElement: anEvent.
selectedDataItems := self selectionModel selectedIndexesCollect: [
:idx | self sieve originalData at: idx ].
changedEvent := ToSelectChangedEvent new.
changedEvent selectedDataItems: selectedDataItems.
changedEvent selectedIndexes: self selectionModel selectedIndexes.
self dispatchEvent: changedEvent
]

{ #category : #'accessing - list' }
ToMultiSelectElement >> setGroupIndex: anIndex [

Expand Down
59 changes: 59 additions & 0 deletions src/Toplo-Widget-Select/ToSelectChangedEvent.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Class {
#name : #ToSelectChangedEvent,
#superclass : #BlEvent,
#instVars : [
'selectedIndexes',
'selectedDataItems'
],
#category : #'Toplo-Widget-Select-Single'
}

{ #category : #accessing }
ToSelectChangedEvent >> selectedData [

^ self selectedDataItems ifNotEmpty: [ :s | s anyOne ] ifEmpty: [ ]
]

{ #category : #accessing }
ToSelectChangedEvent >> selectedData: aDataItem [

self selectedDataItems:
(aDataItem ifNil: [ #( ) ] ifNotNil: [ { aDataItem } ])
]

{ #category : #accessing }
ToSelectChangedEvent >> selectedDataItems [

^ selectedDataItems
]

{ #category : #accessing }
ToSelectChangedEvent >> selectedDataItems: aDataArray [

selectedDataItems := aDataArray
]

{ #category : #accessing }
ToSelectChangedEvent >> selectedIndex [

^ self selectedIndexes ifNotEmpty: [ :s | s anyOne ] ifEmpty: [ 0 ]
]

{ #category : #accessing }
ToSelectChangedEvent >> selectedIndex: aSelectedIndex [
"aSelectedIndex can be zero in case none is selected "

self selectedIndexes: { aSelectedIndex }
]

{ #category : #accessing }
ToSelectChangedEvent >> selectedIndexes [

^ selectedIndexes
]

{ #category : #accessing }
ToSelectChangedEvent >> selectedIndexes: anArray [

selectedIndexes := anArray
]
31 changes: 5 additions & 26 deletions src/Toplo-Widget-Select/ToSingleSelectChangedEvent.class.st
Original file line number Diff line number Diff line change
@@ -1,33 +1,12 @@
Class {
#name : #ToSingleSelectChangedEvent,
#superclass : #BlEvent,
#instVars : [
'selectedDataArray',
'selectedIndexes'
],
#superclass : #ToSelectChangedEvent,
#category : #'Toplo-Widget-Select-Single'
}

{ #category : #accessing }
ToSingleSelectChangedEvent >> selectedData [
{ #category : #testing }
ToSingleSelectChangedEvent class >> isDeprecated [
" use ToSelectChangedEvent instead "

^ selectedDataArray ifNotEmpty: [ :s | s anyOne ] ifEmpty: [ ]
]

{ #category : #accessing }
ToSingleSelectChangedEvent >> selectedDataArray: aDataArray [

selectedDataArray := aDataArray
]

{ #category : #accessing }
ToSingleSelectChangedEvent >> selectedIndex [

^ selectedIndexes ifNotEmpty: [ :s | s anyOne ] ifEmpty: [ 0 ]
]

{ #category : #accessing }
ToSingleSelectChangedEvent >> selectedIndexes: anArray [

selectedIndexes := anArray
^ true
]
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,9 @@ ToSingleSelectInnerContainerElement >> refreshFromPopupListSelection [
dataItem := originalData at: selectedIndex.
dataViewBuilder cull: dataView cull: dataItem ].

changedEvent := ToSingleSelectChangedEvent new.
changedEvent selectedDataArray:
(dataItem ifNil: [ #( ) ] ifNotNil: [ { dataItem } ]).
changedEvent selectedIndexes: { selectedIndex }.
changedEvent := ToSelectChangedEvent new.
changedEvent selectedData: dataItem.
changedEvent selectedIndex: selectedIndex.
selectElement dispatchEvent: changedEvent
]

Expand Down

0 comments on commit e37a9b4

Please sign in to comment.