• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: several questions about saving a bundle in an NSDocument based application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: several questions about saving a bundle in an NSDocument based application


  • Subject: Re: several questions about saving a bundle in an NSDocument based application
  • From: Graham Cox <email@hidden>
  • Date: Tue, 2 Jun 2009 14:39:36 +1000


On 02/06/2009, at 11:40 AM, Matthew Jeorrett wrote:

I have successfully implemented the NSDocument architecture in my application and have implemented saving and loading documents by overriding the "dataOfType:error:" and "readFromData:ofType:error:"; methods. I now want to be able to export my document into a folder selected by the user. The items I will be putting in the folder are a few png images and a plain text file. I have created a new package document type in the build target properties with the role value set as none. The first gap in my knowledge is what the store type should be?

I would guess 'binary' if you're writing out the content yourself. I'm not sure where this setting is used, it doesn't actually seem to make any difference.


I am guessing that I should override the fileWrapperOfType:error: method so that if the type is "document package" I call a method to create a directory file wrapper with the images and text files I want instead of the default behaviour which is to create a file type NSFileWrapper with the data from the "dataOfType:error:" method. I assume that the save panel will have asked the user for a directory as the document type is a package.

Yes - you override -fileWrapperOfType:error: and build your own file wrapper with your package content.


Finally, assuming my approach so far is correct, my last problem is I am unsure of how to add PNG images and a text file to the wrapper. The images are stored as CGImageRefs and the text is in an NSString.
If anyone can clear any of this or maybe even all of this up or point me in the direction of an example I would be much obliged.

You need to first get the images/text in the form of NSData representing the file contents. You then add these to the package fileWrapper using the -addRegularFileWithContents:preferredFilename: method




Here's some cut down code from my current project that writes out a package, including Quicklook thumbnails, which is simiar to your situation:

- (NSFileWrapper*) fileWrapperOfType:(NSString*) typeName error: (NSError**) outError
{
NSData* mainContent = [self dataOfType:kDKDrawingDocumentType error:outError];


if( mainContent == nil )
{
*outError = [NSError errorWithDomain:kOrteliusErrorDomain code:kOrteliusNoDataErrorCode userInfo:nil];
return nil;
}


NSFileWrapper* fw = [[NSFileWrapper alloc] initDirectoryWithFileWrappers:nil];

[fw addRegularFileWithContents:mainContent preferredFilename:@"main_content"];

// add "Quick Look" preview:

NSFileWrapper* qlFolder = [[NSFileWrapper alloc] initDirectoryWithFileWrappers:nil];
[qlFolder setPreferredFilename:@"QuickLook"];
[fw addFileWrapper:qlFolder];
[qlFolder release];

// add preview and thumbnail

NSData* preview = [[self drawing] thumbnailData];
[qlFolder addRegularFileWithContents:preview preferredFilename:@"Thumbnail.jpg"];

if( mSavePreview )
{
preview = [[self drawing] pdf];
[qlFolder addRegularFileWithContents:preview preferredFilename:@"Preview.pdf"];
}

return [fw autorelease];
}


_______________________________________________

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


  • Follow-Ups:
    • Re: several questions about saving a bundle in an NSDocument based application
      • From: Michael Ash <email@hidden>
References: 
 >several questions about saving a bundle in an NSDocument based application (From: Matthew Jeorrett <email@hidden>)

  • Prev by Date: Re: How determine if file is in Trash, given Path or Alias
  • Next by Date: Re: several questions about saving a bundle in an NSDocument based application
  • Previous by thread: several questions about saving a bundle in an NSDocument based application
  • Next by thread: Re: several questions about saving a bundle in an NSDocument based application
  • Index(es):
    • Date
    • Thread