[Cuis-dev] updating a TextModelMorph

Mark Volkmann r.mark.volkmann at gmail.com
Sun Aug 25 08:47:28 PDT 2024


On Sun, Aug 25, 2024 at 7:56 AM Juan Vuletich <juan at cuis.st> wrote:

> On 8/24/2024 5:40 PM, Mark Volkmann via Cuis-dev wrote:
>
> I have a class whose initialize method creates a TextModelMorph like
> this:
>
> textModelMorph := TextModelMorph
>     textProvider: self
>     textGetter: #text
>     textSetter: #text:.
>
> It has the following additional instance methods:
>
> text
>     ^ text
>
> text: aString
>     text := aString.
>
> In addition to displaying the TextModelMorph, it displays a button.
> When the button is clicked, it does this:
>
> self text: 'test'.
>
> But the TextModelMorph does not update to show the new value.
> I thought since I changed the "model", it would update.
> I tried lots of methods in TextModelMorph, such as updateActualContents,
> but nothing is working.
> What do I need to do to cause it to update when the value of the text
> instance variable changes?
>
> Hi Mark,
>
> I don't have access to your full example, so I can not try what I'll say.
> So take it just as a suggestion for further exploration.
>
> You need to do `self changed: #text.`. For an example, see senders of
> #classCommentText, especially in #newClassComment:. This is the changed:
> /update: dependency mechanism in action. According to MVC and the Observer
> pattern, models don't know about views, so they can't communicate directly.
> It is views, when created, that say 'I want to be notified when...'.
>

Thanks so much for that tip! That almost does what I need. When I type a
new value into the TextModelMorph, I get a popup that says "Caution!
Contents were saved elsewhere since you started editing them here. Accept
anyway?".

I attached a fileOut of my simple demo. To run this, enter 'TextEntryDemo
new" and "Do it".
It displays a TextEntryMorph, a TextModelMorph, a LabelMorph, and a
PluggableButtonMorph.

If you change the text in the TextEntryMorph and press the return key, the
text in the TextModelMorph will update to match and the LabelMorph will
update.
If you press the "Reset" button, the TextEntryMorph and TextModelMorph will
go back to "World" and the LabelMorph will update.
If you change the text in the TextModelMorph by one character, the
TextEntryMorph will update to match and the LabelMorph will update.
BUT ... if you change it by a second character, that "Caution" popup will
appear. Why does that happen?

-- 
R. Mark Volkmann
Object Computing, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240825/135661ad/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TextEntryDemo.st
Type: application/octet-stream
Size: 2237 bytes
Desc: not available
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240825/135661ad/attachment.obj>


More information about the Cuis-dev mailing list