Selaa lähdekoodia

【页面编辑】拆分新增进度条

tangchao 1 vuosi sitten
vanhempi
commit
be81b58802

+ 29 - 0
PDF Office/PDF Master/Class/Common/Base/KMBaseViewController.swift

@@ -202,6 +202,35 @@ class KMBaseViewController: NSViewController {
         }
     }
     
+    // MARK: - Progress Window
+    
+    var progressC: SKProgressController?
+    func showProgressWindow(message: String = "") {
+        if (self.progressC != nil) {
+            self.hiddenProgressWindow()
+        }
+        
+        let progressC = SKProgressController()
+        progressC.showClose = false
+        progressC.message = message
+        progressC.window?.backgroundColor = NSColor(hex: "#36383B")
+        progressC.window?.contentView?.wantsLayer = true
+        progressC.window?.contentView?.layer?.backgroundColor = NSColor(hex: "#36383B").cgColor
+        progressC.progressField.textColor = NSColor.white
+        
+        self.progressC = progressC
+        self.view.window?.beginSheet(progressC.window!)
+    }
+    
+    func hiddenProgressWindow() {
+        if let _progressC = self.progressC {
+            if let _window = _progressC.window {
+                self.view.window?.endSheet(_window)
+            }
+            self.progressC = nil
+        }
+    }
+    
     // MARK: - Menu Add & Remove
     
     public func addMenu(to view: NSView?) {

+ 31 - 5
PDF Office/PDF Master/Class/PDFTools/PageEdit/Controller/KMPDFEditViewController.swift

@@ -584,11 +584,37 @@ class KMPDFEditViewController: KMPDFThumbViewBaseController {
                 if (response == .cancel) {
                     return
                 }
-                KMPageEditTools.split((self?.listView?.document)!, outputModel, panel.url!.path, outputModel.outputFileNameDeletePathExtension) { result, outputFilepaths, error in
-                    if (result) {
-                        if let _urlString = outputFilepaths?.first?.deletingLastPathComponent {
-                            NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: _urlString)])
-                        }
+                
+                let file_indexs = outputModel.getSplitIndexSets
+                if (file_indexs == nil || file_indexs!.count <= 0) {
+                    return
+                }
+                
+                DispatchQueue.main.async {
+                    self?.showProgressWindow(message: NSLocalizedString("Spliting...", comment: ""))
+                    self?.progressC?.maxValue = Double(file_indexs!.count)
+                    let _document: CPDFDocument = (self?.listView?.document)!
+                    
+                    let filePath = "\(panel.url!.path)/\(_document.documentURL.deletingPathExtension().lastPathComponent)"
+                    if (!FileManager.default.fileExists(atPath: filePath)) {
+                        try?FileManager.default.createDirectory(atPath: filePath, withIntermediateDirectories: true)
+                    }
+                    let fileName = outputModel.outputFileNameDeletePathExtension
+                    
+                    var filepaths: [String] = []
+                    for i in 0 ..< file_indexs!.count {
+                        let indexs = file_indexs![i]
+                        let filepath = String(format: "%@/%@ %d.pdf", filePath, fileName!, i+1)
+                        filepaths.append(filepath)
+                        
+                        let newDocument = CPDFDocument()
+                        newDocument?.importPages(indexs, from: _document, at: 0)
+                        self?.progressC?.increment(by: 1.0)
+                        newDocument?.write(to: URL(fileURLWithPath: filepath))
+                    }
+                    self?.hiddenProgressWindow()
+                    if let _urlString = filepaths.first?.deletingLastPathComponent {
+                        NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: _urlString)])
                     }
                 }
             }

+ 7 - 1
PDF Office/PDF Master/Class/PDFTools/PageEdit/Model/KMPageEditSplitSettingModel.swift

@@ -108,9 +108,15 @@ class KMPageEditSplitSettingModel: KMPageEditSettingBaseModel {
                     if (selectedPages.count <= 0) {
                         return nil
                     }
+                    var tmpPages: [Int] = []
+                    for page in selectedPages {
+                        if (page > 0) {
+                            tmpPages.append(page-1)
+                        }
+                    }
                     
                     for i in 0 ..< pageCount {
-                        if (selectedPages.contains(i)) {
+                        if (tmpPages.contains(i)) {
                             indexSet1.insert(i)
                         } else {
                             indexSet2.insert(i)