KMSecureAlertView.swift 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // KMSecureAlertView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by lizhe on 2024/1/24.
  6. //
  7. import Cocoa
  8. typealias KMSecureAlertViewCloseAction = (_ view: KMSecureAlertView) -> Void
  9. typealias KMSecureAlertViewPasswordAction = (_ view: KMSecureAlertView) -> Void
  10. class KMSecureAlertView: KMBaseXibView {
  11. @IBOutlet var tipsLabel: NSTextField!
  12. @IBOutlet var rightBox: NSBox!
  13. @IBOutlet var rightBtn: NSButton!
  14. var closeAction: KMSecureAlertViewCloseAction?
  15. var passwordAction: KMSecureAlertViewPasswordAction?
  16. var isClosePromptView: Bool = false
  17. override func setup() {
  18. self.wantsLayer = true
  19. self.layer?.backgroundColor = KMAppearance.Else.tipbarColor().cgColor
  20. self.tipsLabel.stringValue = NSLocalizedString("This document has a permission password.", comment: "")
  21. self.tipsLabel.textColor = KMAppearance.Layout.w0Color()
  22. self.rightBox.borderWidth = 1.0
  23. self.rightBox.borderColor = KMAppearance.Layout.w70Color()
  24. self.rightBtn.title = " \(NSLocalizedString("Enter Password", comment: "")) "
  25. if self.rightBtn.responds(to: #selector(setter: NSButton.bezelColor)) {
  26. self.rightBtn.bezelColor = KMAppearance.Interactive.m0Color()
  27. }
  28. }
  29. @IBAction func closedAction(_ sender: Any) {
  30. self.isClosePromptView = true
  31. self.closeAction?(self)
  32. self.removeFromSuperview()
  33. }
  34. @IBAction func passwordAction(_ sender: Any) {
  35. self.passwordAction?(self)
  36. }
  37. func show(in pdfView: CPDFView) {
  38. if self.isClosePromptView || !pdfView.document!.isEncrypted {
  39. if self.superview != nil {
  40. self.removeFromSuperview()
  41. }
  42. return
  43. }
  44. DispatchQueue.main.async {
  45. self.frame = NSRect(x: 0, y: pdfView.frame.size.height - 40, width: pdfView.frame.size.width, height: 40)
  46. pdfView.addSubview(self)
  47. self.autoresizingMask = [.width, .minYMargin]
  48. }
  49. }
  50. }