faqts : Computers : Programming : Application Frameworks : Macintosh : Cocoa

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

7 of 8 people (88%) answered Yes
Recently 7 of 8 people (88%) answered Yes

Entry

How do I let my application drag and drop files out to the finder?

May 16th, 2002 16:39
Tom Waters,


You might be tempted to use NSPasteboard's setString:forType:, 
but the filenames are always an array, even if there's only one.  So 
you have to use setPropertyList:forType

NSPasteboard *pb = [NSPasteboard 
pasteboardWithName:NSDragPboard];
NSString *filename = @"/tmp/test.txt";
[pb declareTypes: [NSArray 
arrayWithObject:NSFilenamesPboardType]
owner:self];
[pb setPropertyList:[NSArray arrayWithObject:filename] 
forType:NSFilenamesPboardType];
[self dragImage:iconImage at:dragPoint offset:NSMakeSize(0,0) 
event:event
pasteboard:pb source:self slideBack:YES];