[Cuis-dev] dependency mechanism for TextModelMorph

Weslleymberg Lisboa weslleym.lisboa at gmail.com
Sun Mar 23 20:29:25 PDT 2025


Actually, part of the problem was the event you were listening to. But 
it still doesn't work if you don't set the model in the window.

Em 24/03/2025 00:24, Weslleymberg Lisboa escreveu:
> This works:
> 
> initialize
> 
>      | tmm window |
> 
>      tmm := TextModelMorph withText: '' :: acceptOnAny: true.
> 
>      "tmm model when: #changed: send: #update: to: self. (Samething as 
> below)"
>      tmm model addDependent: self.
> 
>      SystemWindow new addMorph: tmm; model: tmm model; openInWorld.
> 
> 
> update: anEvent
> 
>      (anEvent asString, ' triggered!') print.
> 
> Have no idea at the moment why this works and your example doesn't. But 
> I looked on how TextEditor class>>#open and SystemWindow 
> class>>#editString:label:wrap: does it to see what needs to be set 
> before opening the window.
> 
> 
> Em 23/03/2025 18:31, Mark Volkmann escreveu:
>> I must be doing a poor job of describing what I want to achieve.
>> I've boiled it down to the minimum code needed to demonstrate.
>> Here are the steps:
>>
>> - create a subclass of Object
>>
>> - add the following instance methods
>>
>> initialize
>>      | tmm |
>>
>>      tmm := TextModelMorph withText: '' :: acceptOnAny: true.
>>      SystemWindow new addMorph: tmm; openInWorld.
>>
>> update: arg
>>      'update was called' print
>>
>> What can I do in the initialize method so update: is called after 
>> every keystroke in the TextModelMorph?
>> Here are two things I tried that do not work:
>>
>>      tmm model addDependent: self.
>>
>>      tmm model when: #actualContents send: #update: to: self.
>>
>> On Sun, Mar 23, 2025 at 11:45 AM Weslleymberg Lisboa via Cuis-dev 
>> <cuis- dev at lists.cuis.st <mailto:cuis-dev at lists.cuis.st>> wrote:
>>
>>     TextModel generates some events. Browse senders of #changed: to see
>>     it. Maybe the event that #addDepedent: listens to is not the one you
>>     need.
>>
>>     Cuis use the Observer Pattern as a dependency mechanism (see [1]) so
>>     #addDependent: and #changed: are "simplifications" of #when:send:to:
>>     and #triggerEvent:with:
>>
>>     IMHO if what you need is to be notified of changes in the model, I'd
>>     use it directly instead of making TextModelMorph notify me.
>>
>>     1 - <https://github.com/nmingotti/The-Cuis-CookBook/wiki/The-
>>     Dependency-Mechanism--3 <https://github.com/nmingotti/The-Cuis-
>>     CookBook/wiki/The-Dependency-Mechanism--3>>
>>
>>
>>     Em 23 de março de 2025 11:53:10 BRT, Mark Volkmann via Cuis-dev
>>     <cuis-dev at lists.cuis.st <mailto:cuis-dev at lists.cuis.st>> escreveu:
>>
>>         As far as I can tell,TextModelmorph does not send#changed:every
>>         time its value changes, so that prevents me from listening for
>>         updates. I see that the TextModelmethodactualContents:does
>>         send#changed:, but that is not invoked on every change to
>>         aTextModelMorpheven when it is configured withacceptOnAny: true.
>>
>>         On Sun, Mar 23, 2025 at 9:38 AM <ken.dickey at whidbey.com
>>         <mailto:ken.dickey at whidbey.com>> wrote:
>>
>>             On 2025-03-23 06:35, Mark Volkmann via Cuis-dev wrote:
>>
>>              > ...
>>              > myTextModelMorph addDependent: self.
>>             ..
>>              >
>>              > I have a few questions.
>>              > - Are there reasons why I should not want this ability?
>>
>>             Generally, Morphs are Views and update to reflect changes 
>> in an
>>             underlying Model.
>>
>>             A Morph can be a Model if sensible.
>>
>>              > - Would it be better to listen for changes on the
>>             underlying TextModel?
>>
>>             IMHO, yes.
>>
>>             $0.02,
>>             -KenD
>>
>>
>>
>>
>>     --
>>     Att.
>>     Wéslleymberg Lisboa
>>     Graduado em Sistemas de Informação
>>     Docente no IFFluminense - Campus Itaboraí
>>     Ex-Bolsista de IC do Núcleo de Computação Científica (NC2-IFF) -
>>     Projeto IFF Aerospace
>>     Github: https://github.com/weslleymberg <https://github.com/
>>     weslleymberg>
>>     Tel.: +55 22 99931-2376
>>     --     Cuis-dev mailing list
>>     Cuis-dev at lists.cuis.st <mailto:Cuis-dev at lists.cuis.st>
>>     https://lists.cuis.st/mailman/listinfo/cuis-dev <https://
>>     lists.cuis.st/mailman/listinfo/cuis-dev>
>>
>>
>>
>> -- 
>> R. Mark Volkmann
>> Object Computing, Inc.
> 

-- 
Wéslleymberg Lisboa
Graduado em Sistemas de Informação
Docente no IFFluminense - Campus Itaboraí



More information about the Cuis-dev mailing list