<div dir="ltr">The conclusion I'm reaching is that the necessary events to be notified of every change to the value of a <font face="monospace">TextModelMorph</font> aren't really in place, at least not to support what I'm trying to do. It is far simpler to just do this:<div><br></div><div><font face="monospace">initialize<br> | tmm |<br> <br> tmm := TextModelMorph withText: '' ::<br> acceptOnAny: true;<br> askBeforeDiscardingEdits: false.<br> tmm keystrokeAction: [:event |<br> tmm text print.<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 12:41 PM Weslleymberg Lisboa <<a href="mailto:weslleym.lisboa@gmail.com">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">Thats interesting... I tested it on a clean image updated to #7088. It <br>
asks to save the file on the first key stroke and generates the <br>
#clearUserEdits every time. Attached is a FileOut of the class I used.<br>
<br>
When inserting text, TextModel's actualContent is mainly changed through <br>
TextModel>>#basicReplaceFrom:to:with: and not by #actualContents:. <br>
Unfortunately, I think this is the furthest we can go with a clean base <br>
image. Anything beyond that will require you to change it or subclass <br>
TextModel or TextModelMorph to make it generate the desired notifications.<br>
<br>
I tried modifying #basicReplaceFrom:to:with: to include "self changed: <br>
#actualContents" but it caused a bug that makes cursor jump to the <br>
beginning of the string on every key stroke. Don't know why... since <br>
#basicReplaceFrom:to:with: does note return anything specific.<br>
<br>
Em 24/03/2025 09:41, Mark Volkmann escreveu:<br>
> Your solution does cause the update: method to be called, but only on <br>
> the first keystroke in the TextModelMorph. The argument passed to <br>
> update: is the symbol #clearUserEdits. I want a solution that invokes <br>
> update: on every keystroke. I know I could listen for key events, but <br>
> I'd really like to find a solution that utilizes the dependency <br>
> mechanism. Here is the latest code in the initialize method:<br>
> <br>
> 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.<br>
> <br>
> On Sun, Mar 23, 2025 at 10:24 PM Weslleymberg Lisboa <br>
> <<a href="mailto:weslleym.lisboa@gmail.com" target="_blank">weslleym.lisboa@gmail.com</a> <mailto:<a href="mailto:weslleym.lisboa@gmail.com" target="_blank">weslleym.lisboa@gmail.com</a>>> wrote:<br>
> <br>
> 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.<br>
> (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<br>
> 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<br>
> <cuis-<br>
> > <a href="mailto:dev@lists.cuis.st" target="_blank">dev@lists.cuis.st</a> <mailto:<a href="mailto:dev@lists.cuis.st" target="_blank">dev@lists.cuis.st</a>> <mailto:<a href="mailto:cuis-" target="_blank">cuis-</a><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:<br>
> to see<br>
> > it. Maybe the event that #addDepedent: listens to is not the<br>
> one you<br>
> > need.<br>
> ><br>
> > Cuis use the Observer Pattern as a dependency mechanism (see<br>
> [1]) so<br>
> > #addDependent: and #changed: are "simplifications" of<br>
> #when:send:to:<br>
> > and #triggerEvent:with:<br>
> ><br>
> > IMHO if what you need is to be notified of changes in the<br>
> 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>
> <<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-" rel="noreferrer" target="_blank">https://github.com/nmingotti/The-</a><br>
> Cuis- <<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>><br>
> <mailto:<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>
> escreveu:<br>
> ><br>
> > As far as I can tell,TextModelmorph does not<br>
> send#changed:every<br>
> > time its value changes, so that prevents me from<br>
> 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<br>
> 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>><br>
> > <mailto:<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<br>
> ability?<br>
> ><br>
> > Generally, Morphs are Views and update to reflect<br>
> 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> <<a href="https://github.com/" rel="noreferrer" target="_blank">https://github.com/</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>
> <mailto:<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>> <https://<br>
> > <a href="http://lists.cuis.st/mailman/listinfo/cuis-dev" rel="noreferrer" target="_blank">lists.cuis.st/mailman/listinfo/cuis-dev</a> <<a href="http://lists.cuis.st/" rel="noreferrer" target="_blank">http://lists.cuis.st/</a><br>
> mailman/listinfo/cuis-dev>><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>
> <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>
</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>