On Jan 28, 2015, at 16:16 , Charles Jenkins <cejw...@gmail.com> wrote:
> 
> I need to have a File > Export command to save the document in OpenXML 
> format. I’ve done some research in the Developer Library, and the best clues 
> I’ve found so far are in the Sketch app. Sketch manages multiple output types 
> by overriding NSDocument’s dataOfType:error: and paying attention to the 
> requested type name. Somehow that gets called by saveDocumentTo:
> 
> My app needs to work more like Pages, by presenting a dialog confirming 
> export options before the OpenXML file is generated. I can see where I might 
> have to do this by overriding saveDocumentTo: so my options dialog will 
> appear and eventually dataOfType:error: will be called. But I’m worried that 
> dataOfType and fileWrapperOfType can’t both be used???


(It's not clear whether you really want File -> Export, or whether you want an 
alternative document type for a regular Save/Save As/etc. …)

There’s no set in stone way of handling export, but I think a rational place to 
start is to think of it as writing a file format that’s incompatible with your 
document editing environment. That is, any file formats in which you can save 
your data model without loss of information are a document type, while an 
export type implies you can’t re-open the exported file and have the document 
data you started with.

This can get a little confusing, because your plist might have “document” type 
definitions in your plist for types that your document can’t save as — if you 
can view or import other file formats, for example.

But generally, document types are handled by the NSDocument save mechanism, 
exports aren’t. So, when the user chooses an export function:

— If necessary, put up a sheet asking for the export parameters.

If this information is simple, you can add it as an accessory view of the save 
panel, and skip this step. However, some things are awkward to do from the save 
panel, particularly validation of user choices, so it’s often easier to use a 
separate sheet first.

— Put up a NSSavePanel asking for the destination of the save. (This will 
automatically take care of sandboxing restrictions.)

— If necessary, customize the save panel to allow the user to choose an export 
format. (Often, the export format is determined by the originally chosen export 
function, or is chosen in the export parameters sheet, but sometimes it’s 
clearer to let the specific format be chosen at the same time as the file is 
named.)

Once you’ve collected all this information, you can write the export file 
directly, not using the NSDocument save mechanism. The only thing you have to 
take care with is concurrency issues with the document/model, especially if you 
move the export to a background thread to avoid blocking the main thread.



_______________________________________________

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