Explorar el Código

【页面编辑】拆分权益弹窗还原

tangchao hace 1 año
padre
commit
ba64c2e064

+ 136 - 61
PDF Office/PDF Master/Class/PDFTools/PageEdit/Controller/KMPDFEditViewController.swift

@@ -380,6 +380,27 @@ class KMPDFEditViewController: KMPDFThumbViewBaseController {
         
         Task { @MainActor in
             self.toolBar.unSelectItem(for: KMToolbarPageEditSplitItemIdentifier)
+//            if await (KMLightMemberManager.manager.canUseAdvanced() == false) {
+//                let _ = KMComparativeTableViewController.show(window: self.view.window!, .pageEdit)
+//                return
+//            }
+            if await (KMLightMemberManager.manager.canPayFunction() == false) {
+                let _ = KMSubscribeWaterMarkWindowController.show(window: self.view.window!, isContinue: true, type: .split) { isSubscribeSuccess, isWaterMarkExport, isClose in
+                    if (isClose) {
+                        return
+                    }
+                    if (isSubscribeSuccess) {
+                        self._showSplitWindow()
+                        return
+                    }
+                    if (isWaterMarkExport) {
+                        self._showSplitWindow(limit: true)
+                        return
+                    }
+                }
+                return
+            }
+            
             self._showSplitWindow()
         }
     }
@@ -429,73 +450,127 @@ class KMPDFEditViewController: KMPDFThumbViewBaseController {
                 return
             }
             
-            if self?.canPayFunction == false {
-                let _ = KMSubscribeWaterMarkWindowController.show(window: windowController.window!, isContinue: true, type: .split) { isSubscribeSuccess, isWaterMarkExport, isClose in
-                    var limit = true
-                    if (isClose) {
-                        return
-                    }
-                    if (isSubscribeSuccess) {
-                        limit = false
-                    }
-                    if (isWaterMarkExport) {
-                        
-                    }
+//            if self?.canPayFunction == false {
+//                let _ = KMSubscribeWaterMarkWindowController.show(window: windowController.window!, isContinue: true, type: .split) { isSubscribeSuccess, isWaterMarkExport, isClose in
+//                    var limit = true
+//                    if (isClose) {
+//                        return
+//                    }
+//                    if (isSubscribeSuccess) {
+//                        limit = false
+//                    }
+//                    if (isWaterMarkExport) {
+//
+//                    }
+//
+//                    /// 拆分
+//                    let outputModel = _windowC.model! as! KMPageEditSplitSettingModel
+//                    self?.km_endSheet()
+//
+//                    let panel = NSOpenPanel()
+//                    panel.canChooseFiles = false
+//                    panel.canChooseDirectories = true
+//                    panel.canCreateDirectories = true
+//                    panel.beginSheetModal(for: (self?.view.window)!) { response in
+//                        if (response == .cancel) {
+//                            return
+//                        }
+//
+//                        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)"
+//                            let uniqueFilePath = KMTools.getUniqueFilePath(filePath: filePath)
+//        //                    Swift.debugPrint(uniqueFilePath)
+//                            if (!FileManager.default.fileExists(atPath: uniqueFilePath)) {
+//                                try?FileManager.default.createDirectory(atPath: uniqueFilePath, withIntermediateDirectories: true)
+//                            }
+//
+//                            var filepaths: [String] = []
+//                            for i in 0 ..< file_indexs!.count {
+//                                let indexs = file_indexs![i]
+//                                if (indexs.isEmpty) {
+//                                    continue
+//                                }
+//                                let filepath = String(format: "%@/%@.pdf", uniqueFilePath, model.getNewOutputFileName(index: i+1))
+//                                filepaths.append(filepath)
+//
+//                                let newDocument = CPDFDocument()
+//                                newDocument?.importPages(indexs, from: _document, at: 0)
+//                                self?.progressC?.increment(by: 1.0)
+//                                if (limit) {
+//                                    let _ = KMTools.saveWatermarkDocument(document: newDocument!, to: URL(fileURLWithPath: filepath))
+//                                } else {
+//                                    newDocument?.write(to: URL(fileURLWithPath: filepath))
+//                                }
+//                            }
+//                            self?.hiddenProgressWindow()
+//                            if let _urlString = filepaths.first?.deletingLastPathComponent {
+//                                NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: _urlString)])
+//                            }
+//                        }
+//                    }
+//                }
+//            }
+            /// 拆分
+            let outputModel = _windowC.model! as! KMPageEditSplitSettingModel
+            self?.km_endSheet()
+            
+            let panel = NSOpenPanel()
+            panel.canChooseFiles = false
+            panel.canChooseDirectories = true
+            panel.canCreateDirectories = true
+            panel.beginSheetModal(for: (self?.view.window)!) { response in
+                if (response == .cancel) {
+                    return
+                }
+                
+                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 outputModel = _windowC.model! as! KMPageEditSplitSettingModel
-                    self?.km_endSheet()
+                    let filePath = "\(panel.url!.path)/\(_document.documentURL.deletingPathExtension().lastPathComponent)"
+                    let uniqueFilePath = KMTools.getUniqueFilePath(filePath: filePath)
+//                    Swift.debugPrint(uniqueFilePath)
+                    if (!FileManager.default.fileExists(atPath: uniqueFilePath)) {
+                        try?FileManager.default.createDirectory(atPath: uniqueFilePath, withIntermediateDirectories: true)
+                    }
                     
-                    let panel = NSOpenPanel()
-                    panel.canChooseFiles = false
-                    panel.canChooseDirectories = true
-                    panel.canCreateDirectories = true
-                    panel.beginSheetModal(for: (self?.view.window)!) { response in
-                        if (response == .cancel) {
-                            return
+                    var filepaths: [String] = []
+                    for i in 0 ..< file_indexs!.count {
+                        let indexs = file_indexs![i]
+                        if (indexs.isEmpty) {
+                            continue
                         }
+                        let filepath = String(format: "%@/%@.pdf", uniqueFilePath, model.getNewOutputFileName(index: i+1))
+                        filepaths.append(filepath)
                         
-                        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)"
-                            let uniqueFilePath = KMTools.getUniqueFilePath(filePath: filePath)
-        //                    Swift.debugPrint(uniqueFilePath)
-                            if (!FileManager.default.fileExists(atPath: uniqueFilePath)) {
-                                try?FileManager.default.createDirectory(atPath: uniqueFilePath, withIntermediateDirectories: true)
-                            }
-                            
-                            var filepaths: [String] = []
-                            for i in 0 ..< file_indexs!.count {
-                                let indexs = file_indexs![i]
-                                if (indexs.isEmpty) {
-                                    continue
-                                }
-                                let filepath = String(format: "%@/%@.pdf", uniqueFilePath, model.getNewOutputFileName(index: i+1))
-                                filepaths.append(filepath)
-                                
-                                let newDocument = CPDFDocument()
-                                newDocument?.importPages(indexs, from: _document, at: 0)
-                                self?.progressC?.increment(by: 1.0)
-                                if (limit) {
-                                    let _ = KMTools.saveWatermarkDocument(document: newDocument!, to: URL(fileURLWithPath: filepath))
-                                } else {
-                                    newDocument?.write(to: URL(fileURLWithPath: filepath))
-                                }
-                            }
-                            self?.hiddenProgressWindow()
-                            if let _urlString = filepaths.first?.deletingLastPathComponent {
-                                NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: _urlString)])
-                            }
+                        let newDocument = CPDFDocument()
+                        newDocument?.importPages(indexs, from: _document, at: 0)
+                        self?.progressC?.increment(by: 1.0)
+                        if (limit) {
+                            let _ = KMTools.saveWatermarkDocument(document: newDocument!, to: URL(fileURLWithPath: filepath))
+                        } else {
+                            newDocument?.write(to: URL(fileURLWithPath: filepath))
                         }
                     }
+                    self?.hiddenProgressWindow()
+                    if let _urlString = filepaths.first?.deletingLastPathComponent {
+                        NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: _urlString)])
+                    }
                 }
             }
         }

