Use `View >> pushEvent:` or `ApplicationModel >> enqueueMessage:` to post events
authorJan Vrany <jan.vrany@fit.cvut.cz>
Mon, 18 Feb 2019 10:49:02 +0000
changeset 176 e734c17e7c37
parent 175 a04e1a36e888
child 177 e7bd05df3d6b
Use `View >> pushEvent:` or `ApplicationModel >> enqueueMessage:` to post events ...rather than asking for a window sensor and then talking to it. This allows for more flexibility as the object (subscription receiver) can decide how to handle posting of events.
GDBEventSubscription.st
--- a/GDBEventSubscription.st	Thu Feb 07 15:18:41 2019 +0000
+++ b/GDBEventSubscription.st	Mon Feb 18 10:49:02 2019 +0000
@@ -58,9 +58,9 @@
     args := aSelector numArgs.      
 
     anObject isView ifTrue:[ 
-        args = 0 ifTrue: [ ^[ anObject sensor pushUserEvent: aSelector for: anObject ] ].
-        args = 1 ifTrue: [ ^[ :anAnnouncement | anObject sensor pushUserEvent: aSelector for: anObject withArgument: anAnnouncement ] ].
-        args = 2 ifTrue: [ ^[ :anAnnouncement :anAnnouncer | anObject sensor pushUserEvent: aSelector for: anObject withArguments: (Array with: anAnnouncement with: anAnnouncer) ] ].
+        args = 0 ifTrue: [ ^[ anObject pushEvent: aSelector ] ].
+        args = 1 ifTrue: [ ^[ :anAnnouncement | anObject pushEvent: aSelector with: anAnnouncement ] ].
+        args = 2 ifTrue: [ ^[ :anAnnouncement :anAnnouncer | anObject pushEvent: aSelector with: anAnnouncement with: anAnnouncer ] ].
         self error: 'Couldn''t create block'.        
     ].
 
@@ -74,36 +74,16 @@
     "/ for existence of sensor. If application/window is not fully 
     "/ initialized, process the event as usual.
     (anObject isKindOf: ApplicationModel) ifTrue:[
-        args = 0 ifTrue: [  ^[  | window |
-
-                                window := anObject window.
-                                window notNil 
-                                    ifTrue:[ window sensor pushUserEvent: aSelector for: anObject ]
-                                    ifFalse:[ anObject perform: aSelector ]
-                             ]
-        ].
-        args = 1 ifTrue: [  ^[ :anAnnouncement | | window |
-
-                                window := anObject window.
-                                window notNil 
-                                    ifTrue:[ window sensor pushUserEvent: aSelector for: anObject withArgument: anAnnouncement ]
-                                    ifFalse:[ anObject perform: aSelector with: anAnnouncement ]
-                             ]
-        ].
-        args = 1 ifTrue: [  ^[ :anAnnouncement :anAnnouncer | | window |
-        
-                                window := anObject window.
-                                window notNil 
-                                    ifTrue:[ window sensor pushUserEvent: aSelector for: anObject withArguments: (Array with: anAnnouncement with: anAnnouncer) ]
-                                    ifFalse:[ anObject perform: aSelector with: anAnnouncement with: anAnnouncer ]
-                             ].
-        ].
+        args = 0 ifTrue: [  ^[ anObject enqueueMessage: aSelector ] ].
+        args = 1 ifTrue: [  ^[ :anAnnouncement | anObject enqueueMessage: aSelector with: anAnnouncement ] ].
+        args = 1 ifTrue: [  ^[ :anAnnouncement :anAnnouncer | anObject enqueueMessage: aSelector arguments: (Array with: anAnnouncement with: anAnnouncer) ] ].
         self error: 'Couldn''t create block'.        
     ].
     ^ super blockFor: anObject withSelector: aSelector
 
     "Created: / 18-09-2014 / 00:10:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 01-10-2018 / 17:30:56 / jv"
+    "Modified: / 18-02-2019 / 10:35:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !GDBEventSubscription class methodsFor:'documentation'!