Browse Source

【fix】【标记密文】添加标记密文,点击切换编辑PDF,提示保存-不保存,此时会进入2种模式

tangchao 6 months ago
parent
commit
9c5188bc90

+ 63 - 0
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/KMToolbarController.swift

@@ -750,6 +750,27 @@ extension KMToolbarController: KMToolbarViewControllerDelegate {
     
     func toolbarViewController(_ viewController: KMToolbarViewController, clickMode toolMode: KMToolbarViewType, toolbar toolbarItem: KMToolbarItemView, _ pages: [Int]) {
         let beforeModel = KMToolbarViewType(rawValue: self.lastItemBox.clickButton.tag) ?? .None
+        
+        if toolMode != .redact { // 标记秘文
+            let mainC = self.delegate as? KMMainViewController
+            var control: KMPDFRedactViewController?
+            for childC in mainC?.children ?? [] {
+                if (childC.isKind(of: KMPDFRedactViewController.self)) {
+                    control = (childC as! KMPDFRedactViewController)
+                    break
+                }
+            }
+            if let annos = control?.redactPdfView.newAddAnnotation, annos.count > 0 {
+                let alert = NSAlert()
+                alert.informativeText = KMLocalizedString("There are unapplied redactions in this file. Exit will not save redaction.", nil)
+                alert.addButton(withTitle: KMLocalizedString("Exit", nil))
+                alert.addButton(withTitle: KMLocalizedString("Cancel", nil))
+                let resp = alert.runModal()
+                if resp != .alertFirstButtonReturn {  // 取消
+                    return
+                }
+            }
+        }
         if self.lastItemBox != nil {
             if (toolbarItem.isSelected && toolMode.isToolMode()) {
                 // no nothings
@@ -958,6 +979,27 @@ extension KMToolbarController: KMToolbarViewControllerDelegate {
             }
         }
         
+        if toolbarItem.itemIdentifier != KMDocumentRedactToolbarItemIdentifier { // 标记秘文
+            let mainC = self.delegate as? KMMainViewController
+            var control: KMPDFRedactViewController?
+            for childC in mainC?.children ?? [] {
+                if (childC.isKind(of: KMPDFRedactViewController.self)) {
+                    control = (childC as! KMPDFRedactViewController)
+                    break
+                }
+            }
+            if let annos = control?.redactPdfView.newAddAnnotation, annos.count > 0 {
+                let alert = NSAlert()
+                alert.informativeText = KMLocalizedString("There are unapplied redactions in this file. Exit will not save redaction.", nil)
+                alert.addButton(withTitle: KMLocalizedString("Exit", nil))
+                alert.addButton(withTitle: KMLocalizedString("Cancel", nil))
+                let resp = alert.runModal()
+                if resp != .alertFirstButtonReturn {  // 取消
+                    return
+                }
+            }
+        }
+        
         self.delegate?.toolbarViewController?(viewController, itemDidClick: toolbarItem)
     }
     
@@ -988,6 +1030,27 @@ extension KMToolbarController: KMToolbarViewControllerDelegate {
             }
         }
         
+        if toolbarItem.itemIdentifier != KMDocumentRedactToolbarItemIdentifier { // 标记秘文
+            let mainC = self.delegate as? KMMainViewController
+            var control: KMPDFRedactViewController?
+            for childC in mainC?.children ?? [] {
+                if (childC.isKind(of: KMPDFRedactViewController.self)) {
+                    control = (childC as! KMPDFRedactViewController)
+                    break
+                }
+            }
+            if let annos = control?.redactPdfView.newAddAnnotation, annos.count > 0 {
+                let alert = NSAlert()
+                alert.informativeText = KMLocalizedString("There are unapplied redactions in this file. Exit will not save redaction.", nil)
+                alert.addButton(withTitle: KMLocalizedString("Exit", nil))
+                alert.addButton(withTitle: KMLocalizedString("Cancel", nil))
+                let resp = alert.runModal()
+                if resp != .alertFirstButtonReturn {  // 取消
+                    return
+                }
+            }
+        }
+        
         self.delegate?.toolbarViewController?(viewController, menuItemDidClick: toolbarItem, index: index, info: info)
     }
     

+ 7 - 7
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController.swift

@@ -748,13 +748,13 @@ import Cocoa
         let controller = self._getPDFRedactController()
         if let data = controller {
             if data.redactPdfView.newAddAnnotation.count > 0 {
-                KMAlertTool.runModel(message: "", informative: KMLocalizedString("There are unapplied redactions in this file. Exit will not save redaction.", nil), buttons: [KMLocalizedString("Exit", nil), KMLocalizedString("Cancel", nil)]) { response in
-                    if response == .alertFirstButtonReturn {
-                        data.redactPdfView.newAddAnnotation.removeAll()
-                        self.exitRedact()
-                    }
-                }
-                return
+//                KMAlertTool.runModel(message: "", informative: KMLocalizedString("There are unapplied redactions in this file. Exit will not save redaction.", nil), buttons: [KMLocalizedString("Exit", nil), KMLocalizedString("Cancel", nil)]) { response in
+//                    if response == .alertFirstButtonReturn {
+                controller?.redactPdfView.newAddAnnotation.removeAll()
+//                        self.exitRedact()
+//                    }
+//                }
+//                return
             }
         }
         NSColorPanel.shared.showsAlpha = true