DSignatureCreateViewController.swift 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // DSignatureCreateViewController.swift
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by Niehaoyu on 2023/9/28.
  6. //
  7. import Cocoa
  8. class DSignatureCreateViewController: NSViewController {
  9. @IBOutlet weak var configureLabel: NSTextField!
  10. @IBOutlet weak var selectLabel: NSTextField!
  11. @IBOutlet weak var fileBox: NSBox!
  12. @IBOutlet weak var fileLabel: NSTextField!
  13. @IBOutlet weak var fileSubLabel: NSTextField!
  14. @IBOutlet weak var createFileButton: NSButton!
  15. @IBOutlet weak var createButton: NSButton!
  16. @IBOutlet weak var creatBox: NSBox!
  17. @IBOutlet weak var creatLabel: NSTextField!
  18. @IBOutlet weak var creatSubLabel: NSTextField!
  19. @IBOutlet weak var promptBox: NSBox!
  20. @IBOutlet var promptTextView: NSTextView!
  21. @IBOutlet weak var previousStepButton: NSButton!
  22. @IBOutlet weak var continueButton: NSButton!
  23. var isCreatDS: Bool = false
  24. var _type: CDSignatureCreatType = .createNone
  25. var actionBlock: ((_ createVC:DSignatureCreateViewController, _ actionType:DSignatureActionType, _ createType: CDSignatureCreatType)->Void)?
  26. override func viewWillAppear() {
  27. super.viewWillAppear()
  28. if self.isCreatDS {
  29. self.previousStepButton.isHidden = true
  30. }
  31. }
  32. override func viewDidLoad() {
  33. super.viewDidLoad()
  34. // Do view setup here.
  35. self.localizedLanguage()
  36. self.configureLabel.textColor = NSColor.labelColor
  37. self.selectLabel.textColor = NSColor.labelColor
  38. self.fileLabel.textColor = NSColor.labelColor
  39. self.creatLabel.textColor = NSColor.labelColor
  40. self.fileSubLabel.textColor = NSColor.labelColor
  41. self.creatSubLabel.textColor = NSColor.labelColor
  42. self.promptTextView.textColor = NSColor.labelColor
  43. self.fileBox.borderColor = NSColor(red: 165.0/255.0, green: 167.0/255.0, blue: 179.0/255.0, alpha: 1.0)
  44. self.creatBox.borderColor = NSColor(red: 165.0/255.0, green: 167.0/255.0, blue: 179.0/255.0, alpha: 1.0)
  45. self.type = .fromFile
  46. }
  47. //MARK: Setter
  48. var type: CDSignatureCreatType {
  49. set {
  50. _type = newValue;
  51. if _type == .signCreate {
  52. self.createButton.state = .on
  53. self.createFileButton.state = .off
  54. } else if _type == .fromFile {
  55. self.createButton.state = .off
  56. self.createFileButton.state = .on
  57. }
  58. }
  59. get {
  60. return _type;
  61. }
  62. }
  63. func localizedLanguage() {
  64. self.configureLabel.stringValue = NSLocalizedString("Configure a Digital ID for Signing", comment: "")
  65. self.selectLabel.stringValue = NSLocalizedString("Select the type of Digital ID:", comment: "")
  66. self.fileLabel.stringValue = NSLocalizedString("Use a Digital ID from a File", comment: "")
  67. self.fileSubLabel.stringValue = NSLocalizedString("Import an existing digital ID that you have obtained as a file", comment: "")
  68. self.creatLabel.stringValue = NSLocalizedString("Create a New Digital ID", comment: "")
  69. self.creatSubLabel.stringValue = NSLocalizedString("Create your self-signed digital ID", comment: "")
  70. self.promptTextView.string = String(format:"%@\n\n%@",NSLocalizedString("A digital ID is required to create a digital signature.The most secure digital ID are issued by trusted Certificate authorities and are based on secure devices like smart card or token. Some are based on files.", comment: ""),NSLocalizedString("You can also create a new digital ID, but they provide a low level of identity assurance.", comment: ""))
  71. self.previousStepButton.title = NSLocalizedString("Previous Step", comment: "")
  72. self.continueButton.title = NSLocalizedString("Continue", comment: "")
  73. }
  74. //MARK: IBAction
  75. @IBAction func closeAction(_ sender: Any) {
  76. guard let callBack = self.actionBlock else {
  77. return
  78. }
  79. callBack(self, .cancel, self.type)
  80. }
  81. @IBAction func previousAction(_ sender: Any) {
  82. guard let callBack = self.actionBlock else {
  83. return
  84. }
  85. callBack(self, .previousStep, self.type)
  86. }
  87. @IBAction func continueAction(_ sender: Any) {
  88. guard let callBack = self.actionBlock else {
  89. return
  90. }
  91. callBack(self, .confirm, self.type)
  92. }
  93. @IBAction func buttonItemClick_CreatType(_ sender: Any) {
  94. let button: NSButton = sender as! NSButton
  95. if button.tag == 0 {
  96. self.type = .fromFile
  97. } else if button.tag == 1 {
  98. self.type = .signCreate
  99. }
  100. }
  101. }