On 18.04.2011 10:47, Fernando Olivero wrote:
To remove the subscription you can evaluate: World announcer initialize.
Maybe the tutorial should add (pesudo code):
MyStuff>>initialize World announcer on: WindowOpened send: #showOnTranscript to: self SystemAnnouncer on:#classremove send:#release: to: self.
MyStuff>>release: anAnn World announcer unsuscribe: self.
MyStuff>>showOnTranscript Transcript show: 'A new window was opened';cr
I can update the tutorial if people agrees on the pseudo code.
To open a transcript evaluate: TranscriptMorph openWindow (decoupled Transcript from Morphic, so directly ask the view to open itself)
Fernando
The old tutorial was weak mainly because it didn't tell you how to unsubscribe. Here's a few examples of that: "Unsubscribe automatically with weak announcements." World announcer weak on: WindowOpened send: #shownOnTranscript to: self. Then example in Workspace obj := self new. "Open a window, and see Transcript printing" obj := nil. "Open a window, you may see Transcript printing (depending on finalization)" "Now force finalization" Smalltalk garbageCollect. "Open a window, now see no transcript prints." "Automatically unregister after handling one announcement" initialize World announcer on: WindowOpened do: [:ann: announcer | self shownOnTranscript. announcer unsubscribe: self.] "Unregister specifically after some time" initialize World announcer on: WindowOpened send: #shownOnTranscript to: self. release World announcer unsubscribe: self. "Using same action block registered for multiple announcers, unregister specifially at a specific time" initialize handlesAnnoucements := true. actionBlock:= [:ann :announcer | handlesAnnouncement ifTrue: [self shownOnTranscript] ifFalse: [announcer unsubscribe: self]]. World announcer on: WindowOpened do: actionBlock. AnnouncerTest announcer on: TestCaseEnded do: actionBlock. release handlesAnnouncements := false.