After #122672 landed, slots other than the the slot for the currently active
ID became accessible from the Action Editor. However, the code for inserting
keys directly in the Action Editor assumed that the ID being keyed was
always the active one. This made inserting keys on slots other than the slot
for the active ID fail because the RNA paths wouldn't resolve for that ID.
Additionally, even if they did resolve (e.g. if the ID type was the same), the
keying code would use the wrong ID anyway, which would result in unexpected
behavior regardless.
This commit fixes this by looking up an ID that actually uses the given slot,
and using that ID to perform the keying.
Note that there are various corner cases that have to be handled, such as when
there is more than one user of a slot (and none of them are the active ID),
which makes the choice ambiguous, or when there are no users of a slot. We
handle these corner cases by simply keying the fcurves directly, rather than
going through the normal keyframing code paths. This means that in those corner
cases the value of the property in the scene is ignored, and the fcurve is
simply keyed with whatever value the fcurve evaluates to on that frame. We may
revisit this in the future if this fallback behavior turns out to not feel good
to users in practice, but for now it seems like a reasonable solution.
Pull Request: https://projects.blender.org/blender/blender/pulls/124227