Reconciling registered styles¶
When a drawing is saved, it saves all of the styles it is using with it, as you would expect. Some or all of these styles may be being managed by the Style Registry, if your application is taking advantage of that feature. When such a file is opened again at some later time, it may contain styles that also exist in the current registry - possibly in a different state. Thus a way is needed to reconcile such styles so that the registry and the document agree, or agree to disagree!
The point of the Style Registry is to keep, in a database-like fashion, a set of styles that can be reused across many documents. However if a style is ever changed, which one is true - the document, the registry, or neither? DrawKit provides a mechanism for handling this problem easily, but the decisions about which style is the “one true version” will rest with your application, or its user, perhaps. This mechanism kicks in when a drawing is first unarchived from a file on disk. If you are using DKDrawingDocument, you can override one high-level method to deal with this, if you don’t like the default behaviour. If not, you’ll need to drop down to lower levels. Of course if you are not using the Style Registry, you can simply ignore the problem altogether.
After unarchiving, styles that were originally saved with the drawing are reinitialised and attached to their original objects. Thus after opening, the drawing always “looks right”, as it was saved. However if any styles were registered at the time the document was saved, they may have the same unique key as a style in the current registry. Such styles are flagged as “formerly registered” after unarchiving, and can be collected into a set by the document. The set can be checked against the current registry, which will identify any that do match a registered style, and which of the two is newer (or the same, if they haven’t been changed). Using this information an application can decide what to do - possibly deferring to the user. The registry then performs a “remerge” operation, which either updates the registry from the document, updates the document from the registry, or re-registers the document’s styles anew as additional versions. When actually replacing styles, it calls a nominated delegate to make the final decision about which stays and which goes. If any of the document’s styles are to be updated from the current registry, this set of styles is returned to it and the final step is to switch out the document’s styles for those matching in the returned set.
DKDrawingDocument handles all of this processing but by default it allows the registry to overrule the document for any styles that match. If your application doesn’t want this, it should override -remergeStyles:readFromURL: and either pass a different option to the remerge method of the style registry, or implement a delegate method so it can check each style as it goes, or preflight the styles and take a decision based on that. It can also of course present a dialog or other UI to the user and ask for their opinion.