Browse Source

【综合】BOTA 缩略图列表,未支持直接拖拽页面到桌面上提取文件(已修复)

tangchao 11 months ago
parent
commit
ff7771ce6c

+ 52 - 0
PDF Office/PDF Master/Class/Common/Tools/KMTools.swift

@@ -259,6 +259,58 @@ import Cocoa
             document.updateChangeCount(.changeCleared)
         }
     }
+    
+    // MARK: - 解析 [1-3,5-7]
+    
+    @objc class func parseIndexSet(indexSet: IndexSet) -> String {
+        return self.parseIndexs(indexs: indexSet.sorted())
+    }
+    
+    @objc class func parseIndexs(indexs: [Int]) -> String {
+        if (indexs.isEmpty) {
+            return ""
+        }
+        if (indexs.count == 1) {
+            return "\(indexs.first!+1)"
+        }
+        
+        var sortArray: [Int] = []
+        for i in indexs {
+            sortArray.append(i)
+        }
+        /// 排序 (升序)
+        sortArray.sort(){$0 < $1}
+        
+        var a: Int = 0
+        var b: Int = 0
+        var result: String?
+        for i in sortArray {
+            if (result == nil) {
+                a = i
+                b = i
+                result = ""
+                continue
+            }
+            if (i == b+1) {
+                b = i
+                if (i == sortArray.last) {
+                    result?.append(String(format: "%d-%d", a+1,b+1))
+                }
+            } else {
+                if (a == b) {
+                    result?.append(String(format: "%d,", a+1))
+                } else {
+                    result?.append(String(format: "%d-%d,", a+1,b+1))
+                }
+                a = i
+                b = i
+                if (i == sortArray.last) {
+                    result?.append(String(format: "%d", a+1))
+                }
+            }
+        }
+        return result ?? ""
+    }
 }
 
 // MARK: - PDFReaderPro

+ 0 - 124
PDF Office/PDF Master/Class/PDFTools/Watermark/Tools/KMPageRangeTools.swift

