Skip to content

Commit

Permalink
+ ToCommandApplicationRequestEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
plantec committed Feb 14, 2024
1 parent 5874778 commit 9ea46e4
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 27 deletions.
8 changes: 7 additions & 1 deletion src/Toplo-Widget-List/TToCommandOperator.trait.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@ TToCommandOperator >> addCommand: aCommand [

self dispatchEvent: (ToCommandAddedEvent new
command: aCommand;
commandOperator: self;
operator: self;
yourself)
]

{ #category : #accessing }
TToCommandOperator >> applyAll [

self dispatchEvent: ToCommandApplicationRequestEvent new
]

{ #category : #'command application' }
TToCommandOperator >> applyCommand: aCommand for: aTarget [

Expand Down
11 changes: 11 additions & 0 deletions src/Toplo-Widget-List/ToCommandApplicationRequestEvent.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Class {
#name : #ToCommandApplicationRequestEvent,
#superclass : #BlEvent,
#category : #'Toplo-Widget-List-Command'
}

{ #category : #sending }
ToCommandApplicationRequestEvent >> sendTo: anObject [

anObject commandApplicationRequestEvent: self
]
10 changes: 5 additions & 5 deletions src/Toplo-Widget-List/ToCommandEvent.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Class {
#superclass : #BlEvent,
#instVars : [
'command',
'commandOperator'
'operator'
],
#category : #'Toplo-Widget-List-Command'
}
Expand All @@ -21,13 +21,13 @@ ToCommandEvent >> command: aSelectionCommand [
]

{ #category : #accessing }
ToCommandEvent >> commandOperator [
ToCommandEvent >> operator [

^ commandOperator
^ operator
]

{ #category : #accessing }
ToCommandEvent >> commandOperator: aCommandOperator [
ToCommandEvent >> operator: aCommandOperator [

commandOperator := aCommandOperator
operator := aCommandOperator
]
57 changes: 37 additions & 20 deletions src/Toplo-Widget-List/ToCommandEventHandler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,28 @@ Class {
#category : #'Toplo-Widget-List-Command'
}

{ #category : #'event handling' }
ToCommandEventHandler >> addComand: aCommand fromOperator: anOperator forTarget: aTarget [

| targetedCommand |
aTarget isAttachedToSceneGraph ifFalse: [
anOperator applyCommand: aCommand for: aTarget.
^ self ].
targetedCommand := ToTargetedCommand new
operator: anOperator;
target: aTarget;
command: aCommand;
yourself.
commandQueue nextPut: targetedCommand.
applicationTask ifNotNil: [ ^ self ].
applicationTask := BlTaskAction new action: [
applicationTask := nil.
" use of an event to make sure the target is still on the scene graph "
aTarget dispatchEvent: ToCommandApplicationRequestEvent new ].
aTarget enqueueTask: applicationTask.
aTarget requestLayout
]

{ #category : #'event handling' }
ToCommandEventHandler >> applyAllCommands [

Expand All @@ -20,31 +42,26 @@ ToCommandEventHandler >> applyAllCommands [
{ #category : #'event handling' }
ToCommandEventHandler >> commandAddedEvent: aCommandAddedEvent [

| target targetedCommand |
target := aCommandAddedEvent target.
target isAttachedToSceneGraph ifFalse: [
aCommandAddedEvent commandOperator
applyCommand: aCommandAddedEvent command
for: target.
^ self ].
targetedCommand := ToTargetedCommand new
operator: aCommandAddedEvent commandOperator;
target: target;
command: aCommandAddedEvent command;
yourself.
commandQueue nextPut: targetedCommand.
applicationTask ifNotNil: [ ^ self ].
applicationTask := BlTaskAction new action: [
self applyAllCommands.
applicationTask := nil ].
target enqueueTask: applicationTask.
target requestLayout
self
addComand: aCommandAddedEvent command
fromOperator: aCommandAddedEvent operator
forTarget: aCommandAddedEvent currentTarget
]

{ #category : #'event handling' }
ToCommandEventHandler >> commandApplicationRequestEvent: aCommandApplicationRequestEvent [

applicationTask ifNotNil: [
aCommandApplicationRequestEvent currentTarget dequeueTask:
applicationTask.
applicationTask := nil ].
self applyAllCommands
]

{ #category : #'api - accessing' }
ToCommandEventHandler >> eventsToHandle [

^ { ToCommandAddedEvent }
^ { ToCommandAddedEvent. ToCommandApplicationRequestEvent }
]

{ #category : #initialization }
Expand Down
4 changes: 3 additions & 1 deletion src/Toplo-Widget-List/ToSelectionModelOperator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ ToSelectionModelOperator >> applyCommand: aCommand for: aTarget [
operateSilently ifTrue: [ ^ self ].

self dispatchEvent: (ToSelectionCommandAppliedEvent new
commandOperator: self;
operator: self;
command: aCommand).

changed ifFalse: [ ^ self ].
Expand Down Expand Up @@ -182,6 +182,7 @@ ToSelectionModelOperator >> selectAllIndexes: anArray [
ToSelectionModelOperator >> selectAndScrollToIndex: anIndex [

self selectIndex: anIndex.
self applyAll.
self selectionModel ifNotEmpty: [
self addCommand: (ToActionCommand new
action: [ :e | e scrollToIndex: anIndex ];
Expand All @@ -195,6 +196,7 @@ ToSelectionModelOperator >> selectAndScrollToNext [
nextIdx := self nextIdxTowardEnd.
nextIdx isZero ifTrue: [ ^ self ].
self deselectAll.
self applyAll.
self selectAndScrollToIndex: nextIdx
]

Expand Down

0 comments on commit 9ea46e4

Please sign in to comment.