Re: Advice on document handling
Re: Advice on document handling
- Subject: Re: Advice on document handling
- From: Quincey Morris <email@hidden>
- Date: Fri, 20 Jun 2014 17:27:13 -0700
On Jun 20, 2014, at 16:44 , John Brownie <email@hidden> 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 (email@hidden)
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:
This email sent to email@hidden