NSPasteboardItem kPasteboardTypeFileURLPromise
NSPasteboardItem kPasteboardTypeFileURLPromise
- Subject: NSPasteboardItem kPasteboardTypeFileURLPromise
- From: Gabriele de Simone <email@hidden>
- Date: Fri, 12 Aug 2011 17:55:46 +0200
Hi everyone,
I am trying to implement "promise" type file drags from my app to the Finder using the new, 10.6-and-later NSPasteboardItem APIs. I found almost no information about it, and it didn't seem to make sense.
It starts in the outlineView:writeItems:toPasteboard: method of my NSOutlineViewDataSource instance. In there, I allocate various NSPasteboardItems for all files being dragged.
[...]
NSArray * pasteboardTypes = [NSArray arrayWithObjects:
(NSString *)kPasteboardTypeFileURLPromise,
(NSString *)kPasteboardTypeFilePromiseContent, nil];
NSMutableArray * pasteboardItems = [NSMutableArray array];
for ( <however many files are selected> ) {
NSPasteboardItem * pasteboardItem = [[[NSPasteboardItem alloc] init] autorelease];
[pasteboardItem setDataProvider:provider forTypes:pasteboardTypes];
[pasteboardItems addObject:pasteboardItem];
}
[pasteboard writeObjects:pasteboardItems];
[...]
As the drag moves away from my application and over the Desktop, the "provider" instance used above is called once for each NSPasteboardItem, to get the kPasteboardTypeFilePromiseContent. That part is (presumably) easy, and my provider is returning the UTI for the promised file, based on its contents. In the source code below, I have inserted kUTTypePNG to simplify:
- (void)pasteboard:(NSPasteboard *)pasteboard item:(NSPasteboardItem *)item provideDataForType:(NSString *)type {
if ( [type isEqualToString:(NSString *)kPasteboardTypeFilePromiseContent] ) {
[item setPropertyList:kUTTypePNG forType:type];
} else if ( [type isEqualToString:(NSString *)kPasteboardTypeFileURLPromise] ) {
// What to do here?
}
}
The Finder seems happy with my UTI, and allows the drag to continue. The problem is that if I drop the files onto the desktop, the NSPasteboardDataProvider instance is called again, this time to get the kPasteboardTypeFileURLPromise data.
Intuitively, one would think that you have to:
- Create the file that was promised, and keep the URL to that file handy.
- Call one of the methods on NSPasteboardItem to supply the URL of the promised file.
- Allow the Finder to copy/move the files at will.
Unfortunately, there is no -[NSPasteboardItem setURL:forType:] method, no -[NSURL writeToPasteboardItem:] method, or anything else that would seem to "fit" this scenario.
What am I missing?
Thanks,
Gabe
_______________________________________________
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