Re: Help with pasteboard
Re: Help with pasteboard
- Subject: Re: Help with pasteboard
- From: "Mark's Studio" <email@hidden>
- Date: Thu, 18 Oct 2001 13:06:58 +0200
Thanks for your replay
Yes that's what i tried but it's not working
If i put more than one thing on the pasteboard in writeRows it does not
work.
so i tried only declaring the types and then see what was requested
- (BOOL)tableView:(NSTableView *)tv writeRows:(NSArray*)rows
toPasteboard:(NSPasteboard*)pboard
{
[pboard declareTypes:[NSArray
arrayWithObjects:NSStringPboardType,NSFileContentsPboardType, nil]
owner:self];
}
- (void)pasteboard:(NSPasteboard *)sender provideDataForType:(NSString
*)type
{
NSLog(@"provideDataForType %@",type);
}
The finder only asks for
provideDataForType (
NSStringPboardType
)
if i drag and drop on my own Tableview( AddressView ) it asks for
proposedDropOperation (
NSStringPboardType,
NXFileContentsPboardType,
"NeXT plain ascii pasteboard type"
)
[AddressView registerForDraggedTypes:[NSArray
arrayWithObjects:NSStringPboardType,@"ABVCardStringPBoardType", nil]];
Also is it enough to add an file extension to setPreferredFilename to
set the type of file?
On onsdag, oktober 17, 2001, at 11:52 , Brian Webster wrote:
>
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
>
_______________________________________________
>
cocoa-dev mailing list
>
email@hidden
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
>
Peter Mark
Mark's Recording Studio A/S
Faelledvej 19 b DK2200 N
Copenhagen Denmark
Tel: +45 35366078 Fax: +45 35366038
www.marks-studio.dk
email@hidden