Excellent! I would like to request the abstraction of collecting #activeEventManagersBasicActionMaps. I'm thinking the usage would be:

DeepCopier>>fixActionMaps {like fullCopy} · ct 8/17/2023 14:31
+ fixActionMaps
+     "They are not used much, but need to be right"
+
+     | actionMaps |
+     actionMapOfMaps := Smalltalk activeEventManagers basicActionMaps ifNil: [^ self].
+     actionMapOfMaps do: [:map | map
+         map associationsDo: [:pair |
+             references at: pair key ifPresent: [:copy |
+                 actionMaps at: copy put:
+                     (pair value veryDeepCopyWith: self)]]].

Liscio come l'olio,
rabbit

On 8/17/23 08:49, christoph.thiede@student.hpi.uni-potsdam.de wrote:
Hi all,

I am having the same question:

    s := #(source).
    l
:= #(listener).
    s
when: #plonk send: #halt to: l.
    s
triggerEvent: #plonk. "Halt (as expected)"

    o
:= {s. l}.
    o2
:= o veryDeepCopy.
    s2
:= o2 first. l2 := o2 second.
    s2
triggerEvent: #plonk. "no Halt!"

So, my initial expectation was that when you copy some objects, their actionMaps are copied with them. Otherwise, duplicating an application (e.g., a Morphic window) would not work because the copy's parts would no longer be connected.

However, then I found this test which indicates just the opposite expectation, but for the case of normal (shallow) copies:

    EventManagerTest>>testCopy
        "Ensure that the actionMap is zapped when
        you make a copy of anEventManager"

        eventSource when: #blah send: #yourself to: eventListener.
        self assert: eventSource actionMap keys isEmpty not.
        self assert: eventSource copy actionMap keys isEmpty

In case we want actionMaps to be copied, I am attaching a small change set for that. However, I am curious about your arguments first. With regard to the implementation, we also might want to discuss whether DeepCopier should depend on EventManager or whether we should introduce a generic registry for this that any other class with global references can hook into.

Best,
Christoph

=============== Summary ===============

Change Set:        veryDeepCopy-actionMaps
Date:            17 August 2023
Author:            Christoph Thiede

Copies actionMaps of objects during #veryDeepCopy. Note: We have not yet decided whether this is desired behavior. See: https://lists.squeakfoundation.org/archives/list/squeak-dev@lists.squeakfoundation.org/thread/WWTIYL5FG6QRAUZ3D5NAESC7CKCGBLM4

=============== Diff ===============

DeepCopier>>fixActionMaps {like fullCopy} · ct 8/17/2023 14:31
+ fixActionMaps
+     "They are not used much, but need to be right"
+
+     | actionMaps |
+     actionMaps := EventManager basicActionMaps ifNil: [^ self].
+     actionMaps associationsDo: [:pair |
+         references at: pair key ifPresent: [:copy |
+             actionMaps at: copy put:
+                 (pair value veryDeepCopyWith: self)]].


EventManager class>>basicActionMaps {accessing} · ct 8/17/2023 14:30
+ basicActionMaps
+
+     ^ ActionMaps


Object>>veryDeepCopy {copying} · ct 8/17/2023 14:31 (changed)
veryDeepCopy
    "Do a complete tree copy using a dictionary. An object in the tree twice is only copied once. All references to the object in the copy of the tree will point to the new copy."

    | copier new |
    copier := DeepCopier new: self initialDeepCopierSize.
    new := self veryDeepCopyWith: copier.
    copier mapUniClasses.
    copier references associationsDo: [:assoc |
        assoc value veryDeepFixupWith: copier].
-     copier fixDependents.
+     copier fixDependents; fixActionMaps.
    ^ new

Object>>veryDeepCopySibling {copying} · ct 8/17/2023 14:31 (changed)
veryDeepCopySibling
    "Do a complete tree copy using a dictionary. Substitute a clone of oldPlayer for the root. Normally, a Player or non systemDefined object would have a new class. We do not want one this time. An object in the tree twice, is only copied once. All references to the object in the copy of the tree will point to the new copy."

    | copier new |
    copier := DeepCopier new: self initialDeepCopierSize.
    copier newUniClasses: false.
    new := self veryDeepCopyWith: copier.
    copier mapUniClasses.
    copier references associationsDo: [:assoc |
        assoc value veryDeepFixupWith: copier].
-     copier fixDependents.
+     copier fixDependents; fixActionMaps.
    ^ new

---
Sent from Squeak Inbox Talk

On 2003-07-21T23:32:05+00:00, ned@bike-nomad.com wrote:

> Any Object can have dependents whether or not it has an instance
> variable to keep track of them (these are kept in the
> DependentsFields class variable of Object).
>
> The only class that keeps its own dependents is Model.
>
> Any Object can have an actionMap. These are supplied by EventManager
> class by default, and are stored in the ActionMaps class variable of
> EventManager.
>
> The only class that keeps its own action maps is Morph.
>
> When we veryDeepCopy an object we also copy the global dependents (see
> DeepCopier>>fixDependents).
>
> However, we don't copy the actionMap in those cases where it's held by
> the EventManager class.
>
> When we file out an object that uses DependentsFields out into an
> ImageSegment, we also file out the dependents (see
> ImageSegment>>dependentsSave:) if it's in a project. We do this by
> adding a project parameter called #GlobalDependentsInProject.
>
> However, we don't file out the actionMap in those cases where it's
> held by the EventManager class.
>
> My question is this: should we fix these behaviors (copying and
> serialization) to include these "global action maps" just like we
> already include the "global dependents"?
>
> Or should we discourage the use of the "global action maps"?
>
> --
> Ned Konz
> http://bike-nomad.com
> GPG key ID: BEEA7EFE
-- 
••• rabbit ❤️‍🔥🐰