Kernel-Announcements.st 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. Smalltalk current createPackage: 'Kernel-Announcements'!
  2. Object subclass: #AnnouncementSubscription
  3. instanceVariableNames: 'block announcementClass'
  4. package: 'Kernel-Announcements'!
  5. !AnnouncementSubscription commentStamp!
  6. The subscription is a single entry in a subscription registry of an `Announcer`.
  7. Several subscriptions by the same object is possible.!
  8. !AnnouncementSubscription methodsFor: 'accessing'!
  9. announcementClass
  10. ^announcementClass
  11. !
  12. announcementClass: aClass
  13. announcementClass := aClass
  14. !
  15. block
  16. ^block
  17. !
  18. block: aBlock
  19. block := aBlock
  20. ! !
  21. !AnnouncementSubscription methodsFor: 'announcing'!
  22. deliver: anAnnouncement
  23. (self handlesAnnouncement: anAnnouncement)
  24. ifTrue: [self block value: anAnnouncement]
  25. !
  26. handlesAnnouncement: anAnnouncement
  27. ^anAnnouncement isKindOf: self announcementClass
  28. ! !
  29. Object subclass: #Announcer
  30. instanceVariableNames: 'registry subscriptions'
  31. package: 'Kernel-Announcements'!
  32. !Announcer commentStamp!
  33. The code is based on the announcements as [described by Vassili Bykov](http://www.cincomsmalltalk.com/userblogs/vbykov/blogView?searchCategory=Announcements%20Framework).
  34. The Announcer holds annoncement subscriptions (`AnnouncementSubscription`) in a private registry.
  35. Use `#on:do:` to register subscriptions.!
  36. !Announcer methodsFor: 'announcing'!
  37. announce: anAnnouncement
  38. subscriptions do: [:each |
  39. each deliver: anAnnouncement]
  40. ! !
  41. !Announcer methodsFor: 'initialization'!
  42. initialize
  43. super initialize.
  44. subscriptions := Array new
  45. ! !
  46. !Announcer methodsFor: 'subscribing'!
  47. on: aClass do: aBlock
  48. subscriptions add: (AnnouncementSubscription new
  49. block: aBlock;
  50. announcementClass: aClass;
  51. yourself)
  52. ! !
  53. Announcer subclass: #SystemAnnouncer
  54. instanceVariableNames: ''
  55. package: 'Kernel-Announcements'!
  56. !SystemAnnouncer commentStamp!
  57. My unique instance #current is the global announcer handling all Amber system-related announces!
  58. SystemAnnouncer class instanceVariableNames: 'current'!
  59. !SystemAnnouncer class methodsFor: 'accessing'!
  60. current
  61. ^ current ifNil: [ current := super new ]
  62. ! !
  63. !SystemAnnouncer class methodsFor: 'instance creation'!
  64. new
  65. self shouldNotImplement
  66. ! !
  67. Object subclass: #SystemAnnouncement
  68. instanceVariableNames: 'theClass'
  69. package: 'Kernel-Announcements'!
  70. !SystemAnnouncement commentStamp!
  71. I am the superclass of all system announcements!
  72. !SystemAnnouncement methodsFor: 'accessing'!
  73. theClass
  74. ^ theClass
  75. !
  76. theClass: aClass
  77. theClass := aClass
  78. ! !
  79. SystemAnnouncement subclass: #ClassAnnouncement
  80. instanceVariableNames: 'theClass'
  81. package: 'Kernel-Announcements'!
  82. !ClassAnnouncement methodsFor: 'accessing'!
  83. theClass
  84. ^ theClass
  85. !
  86. theClass: aClass
  87. theClass := aClass
  88. ! !
  89. ClassAnnouncement subclass: #ClassAdded
  90. instanceVariableNames: ''
  91. package: 'Kernel-Announcements'!
  92. !ClassAdded commentStamp!
  93. I am emitted when a class is added to the system.
  94. See ClassBuilder >> #addSubclassOf:... methods!
  95. ClassAnnouncement subclass: #ClassCommentChanged
  96. instanceVariableNames: ''
  97. package: 'Kernel-Announcements'!
  98. !ClassCommentChanged commentStamp!
  99. I am emitted when the comment of a class changes. (Behavior >> #comment)!
  100. ClassAnnouncement subclass: #ClassDefinitionChanged
  101. instanceVariableNames: ''
  102. package: 'Kernel-Announcements'!
  103. !ClassDefinitionChanged commentStamp!
  104. I am emitted when the defintion of a class changes.
  105. See ClassBuilder >> #class:instanceVariableNames:!
  106. ClassAnnouncement subclass: #ClassMoved
  107. instanceVariableNames: 'oldPackage'
  108. package: 'Kernel-Announcements'!
  109. !ClassMoved methodsFor: 'accessing'!
  110. oldPackage
  111. ^ oldPackage
  112. !
  113. oldPackage: aPackage
  114. oldPackage := aPackage
  115. ! !
  116. ClassAnnouncement subclass: #ClassRemoved
  117. instanceVariableNames: ''
  118. package: 'Kernel-Announcements'!
  119. !ClassRemoved commentStamp!
  120. I am emitted when a class is removed.
  121. See Smalltalk >> #removeClass:!
  122. ClassAnnouncement subclass: #ClassRenamed
  123. instanceVariableNames: ''
  124. package: 'Kernel-Announcements'!
  125. !ClassRenamed commentStamp!
  126. I am emitted when a class is renamed.
  127. See ClassBuilder >> #renameClass:to:!
  128. SystemAnnouncement subclass: #MethodAnnouncement
  129. instanceVariableNames: 'method'
  130. package: 'Kernel-Announcements'!
  131. !MethodAnnouncement methodsFor: 'accessing'!
  132. method
  133. ^ method
  134. !
  135. method: aCompiledMethod
  136. method := aCompiledMethod
  137. ! !
  138. MethodAnnouncement subclass: #MethodAdded
  139. instanceVariableNames: ''
  140. package: 'Kernel-Announcements'!
  141. MethodAnnouncement subclass: #MethodModified
  142. instanceVariableNames: 'oldMethod'
  143. package: 'Kernel-Announcements'!
  144. !MethodModified methodsFor: 'accessing'!
  145. oldMethod
  146. ^ oldMethod
  147. !
  148. oldMethod: aMethod
  149. oldMethod := aMethod
  150. ! !
  151. MethodAnnouncement subclass: #MethodMoved
  152. instanceVariableNames: 'oldProtocol'
  153. package: 'Kernel-Announcements'!
  154. !MethodMoved methodsFor: 'accessing'!
  155. oldProtocol
  156. ^ oldProtocol
  157. !
  158. oldProtocol: aString
  159. oldProtocol := aString
  160. ! !
  161. MethodAnnouncement subclass: #MethodRemoved
  162. instanceVariableNames: ''
  163. package: 'Kernel-Announcements'!
  164. SystemAnnouncement subclass: #PackageAnnouncement
  165. instanceVariableNames: 'package'
  166. package: 'Kernel-Announcements'!
  167. !PackageAnnouncement methodsFor: 'accessing'!
  168. package
  169. ^ package
  170. !
  171. package: aPackage
  172. package := aPackage
  173. ! !
  174. PackageAnnouncement subclass: #PackageAdded
  175. instanceVariableNames: ''
  176. package: 'Kernel-Announcements'!
  177. PackageAnnouncement subclass: #PackageRemoved
  178. instanceVariableNames: ''
  179. package: 'Kernel-Announcements'!
  180. SystemAnnouncement subclass: #ProtocolAnnouncement
  181. instanceVariableNames: 'theClass protocol'
  182. package: 'Kernel-Announcements'!
  183. !ProtocolAnnouncement methodsFor: 'accessing'!
  184. protocol
  185. ^ protocol
  186. !
  187. protocol: aString
  188. protocol := aString
  189. !
  190. theClass
  191. ^ theClass
  192. !
  193. theClass: aClass
  194. theClass := aClass
  195. ! !
  196. ProtocolAnnouncement subclass: #ProtocolAdded
  197. instanceVariableNames: ''
  198. package: 'Kernel-Announcements'!
  199. ProtocolAnnouncement subclass: #ProtocolRemoved
  200. instanceVariableNames: ''
  201. package: 'Kernel-Announcements'!