+ 2 - 34
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift

@@ -2424,48 +2424,16 @@ extension KMMainViewController : KMMainToolbarControllerDelegate {
             if (type == .merge) { /// 合并
                 if (self.listView.document.allowsCopying == false || self.listView.document.allowsPrinting == false) {
                     if await (KMLightMemberManager.manager.canPayFunction() == false) {
-                        //FIXME: 方案待确认,先不处理保存
-//                        self.showMergeWindow(password)
-                        let _ = KMSubscribeWaterMarkWindowController.show(window: self.view.window!, isContinue: true, type: .merge) { isSubscribeSuccess, isWaterMarkExport, isClose in
-                            if (isClose) {
-                                return
-                            }
-                            
                             KMPasswordInputWindow.openWindow(window: self.view.window!, type: .owner, url: self.listView.document.documentURL) { [unowned self] result , password in
                                 if (result == .cancel) {
                                     return
                                 }
                                  
-                                if (isSubscribeSuccess) {
-                                    if (self.needSaveDocument()) {
-                                        self.saveDocumentWithProgressAlert { [unowned self] params in
-                                            self.showMergeWindow(password)
-                                        }
-                                        return
-                                    }
-                                    
-                                    self.showMergeWindow(password)
-                                    return
-                                }
-                                if (isWaterMarkExport) {
-                                    DispatchQueue.main.async {
-                                        NSPanel.savePanel(self.view.window!, panel:{ panel in
-                                            panel.directoryURL = self.document?.documentURL.deletingLastPathComponent()
-                                            panel.nameFieldStringValue = (self.document?.documentURL.lastPathComponent)!
-                                        }) { response, url in
-                                            if (response == .cancel) {
-                                                return
-                                            }
-                                            guard let _url = KMTools.saveWatermarkDocumentToTemp(document: self.document!, secureOptions: self.secureOptions, removePWD: self.removeSecureFlag) else {
-                                                return
-                                            }
-                                            self.showMergeWindow(url: _url, password)
-                                        }
-                                    }
+                                guard let _url =  KMTools.saveWatermarkDocumentToTemp(document: self.listView.document, secureOptions: self.secureOptions, removePWD: self.removeSecureFlag) else {
                                     return
                                 }
+                                self.showMergeWindow(url: _url, password)
                             }
-                        }
                         return
                     }