Skip to content

Commit

Permalink
prepare the reuse of dropdownButton from ToSelectElement
Browse files Browse the repository at this point in the history
  • Loading branch information
plantec committed Oct 27, 2024
1 parent b1d4032 commit e362838
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/BaselineOfToplo/BaselineOfToplo.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ BaselineOfToplo >> registerPackages: spec [
#'Toplo-Widget-Menu' #'Toplo-Widget-Pane' #'Toplo-Widget-Segmented' ) ].

spec package: #'Toplo-Widget-Select' with: [
spec requires: #( #Toplo #'Toplo-Widget-List' #'Toplo-Widget-Album'
spec requires: #( #Toplo #'Toplo-Widget-DropdownButton' #'Toplo-Widget-List' #'Toplo-Widget-Album'
#'Toplo-Widget-Button' #'Toplo-Widget-Image'
#'Toplo-Widget-Menu' #'Toplo-Widget-Tag' #'Toplo-Theme' ) ].

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Trait {
#name : #TToDropdownInnerContainerElement,
#category : #'Toplo-Widget-DropdownButton'
}

{ #category : #'t - dropdown inner container' }
TToDropdownInnerContainerElement >> dropdownButton [

^ self explicitRequirement
]

{ #category : #'t - dropdown inner container' }
TToDropdownInnerContainerElement >> dropdownButton: aDropdownButton [

^ self explicitRequirement
]

{ #category : #'t - dropdown inner container' }
TToDropdownInnerContainerElement >> onSelectionChangedInPopupListElement: anEvent [

self refreshFromPopupListSelection.
self requestLayout
]

{ #category : #'t - dropdown inner container' }
TToDropdownInnerContainerElement >> popupWindowManager [

^ self dropdownButton popupWindowManager
]

{ #category : #'t - dropdown inner container' }
TToDropdownInnerContainerElement >> refreshFromPopupListSelection [

^ self explicitRequirement
]

{ #category : #'t - dropdown inner container' }
TToDropdownInnerContainerElement >> windowManager [

self
deprecated: 'Use #popupWindowManager'
transformWith: '`@rcvr windowManager' -> '`@rcvr popupWindowManager'.
^ self selectElement popupWindowManager
]
37 changes: 8 additions & 29 deletions src/Toplo-Widget-Select/TToSelectInnerContainerElement.trait.st
Original file line number Diff line number Diff line change
Expand Up @@ -37,42 +37,21 @@ TToSelectInnerContainerElement >> newFilterTextField [
^ ToSelectFilterTextField new on: self selectElement
]

{ #category : #'t - select inner container' }
TToSelectInnerContainerElement >> onSelectionChangedInPopupListElement: anEvent [

self refreshFromPopupListSelection.
self requestLayout
]

{ #category : #'t - select inner container' }
TToSelectInnerContainerElement >> popupWindowManager [

^ self selectElement popupWindowManager
]

{ #category : #'t - select inner container' }
TToSelectInnerContainerElement >> refreshFromPopupListSelection [

^ self explicitRequirement
]

{ #category : #'t - select inner container' }
TToSelectInnerContainerElement >> selectElement [

^ self explicitRequirement
self
deprecated: 'Use #dropdownButton instead'
transformWith: '`@rcvr selectElement' -> '`@rcvr dropdownButton'.
^ self dropdownButton
]

{ #category : #'t - select inner container' }
TToSelectInnerContainerElement >> selectElement: aSelectElement [

self explicitRequirement
]

{ #category : #'t - select inner container' }
TToSelectInnerContainerElement >> windowManager [

self
deprecated: 'Use #popupWindowManager'
transformWith: '`@rcvr windowManager' -> '`@rcvr popupWindowManager'.
^ self selectElement popupWindowManager
deprecated: 'Use #dropdownButton: instead'
transformWith: '`@rcvr selectElement: `@arg' -> '`@rcvr dropdownButton: `@arg'.
self dropdownButton: aSelectElement

]
44 changes: 28 additions & 16 deletions src/Toplo-Widget-Select/ToMultiSelectBarElement.class.st
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Class {
#name : #ToMultiSelectBarElement,
#superclass : #ToTagBarElement,
#traits : 'TToSelectInnerContainerElement',
#classTraits : 'TToSelectInnerContainerElement classTrait',
#traits : 'TToDropdownInnerContainerElement + TToSelectInnerContainerElement',
#classTraits : 'TToDropdownInnerContainerElement classTrait + TToSelectInnerContainerElement classTrait',
#instVars : [
'selectElement',
'maxSelectedCount',
'keepPickOrder',
'pickCount',
'filterTextField'
'filterTextField',
'dropdownButton'
],
#category : #'Toplo-Widget-Select-Multi'
}
Expand All @@ -30,7 +30,7 @@ ToMultiSelectBarElement >> assertMaxSelectedCount: aNumber [
{ #category : #'accessing - selection' }
ToMultiSelectBarElement >> checkHideSelectionFromListElement [

selectElement hideSelected ifFalse: [ ^ self ].
dropdownButton hideSelected ifFalse: [ ^ self ].
self popupListElement hideSelection
]

Expand All @@ -44,26 +44,38 @@ ToMultiSelectBarElement >> checkMaxSelectedCount [
groupeSM := self popupListElement groupSelectionModel.
sM := self popupListElement selectionModel.

selectElement updateSelectedCountLabel.
selectedCount := selectElement selectionModel selectedIndexesCount.
dropdownButton updateSelectedCountLabel.
selectedCount := dropdownButton selectionModel selectedIndexesCount.

"self assertMaxSelectedCount: selectedIndexCount."
self sieve withLocalAndOriginalIndexDo: [ :d :localIndex :originalIndex |
(groupeSM containsIndex: localIndex) ifFalse: [
selectedCount < maxSelectedCount
ifTrue: [ disabledSM deselectIndex: localIndex ]
ifFalse: [
(selectElement selectionModel containsIndex: originalIndex)
(dropdownButton selectionModel containsIndex: originalIndex)
ifFalse: [ disabledSM selectIndex: localIndex ] ].
" to transfer the selection to the sieve selection model "
sM
transferSelectionFromIndex: localIndex
toIndex: originalIndex
in: selectElement selectionModel ] ].
in: dropdownButton selectionModel ] ].

self popupListElement notifyDataSourceChanged
]

{ #category : #'t - dropdown inner container' }
ToMultiSelectBarElement >> dropdownButton [

^ dropdownButton
]

{ #category : #'t - dropdown inner container' }
ToMultiSelectBarElement >> dropdownButton: aDropdownButton [

dropdownButton := aDropdownButton
]

{ #category : #layout }
ToMultiSelectBarElement >> extentChanged [

Expand Down Expand Up @@ -160,7 +172,7 @@ ToMultiSelectBarElement >> maxSelectedCount: aNumber [
ToMultiSelectBarElement >> popupListElement [


^ selectElement popupListElement
^ dropdownButton popupListElement
]

{ #category : #'t - select inner container' }
Expand All @@ -178,7 +190,7 @@ ToMultiSelectBarElement >> refreshFromPopupListSelection [
" rebuild the current bar nodes according to the selection in the popup list "

| previousTagModels newTagModels |
selectElement showHidePlaceholder.
dropdownButton showHidePlaceholder.
" copy the previous tag models "
previousTagModels := self dataAccessor asOrderedCollection.
newTagModels := OrderedCollection new.
Expand All @@ -191,9 +203,9 @@ ToMultiSelectBarElement >> refreshFromPopupListSelection [
previousTagModels addAll: last items ] ].

" reconstruct the item list. ensure the reuse of pre-existing items"
selectElement selectionModel selectedIndexesDo: [ :idx |
dropdownButton selectionModel selectedIndexesDo: [ :idx |
| new previous data |
data := selectElement sieve originalData at: idx.
data := dropdownButton sieve originalData at: idx.
previous := previousTagModels
detect: [ :item | item data = data ]
ifNone: [ ].
Expand Down Expand Up @@ -221,17 +233,17 @@ ToMultiSelectBarElement >> refreshFromPopupListSelection [
{ #category : #'t - select inner container' }
ToMultiSelectBarElement >> selectElement [

^ selectElement
^ dropdownButton
]

{ #category : #'t - select inner container' }
ToMultiSelectBarElement >> selectElement: aSelectElement [

selectElement := aSelectElement
dropdownButton := aSelectElement
]

{ #category : #accessing }
ToMultiSelectBarElement >> sieve [

^ selectElement sieve
^ dropdownButton sieve
]
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
Class {
#name : #ToSingleSelectInnerContainerElement,
#superclass : #ToElement,
#traits : 'TToSelectInnerContainerElement',
#classTraits : 'TToSelectInnerContainerElement classTrait',
#traits : 'TToDropdownInnerContainerElement + TToSelectInnerContainerElement',
#classTraits : 'TToDropdownInnerContainerElement classTrait + TToSelectInnerContainerElement classTrait',
#instVars : [
'selectElement',
'fakeDataView',
'dataView',
'dataViewFactory',
'dataViewBuilder',
'fakeDataItem',
'currentSelectedIndex',
'filterTextField'
'filterTextField',
'dropdownButton'
],
#category : #'Toplo-Widget-Select-Single'
}
Expand Down Expand Up @@ -46,6 +46,18 @@ ToSingleSelectInnerContainerElement >> defaultLayout [
^ BlLinearLayout horizontal
]

{ #category : #'t - dropdown inner container' }
ToSingleSelectInnerContainerElement >> dropdownButton [

^ dropdownButton
]

{ #category : #'t - dropdown inner container' }
ToSingleSelectInnerContainerElement >> dropdownButton: aDropdownButton [

dropdownButton := aDropdownButton
]

{ #category : #accessing }
ToSingleSelectInnerContainerElement >> fakeDataItem: aData [

Expand Down Expand Up @@ -74,8 +86,8 @@ ToSingleSelectInnerContainerElement >> initialize [
hMatchParent;
constraintsDo: [ :c | c linear vertical alignCenter ].

dataViewFactory := selectElement defaultDataViewFactory.
dataViewBuilder := selectElement defaultDataViewBuilder.
dataViewFactory := dropdownButton defaultDataViewFactory.
dataViewBuilder := dropdownButton defaultDataViewBuilder.

self installDataView.
self installFakeDataView.
Expand Down Expand Up @@ -129,10 +141,10 @@ ToSingleSelectInnerContainerElement >> refresh [
ToSingleSelectInnerContainerElement >> refreshFromPopupListSelection [

| selectedIndex dataItem selectionModel originalData changedEvent |
selectElement showHidePlaceholder.
dropdownButton showHidePlaceholder.

" No data to select from, just do nothing here "
selectElement popupListElement dataAccessor ifEmpty: [ ^ self ].
dropdownButton popupListElement dataAccessor ifEmpty: [ ^ self ].

selectionModel := self popupWindowManager sieve selectionModel.
originalData := self popupWindowManager sieve originalData.
Expand All @@ -155,7 +167,7 @@ ToSingleSelectInnerContainerElement >> refreshFromPopupListSelection [
changedEvent := ToSelectChangedEvent new.
changedEvent selectedData: dataItem.
changedEvent selectedIndex: selectedIndex.
selectElement dispatchEvent: changedEvent
dropdownButton dispatchEvent: changedEvent
]

{ #category : #initialization }
Expand All @@ -175,13 +187,13 @@ ToSingleSelectInnerContainerElement >> sample: aDataItem [
{ #category : #'t - select inner container' }
ToSingleSelectInnerContainerElement >> selectElement [

^ selectElement
^ dropdownButton
]

{ #category : #'t - select inner container' }
ToSingleSelectInnerContainerElement >> selectElement: aSelectElement [

selectElement := aSelectElement
dropdownButton := aSelectElement
]

{ #category : #initialization }
Expand Down

0 comments on commit e362838

Please sign in to comment.