|
@@ -241,7 +241,7 @@ class KMLeftSideViewController: KMSideViewController {
|
|
|
}
|
|
|
|
|
|
private let kKMPDFViewOutlineDragDataType = "kKMPDFViewOutlineDragDataType"
|
|
|
- private let KPDFThumbnailDoucumentURLForDraggedTypes = "KPDFThumbnailDoucumentURLForDraggedTypes"
|
|
|
+ private let KPDFThumbnailDoucumentURLForDraggedTypes = NSPasteboard.PasteboardType("KPDFThumbnailDoucumentURLForDraggedTypes")
|
|
|
|
|
|
var renamePDFOutline: CPDFOutline?
|
|
|
var renamePDFOutlineTextField: NSTextField?
|
|
@@ -2702,9 +2702,6 @@ extension KMLeftSideViewController: NSTableViewDelegate, NSTableViewDataSource {
|
|
|
guard let pbItems = pboard.pasteboardItems else {
|
|
|
return NSDragOperation(rawValue: 0)
|
|
|
}
|
|
|
-// guard let _allowedFileTypes = self.kmAllowedFileTypes else {
|
|
|
-// return .generic
|
|
|
-// }
|
|
|
|
|
|
var hasValidFile = false
|
|
|
for item in pbItems {
|
|
@@ -2712,10 +2709,7 @@ extension KMLeftSideViewController: NSTableViewDelegate, NSTableViewDataSource {
|
|
|
continue
|
|
|
}
|
|
|
let type = _url.pathExtension.lowercased()
|
|
|
-// if (_allowedFileTypes.contains(type)) {
|
|
|
hasValidFile = true
|
|
|
-// break
|
|
|
-// }
|
|
|
}
|
|
|
|
|
|
if (!hasValidFile) {
|
|
@@ -2730,103 +2724,105 @@ extension KMLeftSideViewController: NSTableViewDelegate, NSTableViewDataSource {
|
|
|
if tableView.isEqual(to: self.thumbnailTableView) == false {
|
|
|
return result
|
|
|
}
|
|
|
-
|
|
|
-// let pasteboard = info.draggingPasteboard
|
|
|
-//
|
|
|
-// if pasteboard.availableType(from: [.localDraggedTypes]) {
|
|
|
-// result = true
|
|
|
-// let rowData = pasteboard.data(forType: .localDraggedTypes)
|
|
|
-// let rowIndexes = NSKeyedUnarchiver.unarchiveObject(with: rowData!)
|
|
|
-// NSData *urlData = [pasteboard dataForType:KPDFThumbnailDoucumentURLForDraggedTypes];
|
|
|
-// NSString *url = [NSKeyedUnarchiver unarchiveObjectWithData:urlData];
|
|
|
-// if(![url isEqualToString:[pdfView document].documentURL.absoluteString] && url) {
|
|
|
-// if ([pasteboard availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]]){
|
|
|
-// NSArray *fileNames = [pasteboard propertyListForType:NSFilenamesPboardType];
|
|
|
-// if (fileNames.count == 1) {
|
|
|
-// NSString *path = fileNames.firstObject;
|
|
|
-// NSString *pathExtension = [path.pathExtension lowercaseString];
|
|
|
-// if ([pathExtension isEqualToString:@"pdf"]) {
|
|
|
-// __block NSInteger index = row;
|
|
|
-// __block NSMutableIndexSet *insertIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
|
|
|
-// PDFDocument *pdf = [[[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:path]] autorelease];
|
|
|
-// 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];
|
|
|
-// } 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)];
|
|
|
-// }
|
|
|
-// return YES;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// __block NSInteger pageIndex = 0;
|
|
|
-// __block NSMutableArray *pages = [NSMutableArray array];
|
|
|
-// [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
-// PDFPage *page = [[[pdfView document] pageAtIndex:idx] copy];
|
|
|
-// [pages addObject:page];
|
|
|
-// [page release];
|
|
|
-// }];
|
|
|
-// PDFPage *toPage = nil;
|
|
|
-// if (row < (NSInteger)pdfView.document.pageCount) {
|
|
|
-// toPage = [pdfView.document pageAtIndex:row];
|
|
|
-// }
|
|
|
-// __block NSInteger toPageIndex = 0;
|
|
|
-// if (toPage) {
|
|
|
-// toPageIndex = [pdfView.document indexForPage:toPage];
|
|
|
-// } else {
|
|
|
-// toPageIndex = pdfView.document.pageCount;
|
|
|
-// }
|
|
|
-// for(NSUInteger i = 0;i<pages.count;i++) {
|
|
|
-// PDFPage *page = pages[i];
|
|
|
-// [pdfView.document insertPage:page atIndex:toPageIndex+i];
|
|
|
-// pageIndex += 1;
|
|
|
-// [self.pdfView goToPage:page];
|
|
|
-// }
|
|
|
-// [self.pdfView layoutDocumentView];
|
|
|
-// __block NSMutableArray *deletepages = [NSMutableArray array];
|
|
|
-// [rowIndexes enumerateIndexesWithOptions:NSEnumerationReverse usingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
-// if((NSInteger)idx < toPageIndex) {
|
|
|
-// if((idx+pageIndex) < pdfView.document.pageCount) {
|
|
|
-// PDFPage *page = [[pdfView document] pageAtIndex:idx];
|
|
|
-// [deletepages addObject:page];
|
|
|
-// [pdfView.document removePageAtIndex:idx];
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// if((idx+pageIndex) < pdfView.document.pageCount) {
|
|
|
-// PDFPage *page = [[pdfView document] pageAtIndex:idx+pageIndex];
|
|
|
-// [deletepages addObject:page];
|
|
|
-// [pdfView.document removePageAtIndex:idx+pageIndex];
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }];
|
|
|
-// [[[[self document] undoManager] prepareWithInvocationTarget:self] undoClick];
|
|
|
-// [self.pageLabels setArray:[[self.pdfView document] pageLabels]];
|
|
|
-// [self.pdfView layoutDocumentView];
|
|
|
-// [self resetThumbnails];
|
|
|
-//
|
|
|
-// } else if ([pasteboard availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]] && [tableView isEqual:leftSideController.thumbnailTableView]) {
|
|
|
+
|
|
|
+ let pasteboard = info.draggingPasteboard
|
|
|
+ if (pasteboard.availableType(from: [.localDraggedTypes]) != nil) {
|
|
|
+ result = true
|
|
|
+ let rowData = pasteboard.data(forType: .localDraggedTypes)
|
|
|
+ let rowIndexes = NSKeyedUnarchiver.unarchiveObject(with: rowData!) as? IndexSet ?? IndexSet()
|
|
|
+ let urlData = pasteboard.data(forType: KPDFThumbnailDoucumentURLForDraggedTypes)
|
|
|
+ let url = NSKeyedUnarchiver.unarchiveObject(with: urlData!) as? String
|
|
|
+ if url != nil && url != self.listView.document.documentURL.absoluteString {
|
|
|
+ if (pasteboard.availableType(from: [.fileURL]) != nil) {
|
|
|
+ // if ([pasteboard availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]]){
|
|
|
+ // NSArray *fileNames = [pasteboard propertyListForType:NSFilenamesPboardType];
|
|
|
+ var fileNames = pasteboard.propertyList(forType: .fileURL) as? [String] ?? []
|
|
|
+ if (fileNames.count == 1) {
|
|
|
+ let path = fileNames.first ?? ""
|
|
|
+ let pathExtension = path.pathExtension.lowercased()
|
|
|
+ if pathExtension == "pdf" {
|
|
|
+ var index = row
|
|
|
+ // __block NSMutableIndexSet *insertIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
|
|
|
+ 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];
|
|
|
+ } else {
|
|
|
+ for i in 0 ..< (pdf?.pageCount ?? 0) {
|
|
|
+ // PDFPage *page = [[pdf pageAtIndex:i] copy];
|
|
|
+ var page = pdf?.page(at: i)
|
|
|
+ self.listView.document.insertPageObject(page, at: UInt(index))
|
|
|
+ insertIndexSet.insert(index)
|
|
|
+ index += 1
|
|
|
+ }
|
|
|
+ self.insertPages(insertIndexSet, pageAt: index-1)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var pageIndex = 0
|
|
|
+ var pages: [CPDFPage] = []
|
|
|
+ for idx in rowIndexes {
|
|
|
+ let page = self.listView.document.page(at: UInt(idx))?.copy() as? CPDFPage
|
|
|
+ pages.append(page!)
|
|
|
+ }
|
|
|
+ var toPage: CPDFPage?
|
|
|
+ if row < self.listView.document.pageCount {
|
|
|
+ toPage = self.listView.document.page(at: UInt(row))
|
|
|
+ }
|
|
|
+ var toPageIndex = 0
|
|
|
+ if (toPage != nil) {
|
|
|
+ toPageIndex = Int(self.listView.document.index(for: toPage))
|
|
|
+ } else {
|
|
|
+ toPageIndex = Int(self.listView.document.pageCount)
|
|
|
+ }
|
|
|
+ for i in 0 ..< pages.count {
|
|
|
+ var page = pages[i]
|
|
|
+ self.listView.document.insertPageObject(page, at: UInt(toPageIndex+i))
|
|
|
+ pageIndex += 1
|
|
|
+ self.listView.go(toPageIndex: toPageIndex+i, animated: false)
|
|
|
+ }
|
|
|
+ self.listView.layoutDocumentView()
|
|
|
+ var deletepages: [CPDFPage] = []
|
|
|
+ for idx in rowIndexes {
|
|
|
+ if idx < toPageIndex {
|
|
|
+ if((idx+pageIndex) < self.listView.document.pageCount) {
|
|
|
+ var page = self.listView.document.page(at: UInt(idx))
|
|
|
+ deletepages.append(page!)
|
|
|
+ self.listView.document.removePage(at: IndexSet(integer: idx))
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if((idx+pageIndex) < self.listView.document.pageCount) {
|
|
|
+ let page = self.listView.document.page(at: UInt(idx+pageIndex))
|
|
|
+ deletepages.append(page!)
|
|
|
+ self.listView.document.removePage(at: IndexSet(integer: idx+pageIndex))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // [[[[self document] undoManager] prepareWithInvocationTarget:self] undoClick];
|
|
|
+ // [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];
|
|
|
//
|
|
@@ -2887,67 +2883,74 @@ extension KMLeftSideViewController: NSTableViewDelegate, NSTableViewDataSource {
|
|
|
|
|
|
func tableView(_ tableView: NSTableView, writeRowsWith rowIndexes: IndexSet, to pboard: NSPasteboard) -> Bool {
|
|
|
if tableView.isEqual(to: self.thumbnailTableView) {
|
|
|
-// let idx = rowIndexes.first
|
|
|
-// if (idx != NSNotFound && [[pdfView document] isLocked] == NO) {
|
|
|
-// PDFPage *page = [[pdfView document] pageAtIndex:idx];
|
|
|
-// NSString *fileExt = nil;
|
|
|
-// NSData *tiffData = [page TIFFDataForRect:[page boundsForBox:[pdfView displayBox]]];
|
|
|
-//
|
|
|
-// if ([[pdfView document] allowsPrinting]) {
|
|
|
+ let idx = rowIndexes.first ?? NSNotFound
|
|
|
+ if (idx != NSNotFound && self.listView.document.isLocked == false) {
|
|
|
+ let page = self.listView.document.page(at: UInt(idx))
|
|
|
+ var fileExt: String?
|
|
|
+ let tiffData = page?.PDFListViewTIFFData(for: page?.bounds(for: self.listView.displayBox) ?? .zero)
|
|
|
+ if self.listView.document.allowsPrinting {
|
|
|
// NSData *pdfData = [page dataRepresentation];
|
|
|
-// fileExt = @"pdf";
|
|
|
-// [pboard declareTypes:[NSArray arrayWithObjects:NSPasteboardTypePDF, NSPasteboardTypeTIFF,NSFilenamesPboardType, NSFilesPromisePboardType, KPDFThumbnailLocalForDraggedTypes,KPDFThumbnailDoucumentURLForDraggedTypes,nil] owner:self];
|
|
|
+ fileExt = "pdf"
|
|
|
+ // filenames
|
|
|
+ pboard.declareTypes([.pdf, .tiff, .fileURL, .filePromise, .localDraggedTypes, KPDFThumbnailDoucumentURLForDraggedTypes], owner: self)
|
|
|
+// let newDoc = CPDFDocument()
|
|
|
+// newDoc?.insertPageObject(page, at: 0)
|
|
|
+// let data = newDoc?.dataRepresentation()
|
|
|
|
|
|
// [pboard setData:pdfData forType:NSPasteboardTypePDF];
|
|
|
+ pboard.setData(tiffData, forType: .pdf)
|
|
|
|
|
|
// NSData *zNSIndexSetData = [NSKeyedArchiver archivedDataWithRootObject:rowIndexes];
|
|
|
+ let zNSIndexSetData = NSKeyedArchiver.archivedData(withRootObject: rowIndexes)
|
|
|
+ pboard.setData(zNSIndexSetData, forType: .localDraggedTypes)
|
|
|
|
|
|
-// [pboard setData:zNSIndexSetData forType:KPDFThumbnailLocalForDraggedTypes];
|
|
|
-
|
|
|
-// NSData *documentURL = [NSKeyedArchiver archivedDataWithRootObject:[[pdfView document].documentURL absoluteString]];
|
|
|
+ let documentURL = NSKeyedArchiver.archivedData(withRootObject: self.listView.document.documentURL?.absoluteString)
|
|
|
// NSString *docmentName = [[[pdfView.document.documentURL path] lastPathComponent] stringByDeletingPathExtension];
|
|
|
+ var docmentName = self.listView.document.documentURL.deletingPathExtension().lastPathComponent
|
|
|
// __block NSMutableString *pagesName = nil;
|
|
|
-// if (rowIndexes.count > 1) {
|
|
|
-// pagesName = [NSMutableString stringWithString:@" pages"];
|
|
|
-//
|
|
|
-// } else {
|
|
|
-// pagesName = [NSMutableString stringWithString:@" page"];
|
|
|
-//
|
|
|
-// }
|
|
|
-// NSString * tFileName = [NSString stringWithFormat:@"%@ %@",pagesName,[self fileNameWithSelectedPages:rowIndexes]];
|
|
|
-// PDFDocument * pdf = [[[PDFDocument alloc] init] autorelease];
|
|
|
-// [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
-// PDFPage *copyPage = [[pdfView.document pageAtIndex:idx] copy];
|
|
|
-// [pdf insertPage:copyPage atIndex:pdf.pageCount];
|
|
|
-// [copyPage release];
|
|
|
-// }];
|
|
|
-// NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
|
|
-// NSString *cachesDir = [paths objectAtIndex:0];
|
|
|
+ var pagesName = ""
|
|
|
+ if (rowIndexes.count > 1) {
|
|
|
+ pagesName = " pages"
|
|
|
+ } else {
|
|
|
+ pagesName = " page"
|
|
|
+ }
|
|
|
+ let tFileName = String(format: "%@ %@", pagesName, self.fileNameWithSelectedPages(rowIndexes))
|
|
|
+ let pdf = CPDFDocument()
|
|
|
+ for idx in rowIndexes {
|
|
|
+// var copyPage = self.listView.document.page(at: UInt(idx)).copy() as? CPDFPage
|
|
|
+ var copyPage = self.listView.document.page(at: UInt(idx))
|
|
|
+ pdf?.insertPageObject(copyPage, at: pdf?.pageCount ?? 0)
|
|
|
+ }
|
|
|
+ let paths = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)
|
|
|
+ var cachesDir = paths.first ?? ""
|
|
|
// docmentName = [NSString stringWithFormat:@"%@%@",docmentName,tFileName];
|
|
|
-// if (docmentName.length > 50) {
|
|
|
-// [docmentName substringWithRange:NSMakeRange(0, 50)];
|
|
|
-// }
|
|
|
+ docmentName = String(format: "%@%@", docmentName, tFileName)
|
|
|
+ if (docmentName.count > 50) {
|
|
|
+ docmentName = docmentName.substring(to: 50)
|
|
|
+ }
|
|
|
// cachesDir = [[cachesDir stringByAppendingPathComponent:docmentName] stringByAppendingPathExtension:@"pdf"];
|
|
|
-//
|
|
|
-// BOOL success = [pdf writeToFile:cachesDir];
|
|
|
-// if (success) {
|
|
|
+ cachesDir = "\(cachesDir)/\(docmentName).pdf"
|
|
|
+ let success = pdf?.write(toFile: cachesDir) ?? false
|
|
|
+ if (success) {
|
|
|
// [pboard setPropertyList:@[cachesDir] forType:NSFilenamesPboardType];
|
|
|
-// }else{
|
|
|
+ pboard.setPropertyList([cachesDir], forType: .fileURL)
|
|
|
+ } else{
|
|
|
// [pboard setPropertyList:@[@""] forType:NSFilenamesPboardType];
|
|
|
-// }
|
|
|
-// [pboard setData:documentURL forType:KPDFThumbnailDoucumentURLForDraggedTypes];
|
|
|
-// } else {
|
|
|
-// fileExt = @"tiff";
|
|
|
-// [pboard declareTypes:[NSArray arrayWithObjects:NSPasteboardTypeTIFF, NSFilesPromisePboardType, nil] owner:self];
|
|
|
-// }
|
|
|
-// [pboard setData:tiffData forType:NSPasteboardTypeTIFF];
|
|
|
-// [pboard setPropertyList:[NSArray arrayWithObject:fileExt] forType:NSFilesPromisePboardType];
|
|
|
+ pboard.setPropertyList([], forType: .fileURL)
|
|
|
+ }
|
|
|
+ pboard.setData(documentURL, forType: KPDFThumbnailDoucumentURLForDraggedTypes)
|
|
|
+ } else {
|
|
|
+ fileExt = "tiff"
|
|
|
+ pboard.declareTypes([.tiff, .filePromise], owner: self)
|
|
|
+ }
|
|
|
+ pboard.setData(tiffData, forType: .tiff)
|
|
|
+ pboard.setPropertyList([fileExt], forType: .filePromise)
|
|
|
|
|
|
- let data: Data = try! NSKeyedArchiver.archivedData(withRootObject: rowIndexes, requiringSecureCoding: true)
|
|
|
- pboard.declareTypes([.localDraggedTypes], owner: self)
|
|
|
- pboard.setData(data, forType: .localDraggedTypes)
|
|
|
+// let data: Data = try! NSKeyedArchiver.archivedData(withRootObject: rowIndexes, requiringSecureCoding: true)
|
|
|
+// pboard.declareTypes([.localDraggedTypes], owner: self)
|
|
|
+// pboard.setData(data, forType: .localDraggedTypes)
|
|
|
return true
|
|
|
-// }
|
|
|
+ }
|
|
|
}
|
|
|
// else if ([tv isEqual:rightSideController.snapshotTableView]) {
|
|
|
// NSUInteger idx = [rowIndexes firstIndex];
|