I've been sifting through the newer APIs and header comments for adding file promises to the pasteboard during dragging, and have a question. Assuming the code below, should I write something back to the pasteboard/item at the end of a file promise?
-(void)mouseDown:(NSEvent *)theEvent {
NSPasteboardItem *p = [NSPasteboardItem new];
[p setDataProvider:self forTypes:@[NSPasteboardTypeTabularText, NSPasteboardTypeString, NSPasteboardTypePDF, (__bridge NSString *)kPasteboardTypeFileURLPromise]];
[p setString:kUTTypeXLS forType:(__bridge NSString *)kPasteboardTypeFilePromiseContent];
NSDraggingItem *i = [[NSDraggingItem alloc] initWithPasteboardWriter:p];
NSSize s = NSMakeSize(64, 64);
[i setDraggingFrame:(NSRect){[self convertPoint:theEvent.locationInWindow fromView:nil], s} contents:[NSImage imageWithSize:s flipped:false drawingHandler:^BOOL(NSRect dstRect) {
[clipping drawInRect:dstRect];
return true;
}]];
[self beginDraggingSessionWithItems:@[i] event:theEvent source:self];
}
#pragma mark NSDraggingSource
-(NSDragOperation)draggingSession:(NSDraggingSession *)session sourceOperationMaskForDraggingContext:(NSDraggingContext)context {
return NSDragOperationCopy;
}
#pragma mark NSPasteboardItemDataProvider
-(void)pasteboard:(NSPasteboard *)pasteboard item:(NSPasteboardItem *)item provideDataForType:(NSString *)type {
NSMutableString *s = [NSMutableString string];
if ([type isEqualToString:(__bridge NSString *)kPasteboardTypeFileURLPromise]) {
static NSCharacterSet *set;
if (!set) {
NSMutableCharacterSet *c = [NSMutableCharacterSet characterSetWithRange:NSMakeRange('0', 10)];
[c addCharactersInRange:NSMakeRange('A', 26)];
[c addCharactersInRange:NSMakeRange('a', 26)];
[c addCharactersInString:@"-_."];
set = c.invertedSet;
}
NSMutableString *t = [self.window.representedURL ? self.window.representedURL.lastPathComponent.stringByDeletingPathExtension : self.window.title mutableCopy];
[t replaceOccurrencesOfString:@" " withString:@"-" options:0 range:NSMakeRange(0, t.length)];
NSRange r;
while ((r = [t rangeOfCharacterFromSet:set]).location != NSNotFound)
[t deleteCharactersInRange:r];
PasteboardRef p;
PasteboardCreate((__bridge CFStringRef)pasteboard.name, &p);
CFURLRef u;
PasteboardCopyPasteLocation(p, &u);
CFRelease(p);
[s writeToURL:[(__bridge_transfer NSURL *)u URLByAppendingPathComponent:[t stringByAppendingPathExtension:@"xls"]] atomically:true encoding:NSUTF8StringEncoding error:NULL];
}
}