KMBatchSecurityView.swift 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. //
  2. // KMBatchSecurityView.swift
  3. // PDF Master
  4. //
  5. // Created by lizhe on 2023/1/16.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class KMBatchSecurityView: KMBatchSettingItemView {
  10. @IBOutlet weak var titleLabel: NSTextField!
  11. @IBOutlet weak var titleContentView: NSView!
  12. // @IBOutlet weak var titleLabel: NSTextField!
  13. // @IBOutlet weak var openPasswordButton: KMImageTitleButton!
  14. //
  15. // @IBOutlet weak var openPasswordTextFieldContentView: NSView!
  16. //// @IBOutlet weak var openPasswordTextField: FocusAwareSecureTextField!
  17. // @IBOutlet weak var permissionButton: KMImageTitleButton!
  18. //
  19. // @IBOutlet weak var permissionTextFieldContentView: NSView!
  20. //// @IBOutlet weak var permissionTextfield: FocusAwareSecureTextField!
  21. // @IBOutlet weak var documentPrintButton: KMImageTitleButton!
  22. // @IBOutlet weak var contentCopyButton: KMImageTitleButton!
  23. @IBOutlet weak var encryptButton: NSButton!
  24. var data: KMBatchSecurityViewModel = KMBatchSecurityViewModel()
  25. var presenter: KMBatchSecurityViewPresenter = KMBatchSecurityViewPresenter()
  26. override func draw(_ dirtyRect: NSRect) {
  27. super.draw(dirtyRect)
  28. // Drawing code here.
  29. }
  30. override func setup() {
  31. super.setup()
  32. self.titleContentView.border(ComponentLibrary.shared.getComponentColorFromKey("colorBorder/divider"), 0.5, 0)
  33. self.presenter.initPresenter(view: self)
  34. // self.openPasswordButton.title = NSLocalizedString("Document Open Password", comment: "")
  35. // self.openPasswordButton.imageName = "btn_checkbox_unsel_on"
  36. // self.openPasswordButton.action = { [unowned self] (view, button) in
  37. // self.presenter.openPasswordButtonAction(sender: button)
  38. // }
  39. //
  40. // self.permissionButton.title = NSLocalizedString("Document Permission Password", comment: "")
  41. // self.permissionButton.imageName = "btn_checkbox_unsel_on"
  42. // self.permissionButton.action = { [unowned self] (view, button) in
  43. // self.presenter.permissionButtonAction(sender: button)
  44. // }
  45. //
  46. // //
  47. // self.openPasswordTextFieldContentView.border()
  48. // self.openPasswordTextFieldContentView.backgroundColor(NSColor.km_init(hex: "#FFFFFF"))
  49. // //
  50. //// self.openPasswordTextField.placeholderAttributedString = NSAttributedString.init(string: "Open Password", attributes: [NSAttributedString.Key.font: NSFont.SFProTextRegularFont(14), NSAttributedString.Key.foregroundColor: NSColor.km_init(hex: "#94989C")])
  51. //// self.openPasswordTextField.textColor = NSColor.km_init(hex: "#252629")
  52. //// self.openPasswordTextField.font = NSFont.SFProTextRegularFont(14.0)
  53. // //
  54. // self.permissionTextFieldContentView.border()
  55. // self.permissionTextFieldContentView.backgroundColor(NSColor.km_init(hex: "#FFFFFF"))
  56. // //
  57. //// self.permissionTextfield.placeholderAttributedString = NSAttributedString.init(string: "Permission Password", attributes: [NSAttributedString.Key.font: NSFont.SFProTextRegularFont(14), NSAttributedString.Key.foregroundColor: NSColor.km_init(hex: "#94989C")])
  58. //// self.permissionTextfield.textColor = NSColor.km_init(hex: "#252629")
  59. //// self.permissionTextfield.font = NSFont.SFProTextRegularFont(14.0)
  60. // //
  61. // self.documentPrintButton.title = NSLocalizedString("Restrict document printing", comment: "")
  62. // self.documentPrintButton.imageName = "btn_checkbox_unsel_on"
  63. // self.documentPrintButton.action = { [unowned self] (view, button) in
  64. // self.presenter.documentPrintButtonAction(sender: button)
  65. // }
  66. //
  67. // self.contentCopyButton.title = NSLocalizedString("Restrict content copying", comment: "")
  68. // self.contentCopyButton.imageName = "btn_checkbox_unsel_on"
  69. // self.contentCopyButton.action = { [unowned self] (view, button) in
  70. // self.presenter.contentCopyButtonAction(sender: button)
  71. // }
  72. // self.titleLabel.textColor = NSColor.km_init(hex: "#252629")
  73. // self.titleLabel.stringValue = NSLocalizedString("Settings", comment: "")
  74. // self.titleLabel.font = NSFont.SFProTextRegularFont(16.0)
  75. self.encryptButton.wantsLayer = true
  76. self.encryptButton.layer?.cornerRadius = 4
  77. self.encryptButton.contentTintColor = NSColor.km_init(hex: "#FFFFFF")
  78. self.encryptButton.stringValue = NSLocalizedString("Compress", comment: "")
  79. self.encryptButton.font = NSFont.SFProTextRegularFont(14.0)
  80. self.encryptButton.layer?.backgroundColor = NSColor.km_init(hex: "#BDDFFD").cgColor
  81. // self.openPasswordButton.titleLabel.textColor = NSColor.km_init(hex: "#252629")
  82. // self.openPasswordButton.titleLabel.font = NSFont.SFProTextRegularFont(14.0)
  83. // self.permissionButton.titleLabel.textColor = NSColor.km_init(hex: "#252629")
  84. // self.permissionButton.titleLabel.font = NSFont.SFProTextRegularFont(14.0)
  85. //
  86. // self.documentPrintButton.titleLabel.textColor = NSColor.km_init(hex: "#252629")
  87. // self.documentPrintButton.titleLabel.font = NSFont.SFProTextRegularFont(14.0)
  88. //
  89. // self.contentCopyButton.titleLabel.textColor = NSColor.km_init(hex: "#252629")
  90. // self.contentCopyButton.titleLabel.font = NSFont.SFProTextRegularFont(14.0)
  91. }
  92. override func reloadData() {
  93. // if data.isOpenPassword {
  94. // self.openPasswordButton.imageName = "btn_checkbox_sel_on"
  95. //// self.openPasswordTextField.isEnabled = true
  96. // } else {
  97. // self.openPasswordButton.imageName = "btn_checkbox_unsel_on"
  98. //// self.openPasswordTextField.isEnabled = false
  99. // }
  100. //
  101. // if data.isPermission {
  102. // self.permissionButton.imageName = "btn_checkbox_sel_on"
  103. //// self.permissionTextfield.isEnabled = true
  104. // self.documentPrintButton.isEnabled = true
  105. // self.contentCopyButton.isEnabled = true
  106. // } else {
  107. // self.permissionButton.imageName = "btn_checkbox_unsel_on"
  108. //// self.permissionTextfield.isEnabled = false
  109. // self.documentPrintButton.isEnabled = false
  110. // self.contentCopyButton.isEnabled = false
  111. // }
  112. //
  113. // if data.restrictOptions.contains(.print) {
  114. // self.documentPrintButton.imageName = "btn_checkbox_sel_on"
  115. // } else {
  116. // self.documentPrintButton.imageName = "btn_checkbox_unsel_on"
  117. // }
  118. //
  119. // if data.restrictOptions.contains(.copy) {
  120. // self.contentCopyButton.imageName = "btn_checkbox_sel_on"
  121. // } else {
  122. // self.contentCopyButton.imageName = "btn_checkbox_unsel_on"
  123. // }
  124. if (self.filesData.count != 0) {
  125. self.encryptButton.layer?.backgroundColor = NSColor.km_init(hex: "#1770F4").cgColor
  126. self.encryptButton.isEnabled = true
  127. } else {
  128. self.encryptButton.layer?.backgroundColor = NSColor.km_init(hex: "#BDDFFD").cgColor
  129. self.encryptButton.isEnabled = false
  130. }
  131. }
  132. }
  133. protocol KMBatchSecurityViewAction { }
  134. extension KMBatchSecurityView: KMBatchCompressViewAction {
  135. @IBAction func encryptButtonAction(_ sender: NSButton) {
  136. // guard self.presenter.changePermissionString(self.permissionTextfield.stringValue) else {
  137. // return
  138. // }
  139. // guard self.presenter.changeOpenPasswordString(self.openPasswordTextField.stringValue) else {
  140. // return
  141. // }
  142. if self.batchExport != nil {
  143. self.batchExport!(self, self.data)
  144. }
  145. }
  146. }
  147. extension KMBatchSecurityView: KMBatchSecurityViewPresenterDelegate {
  148. func showData(presenter: KMBatchSecurityViewPresenter, data: KMBatchSecurityViewModel) {
  149. self.data = data
  150. self.reloadData()
  151. }
  152. }
  153. //class FocusAwareSecureTextField: NSSecureTextField {
  154. // var onFocus: () -> Void = {}
  155. // var onUnfocus: () -> Void = {}
  156. //
  157. // override func becomeFirstResponder() -> Bool {
  158. // onFocus()
  159. // let textView = window?.fieldEditor(true, for: nil) as? NSTextView
  160. // textView?.insertionPointColor = NSColor.km_init(hex: "#252629")
  161. // return super.becomeFirstResponder()
  162. // }
  163. //
  164. // override func resignFirstResponder() -> Bool {
  165. // onUnfocus()
  166. // return super.resignFirstResponder()
  167. // }
  168. //}