Skip to content

Commit

Permalink
review list command and command support
Browse files Browse the repository at this point in the history
  • Loading branch information
plantec committed Oct 23, 2024
1 parent a4bd37f commit 4d9a3c5
Show file tree
Hide file tree
Showing 16 changed files with 129 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ToMultiSelectionModelSelecterTest >> setUp [
selectionChangedEventClass:
ToListPrimarySelectionChangedEvent;
yourself.
selecter commandApplier: ToQueueBasedCommandApplier new.
selecter commandApplicationStrategy: ToQueueBasedCommandApplicationStrategy new.
selecter onInstalledIn: element.
selecter multiple: true
]
Expand Down
2 changes: 1 addition & 1 deletion src/Toplo-Widget-List-Tests/ToPrimarySelecterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ToPrimarySelecterTest >> setUp [
selectionChangedEventClass:
ToListPrimarySelectionChangedEvent;
yourself.
selecter commandApplier: ToQueueBasedCommandApplier new.
selecter commandApplicationStrategy: ToQueueBasedCommandApplicationStrategy new.
selecter onInstalledIn: element
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ToSingleSelectionModelSelecterTest >> setUp [
selectionChangedEventClass:
ToListPrimarySelectionChangedEvent;
yourself.
selecter commandApplier: ToQueueBasedCommandApplier new.
selecter commandApplicationStrategy: ToQueueBasedCommandApplicationStrategy new.
selecter onInstalledIn: element.
selecter multiple: false
]
Expand Down
22 changes: 22 additions & 0 deletions src/Toplo-Widget-List/ToCommandApplicationStrategy.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Class {
#name : #ToCommandApplicationStrategy,
#superclass : #Object,
#instVars : [
'element',
'commandApplier'
],
#category : #'Toplo-Widget-List-Command-Support'
}

