Error handling when keeping kPasteboardTypeFileURLPromise

284 views Asked by At

My Mac app should allow dragging and dropping of kPasteboardTypeFileURLPromise to get file promises from or to the pasteboard.

As far as I understand, each NSPasteboardItem should have kPasteboardTypeFileURLPromise in its available types.

Unlike NSURLs which are handled by the dragging destination, kPasteboardTypeFileURLPromise are written by the dragging source to the destination location set by the dragging destination.

However, when the source fails to fulfill the promise, it seems that there is no way to pass the destination the error with its user info for recovery (e.g. NSRecoveryAttempterErrorKey, etc.).

What is the best practice for handling errors when dragging kPasteboardTypeFileURLPromise? Should they be handled by the dragging source?

It might cause some inconsistency compared to dragged NSURLs for which errors are handled by the destination.

1

There are 1 answers

0
Aleksey Mazurenko On

if u need to copy file to clipboard, use this:

NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
[pasteBoard declareTypes:[NSArray arrayWithObjects:NSStringPboardType, NSFilenamesPboardType, nil] owner:nil];
[pasteBoard setString:self.fullpath forType:NSStringPboardType];                // copy file path as string
[pasteBoard setPropertyList:@[self.fullpath] forType:NSFilenamesPboardType];    // copy file link