Browse Source

【综合】系统菜单栏,文件菜单,解除文件权限菜单项补充

tangchao 1 year ago
parent
commit
bdcd6740df

+ 14 - 1
PDF Office/PDF Master/Class/Document/KMMainDocument.swift

@@ -562,7 +562,7 @@ typealias KMMainDocumentCloudUploadHanddler = (@escaping(Bool, String)->()) -> (
         KMPrint("convertNotes")
     }
     @IBAction func batchRemovePassWord(_ sender: Any?) {
-        KMPrint("batchRemovePassWord")
+        self.mainViewController?.removeOwnerPassword()
     }
     @IBAction func batchRemovPrivatySecurity(_ sender: Any?) {
         KMPrint("batchRemovPrivatySecurity")
@@ -727,6 +727,19 @@ extension KMMainDocument {
             return mainVC.isPDFDocumentEdited || mainVC.needSave
         } else if (menuItem.action == #selector(saveAs(_ :))) {
             return !self.isHome
+        } else if menuItem.action == #selector(batchRemovePassWord) {
+            if self.isHome {
+                return false
+            }
+            guard let doc = self.mainViewController?.listView?.document else {
+                return false
+            }
+            let allowsPrinting = doc.allowsPrinting
+            let allowsCopying = doc.allowsCopying
+            if allowsCopying && allowsPrinting {
+                return false
+            }
+            return true
         }
         return super.validateMenuItem(menuItem)
     }

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

@@ -1144,18 +1144,27 @@ let LOCKED_KEY  = "locked"
         }
         
         tip.passwordAction = { [unowned self] view in
-            if (self.listView.document.allowsPrinting == false || self.listView.document.allowsCopying == false) {
-                KMPasswordInputWindow.openWindow(window: self.view.window!, type: .owner, url: self.listView.document.documentURL) { [weak self] result, password in
-                    if result == .cancel { /// 关闭
-                        return
-                    }
-                    /// 解密成功
-                    self?.hiddenSecureLimitTip()
-                    self?.isSaveKeyChain = false
-                    self?.listView.document.unlock(withPassword: password)
-                }
+            self.removeOwnerPassword()
+        }
+    }
+    
+    func removeOwnerPassword() {
+        guard let doc = self.listView?.document else {
+            NSSound.beep()
+            return
+        }
+        if doc.allowsCopying && doc.allowsPrinting {
+            NSSound.beep()
+            return
+        }
+        KMPasswordInputWindow.openWindow(window: self.view.window!, type: .owner, url: doc.documentURL) { [weak self] result, password in
+            if result == .cancel { /// 关闭
                 return
             }
+            /// 解密成功
+            self?.hiddenSecureLimitTip()
+            self?.isSaveKeyChain = false
+            self?.listView.document.unlock(withPassword: password)
         }
     }
     
@@ -2710,15 +2719,7 @@ let LOCKED_KEY  = "locked"
     
     func pdfListViewHaveDocumentAttribute() -> Bool {
         if(!self.listView.document.allowsCopying) {
-            KMPasswordInputWindow.openWindow(window: self.view.window!, type: .owner, url: self.listView.document.documentURL) { [weak self] result, password in
-                if (result == .cancel) {
-                    return
-                }
-                
-                self?.isSaveKeyChain = false
-                self?.listView.document.unlock(withPassword: password)
-                self?.hiddenSecureLimitTip()
-            }
+            self.removeOwnerPassword()
             return false
         }
         return true

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

@@ -78,8 +78,8 @@
             filePath = "PDF Master/Class/PDFWindowController/ViewController/KMMainViewController.swift"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "2376"
-            endingLineNumber = "2376"
+            startingLineNumber = "2385"
+            endingLineNumber = "2385"
             landmarkName = "KMMainViewController"
             landmarkType = "3">
          </BreakpointContent>