KMRemovePasswordAlertWindowController.swift 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // KMRemovePasswordAlertWindowController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2022/11/29.
  6. //
  7. import Cocoa
  8. typealias KMRemovePasswordAlertWindowControllerItemClick = (Int) -> ()
  9. class KMRemovePasswordAlertWindowController: NSWindowController {
  10. @IBOutlet weak var titleLabel: NSTextField!
  11. @IBOutlet weak var cancelButton: NSButton!
  12. @IBOutlet weak var confirmButton: NSButton!
  13. var itemClick: KMRemovePasswordAlertWindowControllerItemClick!
  14. override func windowDidLoad() {
  15. super.windowDidLoad()
  16. titleLabel.stringValue = NSLocalizedString("Are you sure you want to remove the security settings for the file?", comment: "")
  17. titleLabel.font = NSFont.boldSystemFont(ofSize: 16)
  18. let style = NSMutableParagraphStyle()
  19. style.lineSpacing = 6
  20. style.alignment = .center
  21. titleLabel.attributedStringValue = NSAttributedString.init(string: titleLabel.stringValue, attributes: [.font : NSFont.boldSystemFont(ofSize: 16),.paragraphStyle : style])
  22. for button in [cancelButton, confirmButton] {
  23. button?.wantsLayer = true
  24. button?.layer?.borderWidth = 1
  25. button?.layer?.borderColor = NSColor.black.cgColor
  26. button?.layer?.cornerRadius = 4
  27. button!.target = self
  28. if ((button?.isEqual(to: cancelButton))!) {
  29. button?.title = NSLocalizedString("Cancel", comment: "")
  30. button?.action = #selector(cancelButtonAction)
  31. } else {
  32. button?.title = NSLocalizedString("Delete", comment: "")
  33. button?.layer?.backgroundColor = NSColor.black.cgColor
  34. button?.attributedTitle = NSMutableAttributedString(string: button!.title, attributes: [.foregroundColor : NSColor.white])
  35. button?.action = #selector(confirmButtonAction)
  36. }
  37. }
  38. }
  39. @objc func cancelButtonAction() {
  40. guard let callback = itemClick else {
  41. return
  42. }
  43. callback(1)
  44. }
  45. @objc func confirmButtonAction() {
  46. guard let callback = itemClick else {
  47. return
  48. }
  49. callback(2)
  50. }
  51. }