|
@@ -164,6 +164,8 @@ extension KMPDFThumbnailView {
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
+ return super.collectionView(collectionView, acceptDrop: draggingInfo, indexPath: indexPath, dropOperation: dropOperation)
|
|
|
+ } else if (pboard.availableType(from: [.itemDragType]) != nil) {
|
|
|
return super.collectionView(collectionView, acceptDrop: draggingInfo, indexPath: indexPath, dropOperation: dropOperation)
|
|
|
} else if ((pboard.availableType(from: [.fileURL])) != nil) {
|
|
|
//获取url
|
|
@@ -190,45 +192,45 @@ extension KMPDFThumbnailView {
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
-// func collectionView(_ collectionView: NSCollectionView,
|
|
|
-// pasteboardWriterForItemAt indexPath: IndexPath) -> NSPasteboardWriting? {
|
|
|
-// /** Here the sample provide a custom NSFilePromise#imageLiteral(resourceName: "_DSC9930.jpeg")#imageLiteral(resourceName: "_DSC9930.jpeg")Provider.
|
|
|
-// Here we provide a custom provider, offering the row to the drag object, and its URL.
|
|
|
-// */
|
|
|
-//// var provider: NSFilePromiseProvider?
|
|
|
-////
|
|
|
-////// guard let photoItem =
|
|
|
-////// dataSource.itemIdentifier(for: IndexPath(item: indexPath.item, section: 0)) else { return provider }
|
|
|
-////// let photoFileExtension = photoItem.fileURL.pathExtension
|
|
|
-//// let photoFileExtension = "pdf"
|
|
|
-////
|
|
|
-//// if #available(macOS 11.0, *) {
|
|
|
-//// let typeIdentifier = UTType(filenameExtension: photoFileExtension)
|
|
|
-//// provider = FilePromiseProvider(fileType: typeIdentifier!.identifier, delegate: self)
|
|
|
-//// } else {
|
|
|
-//// let typeIdentifier =
|
|
|
-//// UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, photoFileExtension as CFString, nil)
|
|
|
-//// provider = FilePromiseProvider(fileType: typeIdentifier!.takeRetainedValue() as String, delegate: self)
|
|
|
-//// }
|
|
|
-////
|
|
|
-//// // Send out the indexPath and photo's url dictionary.
|
|
|
-//// do {
|
|
|
-//// let data = try NSKeyedArchiver.archivedData(withRootObject: indexPath, requiringSecureCoding: false)
|
|
|
-//// provider!.userInfo = [FilePromiseProvider.UserInfoKeys.urlKey: self.document!.documentURL as Any,
|
|
|
-//// FilePromiseProvider.UserInfoKeys.indexPathKey: data]
|
|
|
-//// } catch {
|
|
|
-//// fatalError("failed to archive indexPath to pasteboard")
|
|
|
-//// }
|
|
|
-//// return provider
|
|
|
-//
|
|
|
+ func collectionView(_ collectionView: NSCollectionView,
|
|
|
+ pasteboardWriterForItemAt indexPath: IndexPath) -> NSPasteboardWriting? {
|
|
|
+ /** Here the sample provide a custom NSFilePromise#imageLiteral(resourceName: "_DSC9930.jpeg")#imageLiteral(resourceName: "_DSC9930.jpeg")Provider.
|
|
|
+ Here we provide a custom provider, offering the row to the drag object, and its URL.
|
|
|
+ */
|
|
|
+ var provider: NSFilePromiseProvider?
|
|
|
+
|
|
|
+// guard let photoItem =
|
|
|
+// dataSource.itemIdentifier(for: IndexPath(item: indexPath.item, section: 0)) else { return provider }
|
|
|
+// let photoFileExtension = photoItem.fileURL.pathExtension
|
|
|
+ let photoFileExtension = "pdf"
|
|
|
+
|
|
|
+ if #available(macOS 11.0, *) {
|
|
|
+ let typeIdentifier = UTType(filenameExtension: photoFileExtension)
|
|
|
+ provider = FilePromiseProvider(fileType: typeIdentifier!.identifier, delegate: self)
|
|
|
+ } else {
|
|
|
+ let typeIdentifier =
|
|
|
+ UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, photoFileExtension as CFString, nil)
|
|
|
+ provider = FilePromiseProvider(fileType: typeIdentifier!.takeRetainedValue() as String, delegate: self)
|
|
|
+ }
|
|
|
+
|
|
|
+ // Send out the indexPath and photo's url dictionary.
|
|
|
+ do {
|
|
|
+ let data = try NSKeyedArchiver.archivedData(withRootObject: indexPath, requiringSecureCoding: false)
|
|
|
+ provider!.userInfo = [FilePromiseProvider.UserInfoKeys.urlKey: self.document!.documentURL as Any,
|
|
|
+ FilePromiseProvider.UserInfoKeys.indexPathKey: data]
|
|
|
+ } catch {
|
|
|
+ fatalError("failed to archive indexPath to pasteboard")
|
|
|
+ }
|
|
|
+ return provider
|
|
|
+
|
|
|
// guard let model = indexPath as? IndexPath else {
|
|
|
// return nil
|
|
|
// }
|
|
|
-//
|
|
|
+
|
|
|
// let pastBoard = NSPasteboardItem.init()
|
|
|
// pastBoard.setString(String(format: "%ld", model.item), forType: NSPasteboard.PasteboardType.string)
|
|
|
// return pastBoard
|
|
|
-// }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
class FilePromiseProvider: NSFilePromiseProvider {
|
|
@@ -249,8 +251,8 @@ class FilePromiseProvider: NSFilePromiseProvider {
|
|
|
*/
|
|
|
override func writableTypes(for pasteboard: NSPasteboard) -> [NSPasteboard.PasteboardType] {
|
|
|
var types = super.writableTypes(for: pasteboard)
|
|
|
- types.append(kKMLocalForDraggedTypes) // Add our own internal drag type (row drag and drop reordering).
|
|
|
- types.append(.fileURL) // Add the .fileURL drag type (to promise files to other apps).
|
|
|
+ types.append(.fileURL) // Add our own internal drag type (row drag and drop reordering).
|
|
|
+ types.append(.itemDragType) // Add the .fileURL drag type (to promise files to other apps).
|
|
|
return types
|
|
|
}
|
|
|
|
|
@@ -267,7 +269,7 @@ class FilePromiseProvider: NSFilePromiseProvider {
|
|
|
if let url = userInfoDict[FilePromiseProvider.UserInfoKeys.urlKey] as? NSURL {
|
|
|
return url.pasteboardPropertyList(forType: type)
|
|
|
}
|
|
|
- case kKMLocalForDraggedTypes:
|
|
|
+ case .itemDragType:
|
|
|
// Incoming type is "com.mycompany.mydragdrop", return (from our userInfo) the item's indexPath.
|
|
|
let indexPathData = userInfoDict[FilePromiseProvider.UserInfoKeys.indexPathKey]
|
|
|
return indexPathData
|
|
@@ -353,4 +355,8 @@ extension KMPDFThumbnailView: NSFilePromiseProviderDelegate {
|
|
|
|
|
|
}
|
|
|
|
|
|
+extension NSPasteboard.PasteboardType {
|
|
|
+ static let itemDragType = NSPasteboard.PasteboardType("com.mycompany.mydragdrop")
|
|
|
+}
|
|
|
+
|
|
|
|