[Newbies] How to reopen a collapsed Morph from another Morph?

Mateusz Grotek unoduetre at poczta.onet.pl
Thu Aug 13 21:37:51 UTC 2015

Hi and welcome to the Squeak world!

If you check the implementation of Morph>>collapse method, it is the  
following (in Squeak 4.5):
   CollapsedMorph new beReplacementFor: self

The problem is the method returning self instead of returning the  
You can either modify the method (discouraged), add your own method to  
the Morph class (remember to use the star prefix in the protocol name,  
and to use the proper name to assign it to a proper package), or just  
use the content of the method directly in your code.

My preferred way to do it would be adding a method to the Morph class.  
Let me assume the class category of my package is MyPackage. Just add  
the protocol *MyPackage with the method:
   ^ collapsedMorph new beReplacementFor: self.

Now you can do:
|morph collapsedMorph|
morph := Morph new.
"collapse it"
collapsedMorph := morph collapse.
"uncollapse it"
collapsedMorph collapseOrExpand.

Best wishes,

More information about the Beginners mailing list