PluggableTextMorph demo 1
Last updated at 1:31 am UTC on 23 December 2019
The project file with all the demos:
Installation: drop file PluggableMorphsDemo-0001.pr (2003) onto Squeak desktop.
All demos after loading the project file
- Squeak 3.6 OK
- Squeak 3.10.2 does not work
Thus the text below explains how to recreate the PluggableTextMorph demo 1 in a newer version of Squeak.
PluggableText demo 1
Purpose: The demo shows how you can create a PluggableTextMorph bound to a model.
1. The construction script for the demo is on the class side of the TextDemo2 class>>example.
2. We first create or model which will hold the textual data. This textual data is shown in the two PluggableTextMorph instances.
3. If you change the contents of the first one, it will affect the other one because they are all "plugged-on" the same model.
- look at how are created the two PluggableTextMorphs in TextDemo1 class>>example method (they are bound to the model with text and text: methods.
- look how those method are defined
- TextDemo2Object>>text ..... nothing extraodinary there)
- TextDemo2Object>>text: ..... notice the usage of changed: method.
Thanks to the changed: invocation when the text: message is sent to the model, the model will notify all its dependents (morphs which were plugged on that model) so that all the model's dependents will update itself approriatelly.
(you may what to put a breakpoints to those methods, play with the demo and see how it all works).
Squeak 3.10.2 (BabySRE)
"Creates two PluggableTextMorph objects which have a common model.
If you change editing the text in one PluggableTextMorph you may save it with press Alt+S.
The display in the other PluggableTextMorph is also updated as the two views share the same model."
| object textMorph1 textMorph2 |
object := TextDataObject new.
textMorph1 := PluggableTextMorph on: object
textMorph1 position: 660@400.
textMorph1 extent: 200 @ 120.
textMorph1 color: Color white.
textMorph2 := PluggableTextMorph on: object
textMorph2 position: 660@540.
textMorph2 extent: 200 @ 120.
textMorph2 color: Color white.
Note: Every object which implements
text _ aText.
^ self changed: #text
may serve as a model object and (a Text model).