|
@@ -2674,25 +2674,18 @@ extension KMLeftSideViewController: NSTableViewDelegate, NSTableViewDataSource {
|
|
|
view2?.isSelectCell = true
|
|
|
|
|
|
self.preThumbnailRow = row
|
|
|
- }
|
|
|
-// else if ([[aNotification object] isEqual:rightSideController.snapshotTableView]) {
|
|
|
-// NSInteger row = [rightSideController.snapshotTableView selectedRow];
|
|
|
+ } else if self.snapshotTableView.isEqual(to: notification.object) {
|
|
|
+ let row = self.snapshotTableView.selectedRow
|
|
|
// [selectCellList removeAllObjects];
|
|
|
// [selectCellList addObject:[NSString stringWithFormat:@"%ld",row]];
|
|
|
-// if (row != -1) {
|
|
|
-// SKSnapshotWindowController *controller = [[rightSideController.snapshotArrayController arrangedObjects] objectAtIndex:row];
|
|
|
-// if ([[controller window] isVisible])
|
|
|
-// [[controller window] orderFront:self];
|
|
|
-// }
|
|
|
-// NSMutableIndexSet *rowIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
|
|
|
-// for (NSInteger i = 0; i < rightSideController.snapshotTableView.numberOfRows; i ++) {
|
|
|
-// [rowIndexSet addIndex:i];
|
|
|
-// }
|
|
|
-// NSMutableIndexSet *columnIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
|
|
|
-// [columnIndexSet addIndex:0];
|
|
|
-// [rightSideController.snapshotTableView reloadDataForRowIndexes:rowIndexSet columnIndexes:columnIndexSet];
|
|
|
-//
|
|
|
-// }
|
|
|
+ if (row != -1) {
|
|
|
+ let controller = (self.snapshots.safe_element(for: row) as? KMSnapshotModel)?.windowC
|
|
|
+ if let data = controller?.window?.isVisible, data {
|
|
|
+ controller?.window?.orderFront(self)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self.snapshotTableView.reloadData()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
func tableView(_ tableView: NSTableView, validateDrop info: NSDraggingInfo, proposedRow row: Int, proposedDropOperation dropOperation: NSTableView.DropOperation) -> NSDragOperation {
|
|
@@ -2947,17 +2940,18 @@ extension KMLeftSideViewController: NSTableViewDelegate, NSTableViewDataSource {
|
|
|
|
|
|
return true
|
|
|
}
|
|
|
+ } else if self.snapshotTableView.isEqual(to: tableView) {
|
|
|
+ let idx = rowIndexes.first ?? NSNotFound
|
|
|
+ if (idx != NSNotFound) {
|
|
|
+ let snapshot = (self.snapshots.safe_element(for: idx) as? KMSnapshotModel)?.windowC
|
|
|
+ if let data = snapshot?.thumbnailWithSize(0)?.tiffRepresentation {
|
|
|
+ pboard.declareTypes([.tiff, .filePromise], owner: self)
|
|
|
+ pboard.setData(data, forType: .tiff)
|
|
|
+ pboard.setPropertyList(["tiff"], forType: .filePromise)
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
-// else if ([tv isEqual:rightSideController.snapshotTableView]) {
|
|
|
-// NSUInteger idx = [rowIndexes firstIndex];
|
|
|
-// if (idx != NSNotFound) {
|
|
|
-// SKSnapshotWindowController *snapshot = [self objectInSnapshotsAtIndex:idx];
|
|
|
-// [pboard declareTypes:[NSArray arrayWithObjects:NSPasteboardTypeTIFF, NSFilesPromisePboardType, nil] owner:self];
|
|
|
-// [pboard setData:[[snapshot thumbnailWithSize:0.0] TIFFRepresentation] forType:NSPasteboardTypeTIFF];
|
|
|
-// [pboard setPropertyList:[NSArray arrayWithObject:@"tiff"] forType:NSFilesPromisePboardType];
|
|
|
-// return YES;
|
|
|
-// }
|
|
|
-// }
|
|
|
return false
|
|
|
}
|
|
|
|
|
@@ -3050,72 +3044,74 @@ extension KMLeftSideViewController: NSTableViewDelegate, NSTableViewDataSource {
|
|
|
// }
|
|
|
}
|
|
|
|
|
|
+ func tableView(_ tableView: NSTableView, namesOfPromisedFilesDroppedAtDestination dropDestination: URL, forDraggedRowsWith indexSet: IndexSet) -> [String] {
|
|
|
+ if self.thumbnailTableView.isEqual(to: tableView) {
|
|
|
+ var fileURLArray: [String] = []
|
|
|
+ if indexSet.count > 1 {
|
|
|
+ var docmentName = ""
|
|
|
+ var tFileName = String(format: "%@", self.fileNameWithSelectedPages(indexSet))
|
|
|
+ var pdf = CPDFDocument()
|
|
|
+ for idx in indexSet {
|
|
|
+ if idx != NSNotFound && self.listView.document.isLocked == false {
|
|
|
+ let copyPage = self.listView.document.page(at: UInt(idx)).copy() as? CPDFPage
|
|
|
+ pdf?.insertPageObject(copyPage, at: pdf?.pageCount ?? 0)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var fileURL = dropDestination.appendingPathComponent(tFileName).appendingPathExtension("pdf").uniqueFileURL()
|
|
|
+ docmentName = fileURL.path
|
|
|
+ let success = pdf?.write(toFile: docmentName) ?? false
|
|
|
+ if(success) {
|
|
|
+ fileURLArray.append(fileURL.lastPathComponent)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if let page = self.listView.document.page(at: UInt(indexSet.first ?? 0)) {
|
|
|
+ var fileURL = dropDestination.appendingPathComponent(self.draggedFileName(for: page))
|
|
|
+ var pathExt = ""
|
|
|
+ var fileData: Data?
|
|
|
+
|
|
|
+ if let data = self.listView?.document?.allowsPrinting, data {
|
|
|
+ pathExt = "pdf"
|
|
|
+ // data = [page dataRepresentation];
|
|
|
+ } else {
|
|
|
+ pathExt = "tiff"
|
|
|
+ fileData = page.PDFListViewTIFFData(for: page.bounds(for: self.listView?.displayBox ?? .cropBox))
|
|
|
+ }
|
|
|
+
|
|
|
+ fileURL = fileURL.appendingPathExtension(pathExt).uniqueFileURL()
|
|
|
+ let success = try?fileData?.write(to: fileURL)
|
|
|
+ if success != nil {
|
|
|
+ fileURLArray.append(fileURL.lastPathComponent)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return fileURLArray
|
|
|
+ } else if self.snapshotTableView.isEqual(to: tableView) {
|
|
|
+ let idx = indexSet.first ?? NSNotFound
|
|
|
+ if (idx != NSNotFound) {
|
|
|
+ if let snapshot = (self.snapshots.safe_element(for: idx) as? KMSnapshotModel)?.windowC {
|
|
|
+ if let page = self.listView?.document?.page(at: snapshot.pageIndex()) {
|
|
|
+ var fileURL = dropDestination.appendingPathComponent(self.draggedFileName(for: page)).appendingPathExtension("tiff")
|
|
|
+ fileURL = fileURL.uniqueFileURL()
|
|
|
+ if ((try?snapshot.thumbnailWithSize(0)?.tiffRepresentation?.write(to: fileURL)) != nil) {
|
|
|
+ return [fileURL.lastPathComponent]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return[]
|
|
|
+ }
|
|
|
+
|
|
|
/*
|
|
|
|
|
|
#pragma mark dragging
|
|
|
|
|
|
- - (NSArray *)tableView:(NSTableView *)tv namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes {
|
|
|
- if ([tv isEqual:leftSideController.thumbnailTableView]) {
|
|
|
- __block NSMutableArray *fileURLArray = [NSMutableArray array];
|
|
|
- if (rowIndexes.count > 1) {
|
|
|
- NSString *docmentName = @"";
|
|
|
- NSString * tFileName = [NSString stringWithFormat:@"%@",[self fileNameWithSelectedPages:rowIndexes]];
|
|
|
- PDFDocument *pdf = [[[PDFDocument alloc] init] autorelease];
|
|
|
- [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
- if (idx != NSNotFound && [[pdfView document] isLocked] == NO) {
|
|
|
- PDFPage *copyPage = [[[pdfView document] pageAtIndex:idx] copy];
|
|
|
- [pdf insertPage:copyPage atIndex:pdf.pageCount];
|
|
|
- [copyPage release];
|
|
|
- }
|
|
|
- }];
|
|
|
- NSURL *fileURL = [[[dropDestination URLByAppendingPathComponent:tFileName] URLByAppendingPathExtension:@"pdf"] uniqueFileURL];
|
|
|
- docmentName = fileURL.path;
|
|
|
- BOOL success = [pdf writeToFile:docmentName];
|
|
|
- if(success) {
|
|
|
- [fileURLArray addObject:[fileURL lastPathComponent]];
|
|
|
- }
|
|
|
- } else {
|
|
|
- PDFPage *page = [[pdfView document] pageAtIndex:rowIndexes.firstIndex];
|
|
|
- NSURL *fileURL = [dropDestination URLByAppendingPathComponent:[self draggedFileNameForPage:page]];
|
|
|
- NSString *pathExt = nil;
|
|
|
- NSData *data = nil;
|
|
|
-
|
|
|
- if ([[pdfView document] allowsPrinting]) {
|
|
|
- pathExt = @"pdf";
|
|
|
- data = [page dataRepresentation];
|
|
|
- } else {
|
|
|
- pathExt = @"tiff";
|
|
|
- data = [page TIFFDataForRect:[page boundsForBox:[pdfView displayBox]]];
|
|
|
- }
|
|
|
-
|
|
|
- fileURL = [[fileURL URLByAppendingPathExtension:pathExt] uniqueFileURL];
|
|
|
- if ([data writeToURL:fileURL atomically:YES]) {
|
|
|
- [fileURLArray addObject:[fileURL lastPathComponent]];
|
|
|
- }
|
|
|
- }
|
|
|
- return fileURLArray;
|
|
|
- } else if ([tv isEqual:rightSideController.snapshotTableView]) {
|
|
|
- NSUInteger idx = [rowIndexes firstIndex];
|
|
|
- if (idx != NSNotFound) {
|
|
|
- SKSnapshotWindowController *snapshot = [self objectInSnapshotsAtIndex:idx];
|
|
|
- PDFPage *page = [[pdfView document] pageAtIndex:[snapshot pageIndex]];
|
|
|
- NSURL *fileURL = [[dropDestination URLByAppendingPathComponent:[self draggedFileNameForPage:page]] URLByAppendingPathExtension:@"tiff"];
|
|
|
- fileURL = [fileURL uniqueFileURL];
|
|
|
- if ([[[snapshot thumbnailWithSize:0.0] TIFFRepresentation] writeToURL:fileURL atomically:YES])
|
|
|
- return [NSArray arrayWithObjects:[fileURL lastPathComponent], nil];
|
|
|
- }
|
|
|
- }
|
|
|
- return [NSArray array];
|
|
|
- }
|
|
|
-
|
|
|
- (void)tableView:(NSTableView *)tv sortDescriptorsDidChange:(NSArray *)oldDescriptors {
|
|
|
if ([tv isEqual:leftSideController.groupedFindTableView]) {
|
|
|
[leftSideController.groupedFindArrayController setSortDescriptors:[tv sortDescriptors]];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
#pragma mark NSTableView delegate protocol
|
|
|
- (void)tableViewColumnDidResize:(NSNotification *)aNotification {
|
|
|
if ([[[[aNotification userInfo] objectForKey:@"NSTableColumn"] identifier] isEqualToString:IMAGE_COLUMNID]) {
|
|
@@ -5330,6 +5326,15 @@ extension KMLeftSideViewController {
|
|
|
return ""
|
|
|
}
|
|
|
|
|
|
+ func draggedFileName(for page: CPDFPage) -> String {
|
|
|
+ let pageIndex = "\(page.pageIndex() + 1)"
|
|
|
+ var fileName = ""
|
|
|
+ if let doc = self.view.window?.windowController?.document as? NSDocument {
|
|
|
+ fileName = doc.displayName.deletingPathExtension
|
|
|
+ }
|
|
|
+ return "\(fileName)-Page \(pageIndex)"
|
|
|
+ }
|
|
|
+
|
|
|
func switchType(_ type: BotaType) {
|
|
|
if type == .Thumbnail {
|
|
|
self.leftView.segmentedControl.selectedSegment = 0
|