|
@@ -655,7 +655,6 @@ class KMLeftSideViewController: KMSideViewController {
|
|
|
// [thumbnailTableView setTypeSelectHelper:[SKTypeSelectHelper typeSelectHelperWithMatchOption:SKFullStringMatch]];
|
|
|
// //支持拖拽的文字类型
|
|
|
// [thumbnailTableView registerForDraggedTypes:@[KPDFThumbnailLocalForDraggedTypes,NSFilenamesPboardType]];
|
|
|
-// self.thumbnailTableView.registerForDraggedTypes([.localDraggedTypes, .fileURL])
|
|
|
self.thumbnailTableView.registerForDraggedTypes([.localDraggedTypes, .fileURL,.string,.pdf])
|
|
|
// self.thumbnailTableView.registerForDraggedTypes(NSFilePromiseReceiver.readableDraggedTypes.map { NSPasteboard.PasteboardType($0) })
|
|
|
// self.thumbnailTableView.setDraggingSourceOperationMask([.copy, .delete], forLocal: true)
|
|
@@ -2709,11 +2708,15 @@ extension KMLeftSideViewController: NSTableViewDelegate, NSTableViewDataSource {
|
|
|
continue
|
|
|
}
|
|
|
let type = _url.pathExtension.lowercased()
|
|
|
+ if type == "pdf" || KMImageToPDFMethod.supportedImageTypes().contains(type) {
|
|
|
hasValidFile = true
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (!hasValidFile) {
|
|
|
return NSDragOperation(rawValue: 0)
|
|
|
+ } else {
|
|
|
+ return .move
|
|
|
}
|
|
|
}
|
|
|
return NSDragOperation(rawValue: 0)
|
|
@@ -2746,23 +2749,17 @@ extension KMLeftSideViewController: NSTableViewDelegate, NSTableViewDataSource {
|
|
|
var insertIndexSet = IndexSet()
|
|
|
var pdf = CPDFDocument(url: URL(fileURLWithPath: path))
|
|
|
if let data = pdf?.isEncrypted, data {
|
|
|
- // if ([pdf isEncrypted]) {
|
|
|
- // KMDecryptWindowController *vc = [[KMDecryptWindowController alloc] init];
|
|
|
- // vc.filePath = url;
|
|
|
- // [vc beginSheetModalForWindow:self.window completionHandler:^(NSString *password) {
|
|
|
- // if (password) {
|
|
|
- // [pdf unlockWithPassword:password];
|
|
|
- // for(NSUInteger i=0; i<pdf.pageCount;i++) {
|
|
|
- // PDFPage *page = [[pdf pageAtIndex:i] copy];
|
|
|
- // [self.pdfView.document insertPage:page atIndex:index];
|
|
|
- // [insertIndexSet addIndex:index];
|
|
|
- // index++;
|
|
|
- // [page release];
|
|
|
- // }
|
|
|
- // [self insertPages:insertIndexSet pageAtIndex:(index-1)];
|
|
|
- // }
|
|
|
- // }];
|
|
|
- // [vc release];
|
|
|
+ KMBaseWindowController.checkPassword(url: URL(fileURLWithPath: path)) { success, resultPassword in
|
|
|
+ if success && resultPassword.isEmpty == false {
|
|
|
+ for i in 0 ..< (pdf?.pageCount ?? 0) {
|
|
|
+ let page = pdf?.page(at: i).copy() as? CPDFPage
|
|
|
+ self.listView.document.insertPageObject(page!, at: UInt(index))
|
|
|
+ insertIndexSet.insert(index)
|
|
|
+ index += 1
|
|
|
+ }
|
|
|
+ self.insertPages(insertIndexSet, pageAt: index-1)
|
|
|
+ }
|
|
|
+ }
|
|
|
} else {
|
|
|
for i in 0 ..< (pdf?.pageCount ?? 0) {
|
|
|
// PDFPage *page = [[pdf pageAtIndex:i] copy];
|
|
@@ -2821,63 +2818,62 @@ extension KMLeftSideViewController: NSTableViewDelegate, NSTableViewDataSource {
|
|
|
// [self.pageLabels setArray:[[self.pdfView document] pageLabels]];
|
|
|
self.listView.layoutDocumentView()
|
|
|
self.resetThumbnails()
|
|
|
- }
|
|
|
-// else if ([pasteboard availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]] && [tableView isEqual:leftSideController.thumbnailTableView]) {
|
|
|
-// if (![[IAPProductsManager defaultManager] isAvailableAllFunction]) {
|
|
|
-// [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
|
|
|
-//
|
|
|
-// return NO;
|
|
|
-// }
|
|
|
-//
|
|
|
-// NSArray *fileNames = [pasteboard propertyListForType:NSFilenamesPboardType];
|
|
|
-// NSMutableIndexSet *insertIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
|
|
|
-// __block NSInteger index = row;
|
|
|
-//
|
|
|
+ } else if pasteboard.availableType(from: [.fileURL]) != nil && tableView.isEqual(to: self.thumbnailTableView) {
|
|
|
+ if IAPProductsManager.default().isAvailableAllFunction() == false {
|
|
|
+ KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ var fileNames = pasteboard.propertyList(forType: .fileURL)
|
|
|
+ var insertIndexSet = IndexSet()
|
|
|
+ var index = row
|
|
|
+
|
|
|
// if (fileNames.count == 1) {
|
|
|
-// NSString *path = fileNames.firstObject;
|
|
|
-// NSString *pathExtension = [path.pathExtension lowercaseString];
|
|
|
-// if ([pathExtension isEqualToString:@"pdf"]) {
|
|
|
-// PDFDocument *pdf = [[[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:path]]autorelease];
|
|
|
-// if ([pdf isEncrypted]) {
|
|
|
+ if fileNames != nil {
|
|
|
+// var path = fileNames.first as? String ?? ""
|
|
|
+ var path = fileNames as? String ?? ""
|
|
|
+ let url = URL(string: path)
|
|
|
+ let pathExtension = url?.pathExtension.lowercased() ?? ""
|
|
|
+ if pathExtension == "pdf" {
|
|
|
+ let pdf = CPDFDocument(url: url!)
|
|
|
+ if let data = pdf?.isEncrypted, data {
|
|
|
// KMDecryptWindowController *vc = [[KMDecryptWindowController alloc] init];
|
|
|
-// vc.filePath = path;
|
|
|
-// [vc beginSheetModalForWindow:self.window completionHandler:^(NSString *password) {
|
|
|
-// if (password) {
|
|
|
-// [pdf unlockWithPassword:password];
|
|
|
-// for (NSUInteger i = 0; i< pdf.pageCount; i++) {
|
|
|
-// PDFPage *page = [[pdf pageAtIndex:i] copy];
|
|
|
-// [self.pdfView.document insertPage:page atIndex:index];
|
|
|
-// [insertIndexSet addIndex:index];
|
|
|
-// index++;
|
|
|
-// [page release];
|
|
|
-// }
|
|
|
-// [self insertPages:insertIndexSet pageAtIndex:(index-1)];
|
|
|
-// }
|
|
|
-// }];
|
|
|
-// [vc release];
|
|
|
-// } else {
|
|
|
-// for (NSUInteger i = 0; i < pdf.pageCount; i++) {
|
|
|
-// PDFPage * page = [[pdf pageAtIndex:i] copy];
|
|
|
-// [self.pdfView.document insertPage:page atIndex:index];
|
|
|
-// [insertIndexSet addIndex:index];
|
|
|
-// index++;
|
|
|
-// [page release];
|
|
|
-// }
|
|
|
-// [self insertPages:insertIndexSet pageAtIndex:(index-1)];
|
|
|
-//
|
|
|
-// }
|
|
|
-// } else if ([[KMImageToPDFMethod supportedImageTypes] containsObject:pathExtension]) {
|
|
|
-// NSImage *image = [[[NSImage alloc] initWithContentsOfFile:path] autorelease];
|
|
|
+ KMBaseWindowController.checkPassword(url: url!) { success, resultPassword in
|
|
|
+ if success && resultPassword.isEmpty == false {
|
|
|
+ pdf?.unlock(withPassword: resultPassword)
|
|
|
+ for i in 0 ..< (pdf?.pageCount ?? 0) {
|
|
|
+// let page = pdf?.page(at: i).copy() as? CPDFPage
|
|
|
+ let page = pdf?.page(at: i)
|
|
|
+ self.listView.document.insertPageObject(page!, at: UInt(index))
|
|
|
+ insertIndexSet.insert(index)
|
|
|
+ index += 1
|
|
|
+ }
|
|
|
+ self.insertPages(insertIndexSet, pageAt: index-1)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for i in 0 ..< (pdf?.pageCount ?? 0) {
|
|
|
+// let page = pdf?.page(at: i).copy() as? CPDFPage
|
|
|
+ let page = pdf?.page(at: i)
|
|
|
+ self.listView.document.insertPageObject(page!, at: UInt(index))
|
|
|
+ insertIndexSet.insert(index)
|
|
|
+ index += 1
|
|
|
+ }
|
|
|
+ self.insertPages(insertIndexSet, pageAt: index-1)
|
|
|
+ }
|
|
|
+ } else if KMImageToPDFMethod.supportedImageTypes().contains(pathExtension) {
|
|
|
+ let image = NSImage(contentsOfFile: url?.path ?? "")
|
|
|
// PDFPage * page = [[[PDFPage alloc] initWithImage:image] autorelease];
|
|
|
// [pdfView.document insertPage:page atIndex:index];
|
|
|
-// [insertIndexSet addIndex:index];
|
|
|
-// [self insertPages:insertIndexSet pageAtIndex:(index-1)];
|
|
|
-// }
|
|
|
-// result = YES;
|
|
|
-// } else {
|
|
|
-// result = NO;
|
|
|
-// }
|
|
|
-// }
|
|
|
+ _ = self.listView.document.km_insert(image: image!, at: UInt(index))
|
|
|
+ insertIndexSet.insert(index)
|
|
|
+ self.insertPages(insertIndexSet, pageAt: index-1)
|
|
|
+ }
|
|
|
+ result = true
|
|
|
+ } else {
|
|
|
+ result = false
|
|
|
+ }
|
|
|
+ }
|
|
|
return result == false
|
|
|
}
|
|
|
|