2013-08-26 26 views
5

我的Mac應用程序應該允許拖放kPasteboardTypeFileURLPromise從文件承諾或到粘貼板。錯誤處理時保持kPasteboardTypeFileURLPromise

據我所知,每個NSPasteboardItem應該在其可用的類型中有kPasteboardTypeFileURLPromise。

與由拖動目標處理的NSURL不同,kPasteboardTypeFileURLPromise由拖動源寫入到由拖動目標設置的目標位置。

但是,當源未能履行承諾時,似乎沒有辦法將目標錯誤及其用戶信息傳遞給恢復(例如NSRecoveryAttempterErrorKey等)。

拖動kPasteboardTypeFileURLPromise時處理錯誤的最佳做法是什麼? 它們是否應該由拖放源處理?

與由目標處理錯誤的拖動NSURL相比,它可能會導致一些不一致。

回答

1

如果u需要複製文件到剪貼板,使用此:

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