Browse Source

【BOTA】快照列表细节补充

tangchao 1 year ago
parent
commit
e516fafb37

+ 17 - 0
PDF Office/PDF Master/Class/Common/Category/NSObject+KMExtension.swift

@@ -744,6 +744,23 @@ extension Array where Element: Equatable {
     }
 }
 
+// MARK: - URL
+
+extension URL {
+    func uniqueFileURL() -> URL {
+        var uniqueFileURL = self
+        let baseURL = self.deletingLastPathComponent()
+        let baseName = self.deletingPathExtension().lastPathComponent
+        let `extension` = self.pathExtension
+        var i = 0
+        while let result = try?uniqueFileURL.checkResourceIsReachable(), result {
+            i += 1
+            uniqueFileURL = baseURL.appendingPathComponent("\(baseName)-\(i)").appendingPathExtension(`extension`)
+        }
+        return uniqueFileURL
+    }
+}
+
 // MARK: - Other
 
 func KMSquaredDistanceFromPointToRect(_ point: NSPoint, _ rect: NSRect) -> CGFloat {

+ 0 - 18
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMBotaTableView.swift

@@ -7,16 +7,6 @@
 
 import Cocoa
 
-/*
- @protocol SKTableViewDelegate <NSTableViewDelegate>
-
- - (NSArray *)tableView:(NSTableView *)aTableView typeSelectHelperSelectionStrings:(SKTypeSelectHelper *)aTypeSelectHelper;
- - (void)tableView:(NSTableView *)aTableView typeSelectHelper:(SKTypeSelectHelper *)aTypeSelectHelper didFailToFindMatchForSearchString:(NSString *)searchString;
- - (void)tableView:(NSTableView *)aTableView typeSelectHelper:(SKTypeSelectHelper *)aTypeSelectHelper updateSearchString:(NSString *)searchString;
-
- @end
- */
-
 @objc protocol KMBotaTableViewDelegate: NSTableViewDelegate {
     @objc optional func tableView(_ aTableView: NSTableView, deleteRowsWithIndexes rowIndexes: IndexSet)
     @objc optional func tableView(_ aTableView: NSTableView, canDeleteRowsWithIndexes rowIndexes: IndexSet) -> Bool
@@ -327,8 +317,6 @@ class KMBotaTableView: NSTableView, SKTypeSelectHelperDelegate {
      }
 
      */
-    
-    
 }
 
 // MARK: - Private Methods
@@ -375,11 +363,6 @@ extension KMBotaTableView {
         self.addTrackingArea(area)
         self.kmTrackingAreas?.add(area)
     }
-    
-    /*
-
-     */
-    
 }
 
 extension KMBotaTableView: NSMenuItemValidation {
@@ -395,7 +378,6 @@ extension KMBotaTableView: NSMenuItemValidation {
         } else if menuItem.action == #selector(deselectAll) {
             return self.allowsEmptySelection
         }
-
 //        else if ([[SKTableView superclass] instancesRespondToSelector:@selector(validateMenuItem:)])
 //            return [super validateMenuItem:menuItem];
         

+ 88 - 83
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController.swift

@@ -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

+ 0 - 16
PDF Office/PDF Reader Pro.xcodeproj/xcuserdata/kdanmobile.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -132,22 +132,6 @@
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
-            uuid = "AC9C2D2A-656C-4707-BB81-827617A9F1B4"
-            shouldBeEnabled = "Yes"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "PDF Master/Class/PDFWindowController/PDFListView/CPDFListViewExtension/CPDFListView+Event.m"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "43"
-            endingLineNumber = "43"
-            landmarkName = "-mouseDown:"
-            landmarkType = "7">
-         </BreakpointContent>
-      </BreakpointProxy>
       <BreakpointProxy
          BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
          <BreakpointContent