Search code examples
pharomorphic

Pharo: how to open a Transcript if none is open


I would like to know whether a Transcript window is visible, and if not to open one.

Since the model behind a Transcript is a PluggableTextMorph I thought about collecting all those which represent Transcripts with

PluggableTextMorph allInstances select: [ :e| e model = Transcript ]

This is all nice, returns a bunch of objects. However, it's not clear which of these is visible. Probably a beginner Morphic question... :)


Solution

  • Maybe there is a better way, but you can definitely use this:

    World submorphs
      detect: [ :m | m model = Transcript ]
      ifNone: [ Transcript open ]
    

    or

    SystemWindow allInstances detect: [ :m | m model = Transcript ] ifNone: [ Transcript open ]

    The thing is that I've tried to do

    ThreadSafeTranscriptPluggableTextMorph allInstances detect: ...
    

    but for some reason morph is still alive even if window is closed