@@ -8,7 +8,6 @@
 import Cocoa
 
 class KMPageRangeTools: NSObject {
-    
     class func isValidPagesString(pagesString: String)-> Bool {
         var valid = false
         for ch in pagesString {
@@ -80,129 +79,6 @@ class KMPageRangeTools: NSObject {
         
         return result
     }
-
-    private class func parseSelectedIndexs(selectedIndex: Array<Int>) -> String {
-        if (selectedIndex.count <= 0) {
-            return ""
-        }
-        if (selectedIndex.count == 1) {
-            return "\((selectedIndex.first)!)"
-        }
-        if (selectedIndex.count == 2) {
-            return "\((selectedIndex.first)!),\((selectedIndex.last)!)"
-        }
-        
-        // 元素大于2个
-        var string: String = ""
-        var index = 0
-        var prePage = 0
-        var count = 0
-        var cubeStart = NSNotFound
-        var cubeEnd = NSNotFound
-        for i in selectedIndex {
-            if index == 0 {
-                string.append(String(i))
-            } else {
-                if i - prePage == 1 {
-                    if count == 0 {
-                        cubeStart = prePage
-                    }
-                    
-                    count += 1
-                } else {
-                    count = 0
-                }
-                
-                // 最后一个元素
-                if (index == selectedIndex.count-1) {
-                    if cubeStart != NSNotFound && cubeEnd != NSNotFound { /// 有效块
-                        if cubeStart == selectedIndex.first {
-                            string.removeFirst()
-                        } else {
-                            string.append(",")
-                        }
-                        
-                        if index == selectedIndex.count-1 {
-                            if count == 0 {
-                                string.append(String(cubeStart))
-                                string.append("-")
-                                string.append(String(cubeEnd))
-                                
-                                string.append(",")
-                                string.append(String(i))
-                            } else {
-                                string.append(String(cubeStart))
-                                string.append("-")
-                                string.append(String(i))
-                            }
-                        } else {
-                            string.append(String(cubeStart))
-                            string.append("-")
-                            string.append(String(cubeEnd))
-                        }
-                    } else {
-                        if prePage == selectedIndex.first {
-                            
-                        } else {
-                            string.append(",")
-                            string.append(String(prePage))
-                        }
-                        
-                        cubeStart = NSNotFound
-                        cubeEnd = NSNotFound
-                    }
-                    break
-                }
-                
-                // 不是最后一个元素
-                if count == 0 { /// 块结束
-                    if cubeStart != NSNotFound && cubeEnd != NSNotFound { /// 有效块
-                        if cubeStart == selectedIndex.first {
-                            string.removeFirst()
-                        } else {
-                            string.append(",")
-                        }
-                        
-                        
-                        if index == selectedIndex.count-1 {
-                            if count == 0 {
-                                string.append(String(cubeStart))
-                                string.append("-")
-                                string.append(String(cubeEnd))
-                                
-                                string.append(",")
-                                string.append(String(i))
-                            } else {
-                                string.append(String(cubeStart))
-                                string.append("-")
-                                string.append(String(i))
-                            }
-                        } else {
-                            string.append(String(cubeStart))
-                            string.append("-")
-                            string.append(String(cubeEnd))
-                        }
-                    } else {
-                        if prePage == selectedIndex.first {
-                            //                                    string.append(",")
-                        } else {
-                            string.append(",")
-                            string.append(String(prePage))
-                        }
-                        
-                        cubeStart = NSNotFound
-                        cubeEnd = NSNotFound
-                    }
-                } else if count >= 2 { /// 可成块
-                    cubeEnd = i
-                }
-            }
-            
-            prePage = i
-            index += 1
-        }
-        return string
-    }
     
     class func newParseSelectedIndexs(selectedIndex: Array<Int>) -> String {
         if (selectedIndex.count == 0) {

+ 8 - 8
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFPageExtensions/CPDFPage+PDFListView.swift

@@ -17,19 +17,19 @@ import Foundation
         }
         
         var data: Data?
-        let page = self.copy() as! PDFPage
+        let page = self.copy() as? CPDFPage
         
         if #available(macOS 10.11, *) {
             // On 10.11 the media box is shifted back to the origin without the contents being shifted
-            page.setBounds(rect, for: .cropBox)
+            page?.setBounds(rect, for: .cropBox)
         } else {
-            page.setBounds(rect, for: .mediaBox)
-            page.setBounds(NSZeroRect, for: .cropBox)
+            page?.setBounds(rect, for: .mediaBox)
+            page?.setBounds(NSZeroRect, for: .cropBox)
         }
-        page.setBounds(NSZeroRect, for: .bleedBox)
-        page.setBounds(NSZeroRect, for: .trimBox)
-        page.setBounds(NSZeroRect, for: .artBox)
-        data = page.dataRepresentation
+        page?.setBounds(NSZeroRect, for: .bleedBox)
+        page?.setBounds(NSZeroRect, for: .trimBox)
+        page?.setBounds(NSZeroRect, for: .artBox)
+//        data = page?.dataRepresentation
         
         return data
     }

+ 26 - 73
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController.swift

@@ -1760,15 +1760,16 @@ extension KMLeftSideViewController: NSTableViewDelegate, NSTableViewDataSource {
             var fileURLArray: [String] = []
             if indexSet.count > 1 {
                 var docmentName = ""
-                var tFileName = String(format: "%@", self.fileNameWithSelectedPages(indexSet))
-                var pdf = CPDFDocument()
+                let tFileName = String(format: "%@", self.fileNameWithSelectedPages(indexSet))
+                let 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
+//                        let copyPage = self.listView.document.page(at: UInt(idx)).copy() as? CPDFPage
+                        let copyPage = self.listView.document.page(at: UInt(idx))
                         pdf?.insertPageObject(copyPage, at: pdf?.pageCount ?? 0)
                     }
                 }
-                var fileURL = dropDestination.appendingPathComponent(tFileName).appendingPathExtension("pdf").uniqueFileURL()
+                let fileURL = dropDestination.appendingPathComponent(tFileName).appendingPathExtension("pdf").uniqueFileURL()
                 docmentName = fileURL.path
                 let success = pdf?.write(toFile: docmentName) ?? false
                 if(success) {
@@ -1777,21 +1778,23 @@ extension KMLeftSideViewController: NSTableViewDelegate, NSTableViewDataSource {
             } 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];
+                        fileURL = fileURL.appendingPathExtension("pdf").uniqueFileURL()
+                        let pdf = CPDFDocument()
+//                        let copyPage = page.copy() as? CPDFPage
+                        let copyPage = page
+                        pdf?.insertPageObject(copyPage, at: pdf?.pageCount ?? 0)
+                        let success = pdf?.write(toFile: fileURL.path) ?? false
+                        if success {
+                            fileURLArray.append(fileURL.lastPathComponent)
+                        }
                     } 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)) != nil
