KMRedactConfirmWindowController.swift 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // KMRedactConfirmWindowController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2023/1/18.
  6. //
  7. import Cocoa
  8. enum KMRedactConfirmType {
  9. case redactOne
  10. case eraserOne
  11. case redactAll
  12. case eraserAll
  13. }
  14. typealias KMRedactConfirmItemClick = (_ index: Int) -> ()
  15. class KMRedactConfirmWindowController: NSWindowController {
  16. @IBOutlet weak var titleLabel: NSTextField!
  17. @IBOutlet weak var subTitleLabel: NSTextField!
  18. @IBOutlet weak var despLabel: NSTextField!
  19. @IBOutlet weak var funcButton: NSButton!
  20. @IBOutlet weak var cancelButton: NSButton!
  21. private var myType: KMRedactConfirmType = .redactOne
  22. var type: KMRedactConfirmType {
  23. get {
  24. return myType
  25. }
  26. set {
  27. myType = newValue
  28. }
  29. }
  30. var itemClick: KMRedactConfirmItemClick!
  31. convenience init(_ type: KMRedactConfirmType) {
  32. self.init(windowNibName: "KMRedactConfirmWindowController")
  33. self.type = type
  34. }
  35. override func windowDidLoad() {
  36. super.windowDidLoad()
  37. self.titleLabel.font = NSFont.boldSystemFont(ofSize: 16)
  38. self.subTitleLabel.textColor = NSColor(white: 0, alpha: 0.6)
  39. cancelButton.title = NSLocalizedString("取消", comment: "")
  40. cancelButton.isBordered = false
  41. cancelButton.wantsLayer = true
  42. cancelButton.layer?.borderWidth = 1
  43. cancelButton.layer?.borderColor = NSColor.black.cgColor
  44. cancelButton.layer?.cornerRadius = 4
  45. cancelButton.target = self
  46. cancelButton.action = #selector(cancelButtonAction)
  47. funcButton.isBordered = false
  48. funcButton.wantsLayer = true
  49. funcButton.layer?.cornerRadius = 4
  50. funcButton.target = self
  51. self.funcButton.layer?.backgroundColor = NSColor.black.cgColor
  52. funcButton.action = #selector(funcButtonAction)
  53. if (self.type == .redactOne) {
  54. self.titleLabel.stringValue = NSLocalizedString("Apply Redactions", comment: "")
  55. } else if (self.type == .eraserOne) {
  56. self.titleLabel.stringValue = NSLocalizedString("Apply Erase", comment: "")
  57. } else if (self.type == .redactAll) {
  58. self.titleLabel.stringValue = NSLocalizedString("Apply Redactions", comment: "")
  59. } else if (self.type == .eraserAll) {
  60. self.titleLabel.stringValue = NSLocalizedString("Apply Erase", comment: "")
  61. }
  62. if (self.type == .redactOne || self.type == .redactAll) {
  63. self.subTitleLabel.stringValue = NSLocalizedString("Use blank blocks to remove selected sensitive content.", comment: "")
  64. self.despLabel.stringValue = NSLocalizedString("This action will permanently delete the marked ciphertext information from this document and you will not be able to retrieve the marked ciphertext information.", comment: "")
  65. self.funcButton.title = NSLocalizedString("Apply & Save as", comment: "")
  66. self.funcButton.attributedTitle = NSMutableAttributedString(string: self.funcButton.title, attributes: [NSAttributedString.Key.foregroundColor : NSColor.white])
  67. }
  68. if (self.type == .eraserOne || self.type == .eraserAll) {
  69. self.subTitleLabel.stringValue = NSLocalizedString("Replace selected sensitive content with color blocks.", comment: "")
  70. self.despLabel.stringValue = NSLocalizedString("This action will permanently delete the marked ciphertext information from this document and you will not be able to retrieve the marked ciphertext information.", comment: "")
  71. self.funcButton.title = NSLocalizedString("Apply & Save as", comment: "")
  72. self.funcButton.attributedTitle = NSMutableAttributedString(string: self.funcButton.title, attributes: [NSAttributedString.Key.foregroundColor : NSColor.white])
  73. }
  74. }
  75. @objc private func cancelButtonAction() {
  76. guard let callback = self.itemClick else {
  77. return
  78. }
  79. callback(2)
  80. }
  81. @objc private func funcButtonAction() {
  82. guard let callback = self.itemClick else {
  83. return
  84. }
  85. callback(1)
  86. }
  87. }