Re: Help with pasteboard
Re: Help with pasteboard
- Subject: Re: Help with pasteboard
- From: Brian Webster <email@hidden>
- Date: Wed, 17 Oct 2001 16:52:38 -0500
Oops! The message got accidentally sent before I was finished
with it. Here's the complete message.
On Wednesday, October 17, 2001, at 11:41 AM, cocoa-dev-
email@hidden wrote:
I have a tableview and when i drag from it i can get a NSString to the
pasteboard, but i also want to drag to the
finder and have that same string stored in a file, I have tried all i
could find but i can't figure it out.
The way to create a file in the Finder is to write data of type
NSFileContentsPboardType to the pasteboard. But, when you drag
a string to somewhere in the Finder, it should automatically
create a clipping file. I'm not sure which of these types the
Finder will grab if they are both present, though.
Anyway, the code to write a string to the pasteboard in such a
manner would be something like this:
NSString *stringToWrite;
NSPasteboard *pboard;
NSFileWrapper *stringFile;
NSData *stringData;
[pboard declareTypes:[NSArray
arrayWithObjects:NSStringPboardType, NSFileContentsPboardType,
nil]];
[pboard setString:stringToWrite forType:NSStringPboardType];
stringData = [stringToWrite
dataUsingEncoding:NSMacOSRomanStringEncoding];
stringFile = [[NSFileWrapper alloc]
initRegularFileWithContents:stringData];
[stringFile setPreferredFilename:@"String file"];
[pboard writeFileWrapper:stringFile];
[stringFile release];
You can substitute whatever string encoding and file name you want.
--
Brian Webster
email@hidden
http://homepage.mac.com/bwebster