<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>