Hi Ben, first I would call it ensureOpen, implemented on the class side, looking for a SystemWindow whose model was an instance of the receiver class. Second allInstances should never be used to search when a collection to search already exists; allInstances/allObjects does not scale. It's a great facility, but like others (eg doesNotUnderstand:) it can be abused :-). So just search the morphs from World. eg it is always quicker (and scales much better) to search the class hierarchy looking for methods than doing allInstances. Also using allInstances is akin to using isKindOf: and so is destroying or depending on the absence of polymorphism. Another alternative is to search the dependents of Transcript looking for an open SystemWindow and if you don't find one or the one you find is closed, open anew. You should find code like this for opening a new Monticello browser or raising the existing one etc. this pattern happens often enough. There are recent new examples in Squeak (Chris Muller's modifications to browsing senders/implementors which raises existing windows if available instead of always creating new ones; v nice). HTHX Eliot (phone) On Sep 20, 2014, at 8:57 AM, Ben Coman <btc@openInWorld.com> wrote:
I often use Transcript output in my adhoc issue-isolation scripts, and it would be nice to ensure a Transcript is open at the start of a script, but I can't current see an option besides "Transcript open" which would open too many Transcripts over time. I'd like to add to Pharo something like...
ThreadSafeTranscript >> ensureOpen "It seems that closed Transcript windows hang around and confuse the #detect. Garbage collecting is easier than trying to reopen a closed window. " Smalltalk garbageCollect. ^ PluggableTextMorph allInstances detect: [ :ptm | ptm model = self ] ifNone: [ self open ]
The hard coding of PluggableTextMorph matches that in ThreadSafeTranscript >> openLabel:. Thoughts anyone? cheers -ben