PartsBin
Last updated at 5:19 am UTC on 25 June 2018
Here is some sample code for creating a parts bin:
coll := OrderedCollection new addAll: #(
(RectangleMorph authoringPrototype 'My Morph' 'Opens a copy of my morph')
(Morph authoringPrototype 'Another' 'Another morph, fun isn''t it?')
(EllipseMorph authoringPrototype 'Ellipse' 'A nice ellipse')
(TextMorph authoringPrototype 'Text' 'A nice ellipse')
).
pbin := (PartsBin newPartsBinWithOrientation: #leftToRight from: coll).
pbin extent: 200@120.
pbin openInHand
This will create a basic parts bin with one object.
Orientations take the form #leftToRight and #topToBottom.
The from: takes a quadList in the form (receiver selector 'label' 'balloonHelp').
The word quadList is a bit misleading. It doesn't actually set up a 4-tuple, but a 3-tuple. The method authoringPrototype is implemented in Morph, so any morph can use it. I don't completely understand its behaviour, but it sets up the returned object to be in a "tear off" mode that the parts bin can use.
Each PartsBin creates a set of IconicButtons corresponding to the object you want to create. The target of the button is the object you put first in the 3-tuple. The message sent to this object for creation is #launchPartVia:label: with the arguments of the selector and the label. From the above example, the first object in parts bin would be created like this when pulled out:
RectangleMorph launchPartVia: #authoringPrototype label: 'My Morph'
This will create a RectangleMorph in hand that has the label 'My Morph' associated with it.