Re: Best 'Cocoa' File Preview
Re: Best 'Cocoa' File Preview
- Subject: Re: Best 'Cocoa' File Preview
- From: Graham Cox <email@hidden>
- Date: Sun, 12 Jul 2009 16:24:18 +1000
On 12/07/2009, at 1:02 PM, David Blanton wrote:
What is the preferred method of showing a file preview (my unique
content) in an NSOpenPanel ?
The Accessory View looks 'hooky' to use , I want the preview in the
next browser column.
If you can image your content to a JPEG and/or PDF, it's very easy to
add these as Quicklook thumbnails and previews to a document package.
That avoids the need to write a QL plug-in for your format, and the
Open panel and Finder and QL preview in the Finder will display these
directly.
You need to use particular names for these preview images - it's given
in the docs somewhere. Here's the code I use to add them in my app
(subclass of NSDocument):
- (NSFileWrapper*) fileWrapperOfType:(NSString*) typeName error:
(NSError**) outError
{
NSData* mainContent = [self dataOfType:typeName error:outError];
if( mainContent == nil )
{
if( outError )
*outError = [NSError errorWithDomain:kOrteliusErrorDomain
code:kOrteliusNoDataErrorCode userInfo:nil];
return nil;
}
NSFileWrapper* fw = [[NSFileWrapper alloc]
initDirectoryWithFileWrappers:nil];
[fw addRegularFileWithContents:mainContent
preferredFilename:kOrteliusFilePackageMainContentFile];
// add "Quick Look" preview folder:
NSFileWrapper* qlFolder = [[NSFileWrapper alloc]
initDirectoryWithFileWrappers:nil];
[qlFolder setPreferredFilename:@"QuickLook"];
[fw addFileWrapper:qlFolder];
[qlFolder release];
// add preview and thumbnail
NSData* preview = [[self drawing] thumbnailData]; // JPEG data
if( preview )
[qlFolder addRegularFileWithContents:preview
preferredFilename:@"Thumbnail.jpg"];
preview = [[self drawing] pdf]; // PDF data
if( preview )
[qlFolder addRegularFileWithContents:preview
preferredFilename:@"Preview.pdf"];
return [fw autorelease];
}
--Graham
_______________________________________________
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