// // KMRedactConfirmWindowController.swift // PDF Master // // Created by tangchao on 2023/1/18. // import Cocoa enum KMRedactConfirmType { case redactOne case eraserOne case redactAll case eraserAll } typealias KMRedactConfirmItemClick = (_ index: Int) -> () class KMRedactConfirmWindowController: NSWindowController { @IBOutlet weak var titleLabel: NSTextField! @IBOutlet weak var subTitleLabel: NSTextField! @IBOutlet weak var despLabel: NSTextField! @IBOutlet weak var funcButton: NSButton! @IBOutlet weak var cancelButton: NSButton! private var myType: KMRedactConfirmType = .redactOne var type: KMRedactConfirmType { get { return myType } set { myType = newValue } } var itemClick: KMRedactConfirmItemClick! convenience init(_ type: KMRedactConfirmType) { self.init(windowNibName: "KMRedactConfirmWindowController") self.type = type } override func windowDidLoad() { super.windowDidLoad() self.titleLabel.font = NSFont.boldSystemFont(ofSize: 16) self.subTitleLabel.textColor = NSColor(white: 0, alpha: 0.6) cancelButton.title = NSLocalizedString("取消", comment: "") cancelButton.isBordered = false cancelButton.wantsLayer = true cancelButton.layer?.borderWidth = 1 cancelButton.layer?.borderColor = NSColor.black.cgColor cancelButton.layer?.cornerRadius = 4 cancelButton.target = self cancelButton.action = #selector(cancelButtonAction) funcButton.isBordered = false funcButton.wantsLayer = true funcButton.layer?.cornerRadius = 4 funcButton.target = self self.funcButton.layer?.backgroundColor = NSColor.black.cgColor funcButton.action = #selector(funcButtonAction) if (self.type == .redactOne) { self.titleLabel.stringValue = NSLocalizedString("Apply Redactions", comment: "") } else if (self.type == .eraserOne) { self.titleLabel.stringValue = NSLocalizedString("Apply Erase", comment: "") } else if (self.type == .redactAll) { self.titleLabel.stringValue = NSLocalizedString("Apply Redactions", comment: "") } else if (self.type == .eraserAll) { self.titleLabel.stringValue = NSLocalizedString("Apply Erase", comment: "") } if (self.type == .redactOne || self.type == .redactAll) { self.subTitleLabel.stringValue = NSLocalizedString("Use blank blocks to remove selected sensitive content.", comment: "") 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: "") self.funcButton.title = NSLocalizedString("Apply & Save as", comment: "") self.funcButton.attributedTitle = NSMutableAttributedString(string: self.funcButton.title, attributes: [NSAttributedString.Key.foregroundColor : NSColor.white]) } if (self.type == .eraserOne || self.type == .eraserAll) { self.subTitleLabel.stringValue = NSLocalizedString("Replace selected sensitive content with color blocks.", comment: "") 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: "") self.funcButton.title = NSLocalizedString("Apply & Save as", comment: "") self.funcButton.attributedTitle = NSMutableAttributedString(string: self.funcButton.title, attributes: [NSAttributedString.Key.foregroundColor : NSColor.white]) } } @objc private func cancelButtonAction() { guard let callback = self.itemClick else { return } callback(2) } @objc private func funcButtonAction() { guard let callback = self.itemClick else { return } callback(1) } }