It seems like when copying to the clipboard, there needs to be a mechanism to scan the selected objects for any referenced objects and also copy the defs for those. The recipient of the paste would then need to add those refs to its own set of defs. It's possible that the receiving document could a) have a different def by the same name, or b) have the same def by a different name; in case (a) it would seem prudent to rename the incoming style, and in case (b) perhaps it should normally merge by default but allow the user an option to not merge when pasting.
That sounds like a lot of code. Maybe we can simplify it a bit as follows:
- a new clipboard is made for storing defs
- whenever anything is cut or copied, the entire defs from the current document are placed on that defs clipboard
- whenever clipboard objects (or style) are pasted, the contents of the defs clipboard are merged with the current document defs:
-- same name, same content: disregard
-- same name, different content: rename both defs and the pasted objects' references (this is the most tricky part)
-- different name, same content: just add, no merge
An advantage of this approach is that you don't need to scan your objects and select relevant defs when copying. However, you'll still have to scan and re-id what you are pasting in case of name conflicts (although these are likely to be rare).