[Cuis-dev] listening for TextModelMorph changes

Mark Volkmann r.mark.volkmann at gmail.com
Mon Jan 13 17:29:12 PST 2025


Thanks so much for this tip! Clearly a key to getting this to work is
knowing the symbols that the watched object passes to the changed: method.
I see that the TextModel instance method actualContents: uses the symbol
#actualContents. So I tried the following to test whether I could make a
sound every time the text in a TextModelMorph is modified:

Preferences at: #soundsEnabled put: true.
model := TextModel withText: 'Hello'.
model when: #actualContents send: #primitiveBeep to: Smalltalk.
input := TextModelMorph withModel: model.
input openInWorld.

I don't hear sounds when modifying the value. I thought perhaps the problem
is that the TextModel instance method actualContents: is not called every
time the value is modified. But even when I explicitly invoke it with model
actualContents: 'Test', I don't hear a sound. I do hear a sound when I
evaluate Smalltalk primitiveBeep.

On Sun, Jan 12, 2025 at 10:23 PM Weslleymberg Lisboa via Cuis-dev <
cuis-dev at lists.cuis.st> wrote:

> Hi, Mark
>
> I think Object>>when:send:to: is what you are looking for. Call it on
> your TextModel instance to register and object to be notified. I'm still
> learning this mechanism, but this wiki page might be of some help:
>
>
> https://github.com/nmingotti/The-Cuis-CookBook/wiki/The-Dependency-Mechanism--3
>
> Em 12/01/2025 23:04, Mark Volkmann via Cuis-dev escreveu:
> > Is there a way to register to have a message sent to a given object
> > every time the "model actualContents" value of a TextModelMorph changes?
> > I searched through the code for TextModelMorph and TextModel, but
> > couldn't find a solution.
> >
> > --
> > R. Mark Volkmann
> > Object Computing, Inc.
> >
>
> --
> Wéslleymberg Lisboa
> Graduado em Sistemas de Informação
> Docente no IFFluminense - Campus Itaboraí
>
> --
> Cuis-dev mailing list
> Cuis-dev at lists.cuis.st
> https://lists.cuis.st/mailman/listinfo/cuis-dev
>


-- 
R. Mark Volkmann
Object Computing, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20250113/06859396/attachment.htm>


More information about the Cuis-dev mailing list