Re: Requiring a User to Save a Document before Being Able to Edit It
Re: Requiring a User to Save a Document before Being Able to Edit It
- Subject: Re: Requiring a User to Save a Document before Being Able to Edit It
- From: Kyle Sluder <email@hidden>
- Date: Tue, 11 Feb 2014 12:29:01 -0800
On Tue, Feb 11, 2014, at 12:21 PM, SevenBits wrote:
> Let’s discuss hypotheticals. Let’s say you’re developing a software
> application that lets you put files together into an archive (be it .zip,
> .tar.gz, whatever). Let’s say that, for your application to work
> properly, you need to have the user select a location for and save the
> file before they can do anything to it. This is similar to how Xcode
> requires you to enter a name and location for a new project before you
> can build it or really do anything to it.
>
> What would the best practice be for implementing something like this in
> Cocoa in an unobtrusive, Mac-like way?
Presuming you're using NSDocument, ask the user for the saving path,
then construct an instance of your NSDocument subclass and send it
-initForURL:(user's chosen URL) withContentsOfURL:nil ofType:(your
document UTI) error:outError.
> (FYI: the intention of this thread
> is _not_ to debate whether or not something like this _should_ be done).
> Apple’s default NSDocument setup in Cocoa doesn’t really work well for
> this kind of model out of the box.
Well, it _is_ possible to separate "file cannot exist purely in memory"
from "user must explicitly save document".
Instead of requesting a saving URL upfront and constructing the document
from nothing, you could instead construct a document with
-initForURL:nil withContentsOfURL:nil…, then immediately tell it to
autosave. That gives you a file on disk (in the Autosaved Documents
area) that you can move components into and out of, but it doesn't break
the Lion Autosave user experience.
It's possible that your situation is well and truly incompatible with
that, but the two concepts are separable.
--Kyle Sluder
_______________________________________________
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