Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error handling when keeping kPasteboardTypeFileURLPromise

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.

like image 421
Yoav Avatar asked Nov 12 '22 23:11

Yoav


1 Answers

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
like image 142
Aleksey Mazurenko Avatar answered Dec 04 '22 13:12

Aleksey Mazurenko