Skip to content

Commit

Permalink
+ ToElementCompositeCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
plantec committed Oct 27, 2024
1 parent a3c2cff commit df86663
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 78 deletions.
5 changes: 5 additions & 0 deletions src/Toplo-Examples/ToSandBox.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/Toplo-Widget-List/ToElementBasicCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Class {
#category : #'Toplo-Widget-List-Command'
}

{ #category : #'private - adding' }
ToElementBasicCommand >> addedIn: aCommandApplier [
]

{ #category : #'private - hook' }
ToElementBasicCommand >> applyWithOperator: anOperator [

Expand Down
42 changes: 42 additions & 0 deletions src/Toplo-Widget-List/ToElementCompositeCommand.class.st
Original file line number Diff line number Diff line change
@@ -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
]
18 changes: 18 additions & 0 deletions src/Toplo-Widget-List/ToIndexesSelectionCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 [

Expand Down
6 changes: 6 additions & 0 deletions src/Toplo-Widget-List/ToListElementCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Class {
#category : #'Toplo-Widget-List-Command'
}

{ #category : #'private - adding' }
ToListElementCommand >> addedIn: aCommandApplier [

selectionModel := aCommandApplier selectionModel
]

{ #category : #accessing }
ToListElementCommand >> indexes [

Expand Down
41 changes: 41 additions & 0 deletions src/Toplo-Widget-List/ToListElementCompositeCommand.class.st
Original file line number Diff line number Diff line change
@@ -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
]
2 changes: 1 addition & 1 deletion src/Toplo-Widget-List/ToListSelecter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ Class {
ToListSelecter >> addCommand: aCommand [

enabled ifFalse: [ ^ self ].
aCommand addedIn: self.
commandApplicationStrategy addCommand: aCommand
]

{ #category : #'command application' }
ToListSelecter >> applyCommand: aCommand [

| previousModel |
aCommand selectionModel: selectionModel.
previousModel := selectionModel copy.
aCommand applyWithOperator: operator.
previousModel = aCommand selectionModel ifTrue: [ ^ self ].
Expand Down
16 changes: 16 additions & 0 deletions src/Toplo-Widget-List/ToWholeSelectionCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 [

Expand Down
6 changes: 0 additions & 6 deletions src/Toplo-Widget-Select/ToMultiSelectBarElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,6 @@ ToMultiSelectBarElement >> maxSelectedCount: aNumber [
self refreshFromPopupListSelection
]

{ #category : #skin }
ToMultiSelectBarElement >> newRawSkin [

^ ToMultiSelectBarElementSkin new
]

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

Expand Down
65 changes: 0 additions & 65 deletions src/Toplo-Widget-Select/ToMultiSelectBarElementSkin.class.st

This file was deleted.

2 changes: 1 addition & 1 deletion src/Toplo-Widget-Select/ToSelectChangedEvent.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Class {
'selectedIndexes',
'selectedDataItems'
],
#category : #'Toplo-Widget-Select-Single'
#category : #'Toplo-Widget-Select-Core'
}

{ #category : #accessing }
Expand Down
18 changes: 13 additions & 5 deletions src/Toplo-Widget-Select/ToSelectElementSkin.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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' }
Expand Down

0 comments on commit df86663

Please sign in to comment.