From df866631ea08386f482cd1dd3812e1e296524f80 Mon Sep 17 00:00:00 2001 From: Alain Plantec Date: Sun, 27 Oct 2024 10:58:40 +0100 Subject: [PATCH] + ToElementCompositeCommand --- src/Toplo-Examples/ToSandBox.class.st | 5 ++ .../ToElementBasicCommand.class.st | 4 ++ .../ToElementCompositeCommand.class.st | 42 ++++++++++++ .../ToIndexesSelectionCommand.class.st | 18 +++++ .../ToListElementCommand.class.st | 6 ++ .../ToListElementCompositeCommand.class.st | 41 ++++++++++++ src/Toplo-Widget-List/ToListSelecter.class.st | 2 +- .../ToWholeSelectionCommand.class.st | 16 +++++ .../ToMultiSelectBarElement.class.st | 6 -- .../ToMultiSelectBarElementSkin.class.st | 65 ------------------- .../ToSelectChangedEvent.class.st | 2 +- .../ToSelectElementSkin.class.st | 18 +++-- 12 files changed, 147 insertions(+), 78 deletions(-) create mode 100644 src/Toplo-Widget-List/ToElementCompositeCommand.class.st create mode 100644 src/Toplo-Widget-List/ToListElementCompositeCommand.class.st delete mode 100644 src/Toplo-Widget-Select/ToMultiSelectBarElementSkin.class.st diff --git a/src/Toplo-Examples/ToSandBox.class.st b/src/Toplo-Examples/ToSandBox.class.st index 3d28e088..202d8a2c 100644 --- a/src/Toplo-Examples/ToSandBox.class.st +++ b/src/Toplo-Examples/ToSandBox.class.st @@ -1850,6 +1850,11 @@ ToSandBox class >> example_SelectMonoFiltrable [ | select innerWindow phtext | select := ToSingleSelectElement new. + select + addEventHandlerOn: ToSelectChangedEvent + do: [ :event | event selectedIndexes traceCr ]. + + select popupListElement placeholderMinHeight: 35. phtext := ('No Data' asRopedText foreground: Color lightGray; diff --git a/src/Toplo-Widget-List/ToElementBasicCommand.class.st b/src/Toplo-Widget-List/ToElementBasicCommand.class.st index 65efaea5..4cdff53d 100644 --- a/src/Toplo-Widget-List/ToElementBasicCommand.class.st +++ b/src/Toplo-Widget-List/ToElementBasicCommand.class.st @@ -8,6 +8,10 @@ Class { #category : #'Toplo-Widget-List-Command' } +{ #category : #'private - adding' } +ToElementBasicCommand >> addedIn: aCommandApplier [ +] + { #category : #'private - hook' } ToElementBasicCommand >> applyWithOperator: anOperator [ diff --git a/src/Toplo-Widget-List/ToElementCompositeCommand.class.st b/src/Toplo-Widget-List/ToElementCompositeCommand.class.st new file mode 100644 index 00000000..f93ff541 --- /dev/null +++ b/src/Toplo-Widget-List/ToElementCompositeCommand.class.st @@ -0,0 +1,42 @@ +Class { + #name : #ToElementCompositeCommand, + #superclass : #ToElementBasicCommand, + #instVars : [ + 'commands' + ], + #category : #'Toplo-Widget-List-Command' +} + +{ #category : #'instance creation' } +ToElementCompositeCommand class >> withAll: commands [ + + ^ self new + addAll: commands; + yourself +] + +{ #category : #accessing } +ToElementCompositeCommand >> add: aCommand [ + + commands add: aCommand +] + +{ #category : #accessing } +ToElementCompositeCommand >> addAll: aCommandArray [ + + commands addAll: aCommandArray +] + +{ #category : #'private - hook' } +ToElementCompositeCommand >> applyWithOperator: anOperator [ + + super applyWithOperator: anOperator. + commands do: [ :c | c applyWithOperator: anOperator ] +] + +{ #category : #initialization } +ToElementCompositeCommand >> initialize [ + + super initialize. + commands := OrderedCollection new +] diff --git a/src/Toplo-Widget-List/ToIndexesSelectionCommand.class.st b/src/Toplo-Widget-List/ToIndexesSelectionCommand.class.st index 2d56188a..b8c7c40b 100644 --- a/src/Toplo-Widget-List/ToIndexesSelectionCommand.class.st +++ b/src/Toplo-Widget-List/ToIndexesSelectionCommand.class.st @@ -7,6 +7,24 @@ Class { #category : #'Toplo-Widget-List-Command' } +{ #category : #'instance creation' } +ToIndexesSelectionCommand class >> add: indexes [ + + ^ self new + indexes: indexes; + operation: ToAddSelectionOperation new; + yourself +] + +{ #category : #'instance creation' } +ToIndexesSelectionCommand class >> remove: indexes [ + + ^ self new + indexes: indexes; + operation: ToRemoveSelectionOperation new; + yourself +] + { #category : #'private - hook' } ToIndexesSelectionCommand >> applyOn: anOperator [ diff --git a/src/Toplo-Widget-List/ToListElementCommand.class.st b/src/Toplo-Widget-List/ToListElementCommand.class.st index 2b5834b0..689bdb2e 100644 --- a/src/Toplo-Widget-List/ToListElementCommand.class.st +++ b/src/Toplo-Widget-List/ToListElementCommand.class.st @@ -7,6 +7,12 @@ Class { #category : #'Toplo-Widget-List-Command' } +{ #category : #'private - adding' } +ToListElementCommand >> addedIn: aCommandApplier [ + + selectionModel := aCommandApplier selectionModel +] + { #category : #accessing } ToListElementCommand >> indexes [ diff --git a/src/Toplo-Widget-List/ToListElementCompositeCommand.class.st b/src/Toplo-Widget-List/ToListElementCompositeCommand.class.st new file mode 100644 index 00000000..514dc842 --- /dev/null +++ b/src/Toplo-Widget-List/ToListElementCompositeCommand.class.st @@ -0,0 +1,41 @@ +Class { + #name : #ToListElementCompositeCommand, + #superclass : #ToElementCompositeCommand, + #instVars : [ + 'selectionModel' + ], + #category : #'Toplo-Widget-List-Command' +} + +{ #category : #'private - adding' } +ToListElementCompositeCommand >> addedIn: aCommandApplier [ + + selectionModel := aCommandApplier selectionModel. + commands do: [ :c | c addedIn: self ] +] + +{ #category : #accessing } +ToListElementCompositeCommand >> indexes [ + + ^ Array streamContents: [ :stream | + commands do: [ :c | stream nextPutAll: c indexes ] ] +] + +{ #category : #accessing } +ToListElementCompositeCommand >> intervals [ + + ^ Array streamContents: [ :stream | + commands do: [ :c | stream nextPutAll: c intervals ] ] +] + +{ #category : #accessing } +ToListElementCompositeCommand >> selectionModel [ + + ^ selectionModel +] + +{ #category : #accessing } +ToListElementCompositeCommand >> selectionModel: aSelectionModel [ + + selectionModel := aSelectionModel +] diff --git a/src/Toplo-Widget-List/ToListSelecter.class.st b/src/Toplo-Widget-List/ToListSelecter.class.st index 6aa2b690..04c41214 100644 --- a/src/Toplo-Widget-List/ToListSelecter.class.st +++ b/src/Toplo-Widget-List/ToListSelecter.class.st @@ -21,6 +21,7 @@ Class { ToListSelecter >> addCommand: aCommand [ enabled ifFalse: [ ^ self ]. + aCommand addedIn: self. commandApplicationStrategy addCommand: aCommand ] @@ -28,7 +29,6 @@ ToListSelecter >> addCommand: aCommand [ ToListSelecter >> applyCommand: aCommand [ | previousModel | - aCommand selectionModel: selectionModel. previousModel := selectionModel copy. aCommand applyWithOperator: operator. previousModel = aCommand selectionModel ifTrue: [ ^ self ]. diff --git a/src/Toplo-Widget-List/ToWholeSelectionCommand.class.st b/src/Toplo-Widget-List/ToWholeSelectionCommand.class.st index 4f96ccc1..063acccf 100644 --- a/src/Toplo-Widget-List/ToWholeSelectionCommand.class.st +++ b/src/Toplo-Widget-List/ToWholeSelectionCommand.class.st @@ -4,6 +4,22 @@ Class { #category : #'Toplo-Widget-List-Command' } +{ #category : #'instance creation' } +ToWholeSelectionCommand class >> add [ + + ^ self new + operation: ToAddSelectionOperation new; + yourself +] + +{ #category : #'instance creation' } +ToWholeSelectionCommand class >> remove [ + + ^ self new + operation: ToRemoveSelectionOperation new; + yourself +] + { #category : #'private - hook' } ToWholeSelectionCommand >> applyOn: anOperator [ diff --git a/src/Toplo-Widget-Select/ToMultiSelectBarElement.class.st b/src/Toplo-Widget-Select/ToMultiSelectBarElement.class.st index 3199ee81..666ef1f1 100644 --- a/src/Toplo-Widget-Select/ToMultiSelectBarElement.class.st +++ b/src/Toplo-Widget-Select/ToMultiSelectBarElement.class.st @@ -164,12 +164,6 @@ ToMultiSelectBarElement >> maxSelectedCount: aNumber [ self refreshFromPopupListSelection ] -{ #category : #skin } -ToMultiSelectBarElement >> newRawSkin [ - - ^ ToMultiSelectBarElementSkin new -] - { #category : #accessing } ToMultiSelectBarElement >> popupListElement [ diff --git a/src/Toplo-Widget-Select/ToMultiSelectBarElementSkin.class.st b/src/Toplo-Widget-Select/ToMultiSelectBarElementSkin.class.st deleted file mode 100644 index adb39a82..00000000 --- a/src/Toplo-Widget-Select/ToMultiSelectBarElementSkin.class.st +++ /dev/null @@ -1,65 +0,0 @@ -Class { - #name : #ToMultiSelectBarElementSkin, - #superclass : #ToRawSkin, - #category : #'Toplo-Widget-Select-Multi' -} - -{ #category : #'event handling' } -ToMultiSelectBarElementSkin >> installSkinEvent: anEvent [ - - super installSkinEvent: anEvent. - anEvent elementDo: [ :e | - e shortcuts: (self shortcutsToInstallIn: e). - e installShortcuts ] -] - -{ #category : #'accessing - shortcuts' } -ToMultiSelectBarElementSkin >> shortcutsToInstallIn: aListElement [ - - ^ Array streamContents: [ :stream | - - stream nextPut: (BlShortcutWithAction new - combination: BlKeyCombination builder arrowDown build; - action: [ :aShortcutEvent :aShortcut | - | idx | - idx := aListElement selecter nextSelectableIndexToScrollTo. - aListElement selecter scrollToDataSourcePosition: idx. - aListElement selecter selectOnlyIndex: idx ]). - - stream nextPut: (BlShortcutWithAction new - combination: BlKeyCombination builder arrowUp build; - action: [ :aShortcutEvent :aShortcut | - | idx | - idx := aListElement selecter previousSelectableIndexToScrollTo. - aListElement selecter scrollToDataSourcePosition: idx. - aListElement selecter selectOnlyIndex: idx ]). - - aListElement isMultipleSelection ifTrue: [ - stream nextPut: (BlShortcutWithAction new - combination: BlKeyCombination primaryA; - action: [ :aShortcutEvent :aShortcut | - aListElement selecter selectAll ]). - - stream nextPut: (BlShortcutWithAction new - combination: BlKeyCombination builder shift arrowDown build; - action: [ :aShortcutEvent :aShortcut | - | idx | - idx := aListElement selecter nextDeselectedIndex. - aListElement selecter selectIndex: idx. - aListElement selecter scrollToDataSourcePosition: idx ]). - - stream nextPut: (BlShortcutWithAction new - combination: BlKeyCombination builder shift arrowUp build; - action: [ :aShortcutEvent :aShortcut | - | idx | - idx := aListElement selecter previousDeselectedIndex. - aListElement selecter selectIndex: idx. - aListElement selecter scrollToDataSourcePosition: idx ]) ] ] -] - -{ #category : #'event handling' } -ToMultiSelectBarElementSkin >> uninstallSkinEvent: anEvent [ - - super uninstallSkinEvent: anEvent. - anEvent elementDo: [ :e | e uninstallShortcuts ] -] diff --git a/src/Toplo-Widget-Select/ToSelectChangedEvent.class.st b/src/Toplo-Widget-Select/ToSelectChangedEvent.class.st index 57786427..5fcd8a5b 100644 --- a/src/Toplo-Widget-Select/ToSelectChangedEvent.class.st +++ b/src/Toplo-Widget-Select/ToSelectChangedEvent.class.st @@ -5,7 +5,7 @@ Class { 'selectedIndexes', 'selectedDataItems' ], - #category : #'Toplo-Widget-Select-Single' + #category : #'Toplo-Widget-Select-Core' } { #category : #accessing } diff --git a/src/Toplo-Widget-Select/ToSelectElementSkin.class.st b/src/Toplo-Widget-Select/ToSelectElementSkin.class.st index ca747c9b..b3d8bc76 100644 --- a/src/Toplo-Widget-Select/ToSelectElementSkin.class.st +++ b/src/Toplo-Widget-Select/ToSelectElementSkin.class.st @@ -41,7 +41,7 @@ ToSelectElementSkin >> shortcutsToInstallIn: aSelect [ stream nextPut: (BlShortcutWithAction new combination: BlKeyCombination builder return build; action: [ :aShortcutEvent :aShortcut | - | selIdxes deselIdxes | + | selIdxes deselIdxes cmd | selIdxes := OrderedCollection new. deselIdxes := OrderedCollection new. listElement secondarySelectionModel selectedIndexesDo: [ :idx | @@ -50,10 +50,18 @@ ToSelectElementSkin >> shortcutsToInstallIn: aSelect [ (listElement selectionModel containsIndex: idx) ifTrue: [ deselIdxes add: idx ] ifFalse: [ selIdxes add: idx ] ] ]. - listElement selecter selectIndexes: selIdxes. - aSelect allowDeselection - ifTrue: [ listElement selecter selectOnlyIndexes: selIdxes ] - ifFalse: [ listElement selecter selectIndexes: selIdxes ] ]) ] + " use a composite command to have only one ToSelectChangedEvent for multiple sub-commands " + cmd := ToListElementCompositeCommand new. + aSelect isMultipleSelection ifFalse: [ + aSelect allowDeselection + ifTrue: [ cmd add: ToWholeSelectionCommand remove ] + ifFalse: [ + selIdxes ifNotEmpty:[ (listElement selecter containsIndex: selIdxes first) + ifFalse: [ cmd add: ToWholeSelectionCommand remove ] ] ] ]. + aSelect allowDeselection ifTrue: [ + cmd add: (ToIndexesSelectionCommand remove: deselIdxes) ]. + cmd add: (ToIndexesSelectionCommand add: selIdxes). + listElement selecter addCommand: cmd ]) ] ] { #category : #'event handling' }