On Jun 20, 2014, at 16:44 , John Brownie <john_brow...@sil.org> wrote:

> I have a complex document bundle, and I'm trying to figure out which files 
> within the package have unsaved changes, and it looks like there's no support 
> for that model in NSDocument.

I haven’t been following this thread very closely, so I may misunderstand, but 
there’s a fairly simple way of doing this that might work for you.

The key is to *keep* the top level NSFileWrapper you’re given when opening the 
(multi-file) document. When creating a new one, just set the kept wrapper ivar 
or property to nil.

When any change is made to the document (so you’d put this in the same place 
that creates undo actions, I guess), you determine which files within the 
package are/will be affected, and you *remove* the corresponding sub-wrapper 
from the store top level wrapper.

At save time, you walk your new/intended file hierarchy, creating missing 
wrappers as you go. By definition, wrappers that aren’t missing represent files 
that haven’t changed. When you’re done, you return this revised wrapper from 
your save method.

Because you haven’t re-created the wrappers for non-changed files, the 
NSDocument saving mechanism realizes that those files don’t need to be 
re-written and hard-links to the existing ones, typically. Thus, if your 
package contains 100 files but only 1 has changed, a save or autosave will be 
fast because only 1 file gets written and copied (from the temp save location 
to its final location).

Is that procedure of any use to you?

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to