|
@@ -149,3 +149,117 @@ class KMDocumentController: NSDocumentController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+extension NSDocumentController {
|
|
|
+ func openDocumentWithURLFromPasteboard(_ pboard: NSPasteboard, showNotes: Bool, outError: NSErrorPointer) -> Any? {
|
|
|
+ guard let theURLs = NSURL.readURLs(from: pboard), let theURL = theURLs.first else {
|
|
|
+ if showNotes == false {
|
|
|
+ outError?.pointee = NSError.readPasteboardError(withLocalizedDescription: NSLocalizedString("Unable to load data from clipboard", comment: "Error description"))
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
+// guard theURL.isFileURL else {
|
|
|
+// if showNotes == false {
|
|
|
+// return SKDownloadController.shared.addDownload(for: theURL)
|
|
|
+// }
|
|
|
+// return nil
|
|
|
+// }
|
|
|
+
|
|
|
+ var document: Any?
|
|
|
+// do {
|
|
|
+// let type = try self.type(forContentsOf: theURL)
|
|
|
+// if showNotes == false || SKNotesDocument.readableTypes.contains(type) {
|
|
|
+// document = try self.openDocument(withContentsOf: theURL, display: true)
|
|
|
+// } else if SKMainDocument.readableTypes.contains(type) {
|
|
|
+// for doc in self.documents {
|
|
|
+// if let sourceURL = (doc as? NSObject)?.value(forKey: "sourceFileURL") as? URL, sourceURL == theURL {
|
|
|
+// document = doc
|
|
|
+// break
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if let existingDoc = document as? NSDocument {
|
|
|
+// existingDoc.showWindows()
|
|
|
+// } else {
|
|
|
+// var error: NSError?
|
|
|
+// var data: Data?
|
|
|
+//
|
|
|
+// if NSWorkspace.shared.type(type, conformsToType: SKPDFBundleDocumentType) {
|
|
|
+// if let skimFileURL = try FileManager.default.bundledFileURL(withExtension: "skim", inPDFBundleAt: theURL) {
|
|
|
+// data = try Data(contentsOf: skimFileURL)
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// data = try SKNExtendedAttributeManager.shared().extendedAttributeNamed(SKIM_NOTES_KEY, atPath: theURL.path, traverseLink: true)
|
|
|
+// }
|
|
|
+//
|
|
|
+// let newDocument = try makeUntitledDocument(ofType: SKNotesDocumentType)
|
|
|
+// newDocument.sourceFileURL = theURL
|
|
|
+//
|
|
|
+// if data == nil || newDocument.read(from: data ?? Data(), ofType: SKNotesDocumentType) {
|
|
|
+// self.addDocument(newDocument)
|
|
|
+// newDocument.makeWindowControllers()
|
|
|
+// newDocument.showWindows()
|
|
|
+// } else {
|
|
|
+// document = nil
|
|
|
+// outError?.pointee = error
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } catch {
|
|
|
+// outError?.pointee = error as NSError
|
|
|
+// }
|
|
|
+
|
|
|
+ return document
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ func openDocumentWithImageFromPasteboard(_ pboard: NSPasteboard, error outError: NSErrorPointer) -> Any? {
|
|
|
+ var document: Any?
|
|
|
+// var data: Data?
|
|
|
+// var type: String?
|
|
|
+//
|
|
|
+// if pboard.canReadItem(withDataConformingToTypes: [NSPasteboard.PasteboardType.PDF]) {
|
|
|
+// pboard.types
|
|
|
+// data = pboard.data(forType: NSPasteboard.PasteboardType.PDF)
|
|
|
+// type = SKPDFDocumentType
|
|
|
+// } else if pboard.canReadItem(withDataConformingToTypes: [SKPasteboardTypePostScript]) {
|
|
|
+// pboard.types
|
|
|
+// data = pboard.data(forType: SKPasteboardTypePostScript)
|
|
|
+// type = isEncapsulatedPostScriptData(data) ? SKEncapsulatedPostScriptDocumentType : SKPostScriptDocumentType
|
|
|
+// } else if pboard.canReadItem(withDataConformingToTypes: [NSPasteboard.PasteboardType.tiff]) {
|
|
|
+// pboard.types
|
|
|
+// data = convertTIFFDataToPDF(pboard.data(forType: NSPasteboard.PasteboardType.tiff))
|
|
|
+// type = SKPDFDocumentType
|
|
|
+// } else {
|
|
|
+// let images = pboard.readObjects(forClasses: [NSImage.self], options: [:]) as? [NSImage]
|
|
|
+// let strings = pboard.readObjects(forClasses: [NSAttributedString.self], options: [:]) as? [NSAttributedString]
|
|
|
+// if let images = images, images.count > 0 {
|
|
|
+// data = convertTIFFDataToPDF(images[0].tiffRepresentation)
|
|
|
+// type = SKPDFDocumentType
|
|
|
+// } else if let strings = strings, strings.count > 0 {
|
|
|
+// data = convertStringsToPDF(strings)
|
|
|
+// type = SKPDFDocumentType
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// if let data = data, let type = type {
|
|
|
+// var error: NSError?
|
|
|
+// document = makeUntitledDocument(ofType: type, error: &error)
|
|
|
+//
|
|
|
+// if (document as? NSDocument)?.read(from: data, ofType: type, error: &error) ?? false {
|
|
|
+// addDocument(document as! NSDocument)
|
|
|
+// (document as! NSDocument).makeWindowControllers()
|
|
|
+// (document as! NSDocument).showWindows()
|
|
|
+// } else {
|
|
|
+// document = nil
|
|
|
+// if let outError = outError {
|
|
|
+// outError.pointee = error
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } else if let outError = outError {
|
|
|
+// outError.pointee = NSError.readPasteboardError(withLocalizedDescription: NSLocalizedString("Unable to load data from clipboard", comment: "Error description"))
|
|
|
+// }
|
|
|
+//
|
|
|
+ return document
|
|
|
+ }
|
|
|
+
|
|
|
+}
|