PluggableTextMorph demo 1
Last updated at 12:06 pm UTC on 25 July 2022
Download: PluggableMorphsDemo-0001.pr
The project file with all the demos:
Installation: drop file PluggableMorphsDemo-0001.pr (2003) onto Squeak desktop.
PluggableMorphsDemo-0001.pr
All demos after loading the project file

Tests:
- Squeak 3.6 OK
- Squeak 3.10.2 does not work
- Squeak 5.3: Project loads but buttons do not work.
Thus the text below explains how to recreate the PluggableTextMorph demo 1 in a newer version of Squeak.
PluggableText demo 1
Code: Demo-TextDemo1_page_1143.st
TextDemo1 explanations
Purpose: The demo shows how you can create a PluggableTextMorph bound to a model.
Steps:
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.
Related stuff:
- Object>>changed:
- PluggableTextMorph>>update:
(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)

The code
"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
text: #text
accept: #text:.
textMorph1 position: 660@400.
textMorph1 extent: 200 @ 120.
textMorph1 color: Color white.
textMorph1 openInWorld.
textMorph2 := PluggableTextMorph on: object
text: #text
accept: #text:.
textMorph2 position: 660@540.
textMorph2 extent: 200 @ 120.
textMorph2 color: Color white.
textMorph2 openInWorld.

Note: Every object which implements
text
^ text
(getter method)
text: aText
text _ aText.
^ self changed: #text
(setter method)
may serve as a model object and (a Text model).