Eliot Miranda wrote:
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.  

Thanks Eliot.  I found success with "World systemWindows select: [  :sw | sw model = Transcript]"
However I'd like it used like "Transcript ensureOpen"
and since "Transcript" is a global singleton holding an instance of ThreadSafeTranscript, I need something on the instance side.  Though I'm not sure if I should only implement it on the instance-side, or if the instance-side should forward to it implemented on the class-side.   Probably the latter.  Since no instance variables are referenced it belongs on the class-side and the the instance-side is just for convenience.

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 :-).  

Point taken.  Consider it was a first pass concept to show intent and generate the feedback I needed to do it properly ;)
cheers -ben

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 <[email protected]> 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

    

  

Reply via email to