<div dir="ltr">Using a suggestion from Hilaire, this works. It passes the <font face="monospace">String</font> value to <font face="monospace">update:</font> on every keystroke. But it seems there should be a solution that does not require listening for key events.<div><br></div><div><font face="monospace">initialize<br> | scroller tmm |<br> <br></font><span style="font-family:monospace"> <span class="gmail-Apple-converted-space"> </span></span><font face="monospace">tmm := TextModelMorph withText: '' ::<br></font><span style="font-family:monospace"> <span class="gmail-Apple-converted-space"> </span></span><font face="monospace">acceptOnAny: true;<br></font><span style="font-family:monospace"> <span class="gmail-Apple-converted-space"> </span></span><font face="monospace">askBeforeDiscardingEdits: false.<br></font><span style="font-family:monospace"> <span class="gmail-Apple-converted-space"> </span></span><font face="monospace">scroller := tmm scroller.<br></font><span style="font-family:monospace"> <span class="gmail-Apple-converted-space"> </span></span><font face="monospace">scroller addDependent: self.<br></font><span style="font-family:monospace"> <span class="gmail-Apple-converted-space"> </span></span><font face="monospace">scroller setProperty: #keyStroke: toValue: [:event |<br></font><span style="font-family:monospace"> <span class="gmail-Apple-converted-space"> </span></span><span style="font-family:monospace"> </span><span class="gmail-Apple-converted-space" style="font-family:monospace"> </span><span style="font-family:monospace">scroller changed: scroller model actualContents string</span></div><div><span style="font-family:monospace"> <span class="gmail-Apple-converted-space"> </span></span><font face="monospace">].<br><br> SystemWindow new addMorph: tmm; openInWorld.</font><br></div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Mon, Mar 24, 2025 at 7:41 AM Mark Volkmann <<a href="mailto:r.mark.volkmann@gmail.com">r.mark.volkmann@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">Your solution does cause the <font face="monospace">update:</font> method to be called, but only on the first keystroke in the <font face="monospace">TextModelMorph</font>. The argument passed to <font face="monospace">update:</font> is the symbol <font face="monospace">#clearUserEdits</font>. I want a solution that invokes update: on every keystroke. I know I could listen for key events, but I'd really like to find a solution that utilizes the dependency mechanism. Here is the latest code in the <font face="monospace">initialize</font> method:<div><br></div><div><font face="monospace">initialize<br> | tmm |<br> <br> tmm := TextModelMorph withText: '' :: acceptOnAny: true.<br> tmm model addDependent: self.<br> SystemWindow new<br> addMorph: tmm;<br> model: tmm model;<br> openInWorld.</font><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Mar 23, 2025 at 10:24 PM Weslleymberg Lisboa <<a href="mailto:weslleym.lisboa@gmail.com" target="_blank">weslleym.lisboa@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">This works:<br>
<br>
initialize<br>
<br>
| tmm window |<br>
<br>
tmm := TextModelMorph withText: '' :: acceptOnAny: true.<br>
<br>
"tmm model when: #changed: send: #update: to: self. (Samething as below)"<br>
tmm model addDependent: self.<br>
<br>
SystemWindow new addMorph: tmm; model: tmm model; openInWorld.<br>
<br>
<br>
update: anEvent<br>
<br>
(anEvent asString, ' triggered!') print.<br>
<br>
Have no idea at the moment why this works and your example doesn't. But <br>
I looked on how TextEditor class>>#open and SystemWindow <br>
class>>#editString:label:wrap: does it to see what needs to be set <br>
before opening the window.<br>
<br>
<br>
Em 23/03/2025 18:31, Mark Volkmann escreveu:<br>
> I must be doing a poor job of describing what I want to achieve.<br>
> I've boiled it down to the minimum code needed to demonstrate.<br>
> Here are the steps:<br>
> <br>
> - create a subclass of Object<br>
> <br>
> - add the following instance methods<br>
> <br>
> initialize<br>
> | tmm |<br>
> <br>
> tmm := TextModelMorph withText: '' :: acceptOnAny: true.<br>
> SystemWindow new addMorph: tmm; openInWorld.<br>
> <br>
> update: arg<br>
> 'update was called' print<br>
> <br>
> What can I do in the initialize method so update: is called after every <br>
> keystroke in the TextModelMorph?<br>
> Here are two things I tried that do not work:<br>
> <br>
> tmm model addDependent: self.<br>
> <br>
> tmm model when: #actualContents send: #update: to: self.<br>
> <br>
> On Sun, Mar 23, 2025 at 11:45 AM Weslleymberg Lisboa via Cuis-dev <cuis- <br>
> <a href="mailto:dev@lists.cuis.st" target="_blank">dev@lists.cuis.st</a> <mailto:<a href="mailto:cuis-dev@lists.cuis.st" target="_blank">cuis-dev@lists.cuis.st</a>>> wrote:<br>
> <br>
> TextModel generates some events. Browse senders of #changed: to see<br>
> it. Maybe the event that #addDepedent: listens to is not the one you<br>
> need.<br>
> <br>
> Cuis use the Observer Pattern as a dependency mechanism (see [1]) so<br>
> #addDependent: and #changed: are "simplifications" of #when:send:to:<br>
> and #triggerEvent:with:<br>
> <br>
> IMHO if what you need is to be notified of changes in the model, I'd<br>
> use it directly instead of making TextModelMorph notify me.<br>
> <br>
> 1 - <<a href="https://github.com/nmingotti/The-Cuis-CookBook/wiki/The-" rel="noreferrer" target="_blank">https://github.com/nmingotti/The-Cuis-CookBook/wiki/The-</a><br>
> Dependency-Mechanism--3 <<a href="https://github.com/nmingotti/The-Cuis-" rel="noreferrer" target="_blank">https://github.com/nmingotti/The-Cuis-</a><br>
> CookBook/wiki/The-Dependency-Mechanism--3>><br>
> <br>
> <br>
> Em 23 de março de 2025 11:53:10 BRT, Mark Volkmann via Cuis-dev<br>
> <<a href="mailto:cuis-dev@lists.cuis.st" target="_blank">cuis-dev@lists.cuis.st</a> <mailto:<a href="mailto:cuis-dev@lists.cuis.st" target="_blank">cuis-dev@lists.cuis.st</a>>> escreveu:<br>
> <br>
> As far as I can tell,TextModelmorph does not send#changed:every<br>
> time its value changes, so that prevents me from listening for<br>
> updates. I see that the TextModelmethodactualContents:does<br>
> send#changed:, but that is not invoked on every change to<br>
> aTextModelMorpheven when it is configured withacceptOnAny: true.<br>
> <br>
> On Sun, Mar 23, 2025 at 9:38 AM <<a href="mailto:ken.dickey@whidbey.com" target="_blank">ken.dickey@whidbey.com</a><br>
> <mailto:<a href="mailto:ken.dickey@whidbey.com" target="_blank">ken.dickey@whidbey.com</a>>> wrote:<br>
> <br>
> On 2025-03-23 06:35, Mark Volkmann via Cuis-dev wrote:<br>
> <br>
> > ...<br>
> > myTextModelMorph addDependent: self.<br>
> ..<br>
> ><br>
> > I have a few questions.<br>
> > - Are there reasons why I should not want this ability?<br>
> <br>
> Generally, Morphs are Views and update to reflect changes in an<br>
> underlying Model.<br>
> <br>
> A Morph can be a Model if sensible.<br>
> <br>
> > - Would it be better to listen for changes on the<br>
> underlying TextModel?<br>
> <br>
> IMHO, yes.<br>
> <br>
> $0.02,<br>
> -KenD<br>
> <br>
> <br>
> <br>
> <br>
> --<br>
> Att.<br>
> Wéslleymberg Lisboa<br>
> Graduado em Sistemas de Informação<br>
> Docente no IFFluminense - Campus Itaboraí<br>
> Ex-Bolsista de IC do Núcleo de Computação Científica (NC2-IFF) -<br>
> Projeto IFF Aerospace<br>
> Github: <a href="https://github.com/weslleymberg" rel="noreferrer" target="_blank">https://github.com/weslleymberg</a> <<a href="https://github.com/" rel="noreferrer" target="_blank">https://github.com/</a><br>
> weslleymberg><br>
> Tel.: +55 22 99931-2376<br>
> -- <br>
> Cuis-dev mailing list<br>
> <a href="mailto:Cuis-dev@lists.cuis.st" target="_blank">Cuis-dev@lists.cuis.st</a> <mailto:<a href="mailto:Cuis-dev@lists.cuis.st" target="_blank">Cuis-dev@lists.cuis.st</a>><br>
> <a href="https://lists.cuis.st/mailman/listinfo/cuis-dev" rel="noreferrer" target="_blank">https://lists.cuis.st/mailman/listinfo/cuis-dev</a> <https://<br>
> <a href="http://lists.cuis.st/mailman/listinfo/cuis-dev" rel="noreferrer" target="_blank">lists.cuis.st/mailman/listinfo/cuis-dev</a>><br>
> <br>
> <br>
> <br>
> -- <br>
> R. Mark Volkmann<br>
> Object Computing, Inc.<br>
<br>
-- <br>
Wéslleymberg Lisboa<br>
Graduado em Sistemas de Informação<br>
Docente no IFFluminense - Campus Itaboraí<br>
<br>
</blockquote></div><div><br clear="all"></div><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><font face="arial, helvetica, sans-serif">R. Mark Volkmann</font></div><div><span style="font-size:12.8px"><font face="arial, helvetica, sans-serif">Object Computing, Inc.</font></span></div></div></div></div></div></div></div></div>
</blockquote></div><div><br clear="all"></div><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><font face="arial, helvetica, sans-serif">R. Mark Volkmann</font></div><div><span style="font-size:12.8px"><font face="arial, helvetica, sans-serif">Object Computing, Inc.</font></span></div></div></div></div></div></div></div></div>