SharingDefs

From Inkscape Wiki
Jump to: navigation, search

We need a mechanism to copy any defs referenced by objects along with these objects. This is something that currently prevents us from properly copying objects with gradients from one document to another, but in the future this may also affect colors, masks, bitmaps, arrowheads, fonts, etc. Here's a simplistic algorithm proposed by bb:

  • 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).

A more "correct" but more difficult to implement approach is: provide a way to query any object for any defs it depends on (bearing in mind that defs may reference other defs) and copy/paste only those defs (via a separate clipboard) when the object is copied/pasted.

---

I think the correct approach is simply to do dependency tracking. Not all of an SPObject's depenencies are going to be in a defs section, and a document's defs section can get arbitrarily large -- simply blindly copying the whole thing won't work. See ClipBoard -- MenTaLguY