-                    if success {
-                        fileURLArray.append(fileURL.lastPathComponent)
+                        fileURL = fileURL.appendingPathExtension("tiff").uniqueFileURL()
+                        let fileData = page.PDFListViewTIFFData(for: page.bounds(for: self.listView?.displayBox ?? .cropBox))
+                        let success = (try?fileData?.write(to: fileURL)) != nil
+                        if success {
+                            fileURLArray.append(fileURL.lastPathComponent)
+                        }
                     }
                 }
             }
@@ -1810,7 +1813,7 @@ extension KMLeftSideViewController: NSTableViewDelegate, NSTableViewDataSource {
                 }
             }
         }
-        return[]
+        return []
     }
     
     func tableViewColumnDidResize(_ notification: Notification) {
@@ -3243,70 +3246,20 @@ extension KMLeftSideViewController {
         if (itemIndexes.count > 1) {
             pagesName.append(" pages")
         } else {
-            pagesName.append("page")
+            pagesName.append(" page")
         }
         
         let docmentName = self.listView.document?.documentURL.deletingPathExtension().lastPathComponent ?? ""
-
-        var fileName = ""
-        if (itemIndexes.count > 0) {
-            if (itemIndexes.count == 1) {
-                let idx = itemIndexes.first! + 1
-                let tFileName = String(format: "%@ %@", pagesName, "\(idx)")
-                return String(format: "%@%@", docmentName, tFileName)
-            }
-            
-            var sortIndex = IndexSet()
-            for idx in itemIndexes {
-                let _idx = idx + 1
-                sortIndex.insert(_idx)
-            }
-//            NSSortDescriptor * sort = [[NSSortDescriptor alloc] initWithKey:nil ascending:YES];
-//            NSArray *sortDesc = @[sort];
-//            NSArray *sortArray = [sortIndex sortedArrayUsingDescriptors:sortDesc];
-            let sortArray = sortIndex.sorted()
-            
-            var a = 0
-            var b = 0
-            
-            for num in sortArray {
-//            for (NSNumber *num in sortArray) {
-                if (fileName.isEmpty == false) {
-                    if (num == b+1) {
-                        b = num
-                        if (num == sortArray.last) {
-                            fileName = "\(fileName)\(a)-\(b)"
-                        }
-                    } else {
-                        if (a == b) {
-                            fileName = "\(fileName)\(a),"
-                        } else {
-                            fileName = "\(fileName)\(a)-\(b),"
-                        }
-                        b = num
-                        a = b
-                        if (num == sortArray.last) {
-                            fileName = "\(fileName)\(a)"
-                        }
-                    }
-                } else {
-                    fileName = ""
-                    b = num
-                    a = b
-                }
-            }
-            let tFileName = String(format: "%@ %@", pagesName,fileName)
-
-            return String(format: "%@%@", docmentName,tFileName)
-        }
-        return ""
+        let tFileName = String(format: "%@ %@", pagesName,KMTools.parseIndexSet(indexSet: itemIndexes))
+        return String(format: "%@%@", docmentName,tFileName)
     }
     
     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
+//            fileName = doc.displayName.deletingPathExtension
+            fileName = doc.fileURL?.deletingPathExtension().lastPathComponent ?? (MainBundle.nameSpaceName ?? "")
         }
         return "\(fileName)-Page \(pageIndex)"
     }

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

@@ -516,22 +516,6 @@
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
-            uuid = "2C2EEAE4-2128-449A-8EDD-44560A48AAAC"
-            shouldBeEnabled = "Yes"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "PDF Master/Class/PDFWindowController/ViewController/KMMainViewController.swift"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "2644"
-            endingLineNumber = "2644"
-            landmarkName = "pdfListViewKeyDownIsContinue(_:theEvent:)"
-            landmarkType = "7">
-         </BreakpointContent>
-      </BreakpointProxy>
       <BreakpointProxy
          BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
          <BreakpointContent