{ #category : #accessing }
ToCommandApplicationStrategy >> addCommand: aCommand [

self subclassResponsibility
]

{ #category : #accessing }
ToCommandApplicationStrategy >> commandApplier: aCommandApplier element: anElement [

commandApplier := aCommandApplier.
element := anElement
]
30 changes: 16 additions & 14 deletions src/Toplo-Widget-List/ToCommandApplicationTask.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,27 @@ Class {
'commandQueue',
'finishedAction',
'posponedRequestTask',
'selecter'
'applier',
'element'
],
#category : #'Toplo-Widget-List-Command-Support'
}

{ #category : #accessing }
ToCommandApplicationTask >> applier: aCommandApplier [

applier := aCommandApplier
]

{ #category : #'api - running' }
ToCommandApplicationTask >> applyAll [

self element ifNil: [ ^ self ].
element ifNil: [ ^ self ].
self canApplyCommands ifFalse: [
posponedRequestTask ifNotNil: [ ^ self ].
posponedRequestTask := BlTaskAction new.
posponedRequestTask action: [ self privateApplyAll ].
self element enqueueTask: posponedRequestTask.
element enqueueTask: posponedRequestTask.
^ self ].

self privateApplyAll
Expand All @@ -27,7 +34,7 @@ ToCommandApplicationTask >> applyAll [
{ #category : #'api - running' }
ToCommandApplicationTask >> canApplyCommands [

^ self element notNil and: [ self element isAttachedToSceneGraph ]
^ element notNil and: [ element isAttachedToSceneGraph ]
]

{ #category : #initialization }
Expand All @@ -37,9 +44,9 @@ ToCommandApplicationTask >> commandQueue: aQueue [
]

{ #category : #accessing }
ToCommandApplicationTask >> element [
ToCommandApplicationTask >> element: anElement [

^ selecter element
element := anElement
]

{ #category : #accessing }
Expand All @@ -52,8 +59,9 @@ ToCommandApplicationTask >> finishedAction: aValuable [
ToCommandApplicationTask >> privateApplyAll [

| nextInQueue |
[ (nextInQueue := commandQueue nextOrNil) isNotNil ] whileTrue: [
selecter applyCommand: nextInQueue ]
[ commandQueue isEmpty ] whileFalse: [
nextInQueue := commandQueue removeFirst.
applier applyCommand: nextInQueue ]
]

{ #category : #'api - running' }
Expand All @@ -62,9 +70,3 @@ ToCommandApplicationTask >> run [
self applyAll.
finishedAction value.
]

{ #category : #accessing }
ToCommandApplicationTask >> selecter: aSelecter [

selecter := aSelecter
]
30 changes: 0 additions & 30 deletions src/Toplo-Widget-List/ToCommandApplier.class.st

This file was deleted.

27 changes: 0 additions & 27 deletions src/Toplo-Widget-List/ToCommandQueue.class.st

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
Class {
#name : #ToDataSourceCommandApplier,
#superclass : #ToCommandApplier,
#name : #ToDataSourceCommandApplicationStrategy,
#superclass : #ToCommandApplicationStrategy,
#category : #'Toplo-Widget-List-Command-Support'
}

{ #category : #accessing }
ToDataSourceCommandApplier >> command: aCommand addedIn: aSelecter [
ToDataSourceCommandApplicationStrategy >> addCommand: aCommand [

element isAttachedToSceneGraph ifFalse: [
aSelecter applyCommand: aCommand.
commandApplier applyCommand: aCommand.
^ self ].
element dataSource
notifySelecterCommandApplicationRequest: aCommand
from: aSelecter.
from: commandApplier.
element spaceDo: [ :sp | sp requestNextPulse ]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Class {
#name : #ToImmediateCommandApplicationStrategy,
#superclass : #ToCommandApplicationStrategy,
#category : #'Toplo-Widget-List-Command-Support'
}

{ #category : #accessing }
ToImmediateCommandApplicationStrategy >> addCommand: aCommand [

commandApplier applyCommand: aCommand
]
11 changes: 0 additions & 11 deletions src/Toplo-Widget-List/ToImmediateCommandApplier.class.st

This file was deleted.

42 changes: 18 additions & 24 deletions src/Toplo-Widget-List/ToListSelecter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Class {
'eventDispatcher',
'selectionChangedEventClass',
'selectionMode',
'commandApplier',
'selectionModel'
'selectionModel',
'commandApplicationStrategy'
],
#category : #'Toplo-Widget-List-Selection-Selecter'
}
Expand All @@ -21,7 +21,7 @@ Class {
ToListSelecter >> addCommand: aCommand [

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

{ #category : #'command application' }
Expand All @@ -47,6 +47,12 @@ ToListSelecter >> beSingleSelection [
self multiple: false
]

{ #category : #accessing }
ToListSelecter >> commandApplicationStrategy: aCommandApplicationStrategy [

commandApplicationStrategy := aCommandApplicationStrategy
]

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

Expand All @@ -66,12 +72,6 @@ ToListSelecter >> commandApplied: aCommand [
element dispatchAuthorisationRequest: req
]

{ #category : #accessing }
ToListSelecter >> commandApplier: aCommandApplierEventHandler [

commandApplier := aCommandApplierEventHandler
]

{ #category : #testing }
ToListSelecter >> containsIndex: anIndex [

Expand All @@ -94,6 +94,12 @@ ToListSelecter >> currentIndex [
ifTrue: [ operator currentIndex ]
]

{ #category : #initialization }
ToListSelecter >> defaultCommandApplicationStrategy [

^ ToQueueBasedCommandApplicationStrategy new
]

{ #category : #operations }
ToListSelecter >> deselectAll [

Expand Down Expand Up @@ -175,15 +181,7 @@ ToListSelecter >> initialize [
multiple := true.
enabled := true.
operator := ToSelectionModelOperator new.
self initializeCommandApplier
]

{ #category : #initialization }
ToListSelecter >> initializeCommandApplier [

"commandApplier := ToDataSourceCommandApplier new."
"commandApplier := ToDirectCommandApplier new."
commandApplier := ToQueueBasedCommandApplier new
commandApplicationStrategy := self defaultCommandApplicationStrategy
]

{ #category : #testing }
Expand Down Expand Up @@ -264,20 +262,16 @@ ToListSelecter >> nextSelectableIndexToScrollTo [

{ #category : #'api - hooks' }
ToListSelecter >> onInstalledIn: anElement [
" the argument is passed as the target of commands.
It receives the selection change event after the application of commands "

element := anElement.
selectionModel on: anElement.
commandApplier element: anElement.
commandApplier onInstalledIn: self
commandApplicationStrategy commandApplier: self element: element
]

{ #category : #'api - hooks' }
ToListSelecter >> onUninstalledIn: anElement [

commandApplier onUninstalledIn: self.
commandApplier := nil.
commandApplicationStrategy := nil.
element := nil
]

Expand Down
Loading

0 comments on commit 4d9a3c5

Please sign in to comment.