123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- //
- // KMBatchSecurityView.swift
- // PDF Master
- //
- // Created by lizhe on 2023/1/16.
- //
- import Cocoa
- import KMComponentLibrary
- class KMBatchSecurityView: KMBatchSettingItemView {
- @IBOutlet weak var titleLabel: NSTextField!
- @IBOutlet weak var titleContentView: NSView!
- // @IBOutlet weak var titleLabel: NSTextField!
- // @IBOutlet weak var openPasswordButton: KMImageTitleButton!
- //
- // @IBOutlet weak var openPasswordTextFieldContentView: NSView!
- //// @IBOutlet weak var openPasswordTextField: FocusAwareSecureTextField!
- // @IBOutlet weak var permissionButton: KMImageTitleButton!
- //
- // @IBOutlet weak var permissionTextFieldContentView: NSView!
- //// @IBOutlet weak var permissionTextfield: FocusAwareSecureTextField!
- // @IBOutlet weak var documentPrintButton: KMImageTitleButton!
- // @IBOutlet weak var contentCopyButton: KMImageTitleButton!
-
- @IBOutlet weak var encryptButton: NSButton!
-
- var data: KMBatchSecurityViewModel = KMBatchSecurityViewModel()
- var presenter: KMBatchSecurityViewPresenter = KMBatchSecurityViewPresenter()
-
- override func draw(_ dirtyRect: NSRect) {
- super.draw(dirtyRect)
- // Drawing code here.
- }
-
- override func setup() {
- super.setup()
-
- self.titleContentView.border(ComponentLibrary.shared.getComponentColorFromKey("colorBorder/divider"), 0.5, 0)
-
- self.presenter.initPresenter(view: self)
-
- // self.openPasswordButton.title = NSLocalizedString("Document Open Password", comment: "")
- // self.openPasswordButton.imageName = "btn_checkbox_unsel_on"
- // self.openPasswordButton.action = { [unowned self] (view, button) in
- // self.presenter.openPasswordButtonAction(sender: button)
- // }
- //
- // self.permissionButton.title = NSLocalizedString("Document Permission Password", comment: "")
- // self.permissionButton.imageName = "btn_checkbox_unsel_on"
- // self.permissionButton.action = { [unowned self] (view, button) in
- // self.presenter.permissionButtonAction(sender: button)
- // }
- //
- // //
- // self.openPasswordTextFieldContentView.border()
- // self.openPasswordTextFieldContentView.backgroundColor(NSColor.km_init(hex: "#FFFFFF"))
- // //
- //// self.openPasswordTextField.placeholderAttributedString = NSAttributedString.init(string: "Open Password", attributes: [NSAttributedString.Key.font: NSFont.SFProTextRegularFont(14), NSAttributedString.Key.foregroundColor: NSColor.km_init(hex: "#94989C")])
- //// self.openPasswordTextField.textColor = NSColor.km_init(hex: "#252629")
- //// self.openPasswordTextField.font = NSFont.SFProTextRegularFont(14.0)
- // //
- // self.permissionTextFieldContentView.border()
- // self.permissionTextFieldContentView.backgroundColor(NSColor.km_init(hex: "#FFFFFF"))
- // //
- //// self.permissionTextfield.placeholderAttributedString = NSAttributedString.init(string: "Permission Password", attributes: [NSAttributedString.Key.font: NSFont.SFProTextRegularFont(14), NSAttributedString.Key.foregroundColor: NSColor.km_init(hex: "#94989C")])
- //// self.permissionTextfield.textColor = NSColor.km_init(hex: "#252629")
- //// self.permissionTextfield.font = NSFont.SFProTextRegularFont(14.0)
- // //
- // self.documentPrintButton.title = NSLocalizedString("Restrict document printing", comment: "")
- // self.documentPrintButton.imageName = "btn_checkbox_unsel_on"
- // self.documentPrintButton.action = { [unowned self] (view, button) in
- // self.presenter.documentPrintButtonAction(sender: button)
- // }
- //
- // self.contentCopyButton.title = NSLocalizedString("Restrict content copying", comment: "")
- // self.contentCopyButton.imageName = "btn_checkbox_unsel_on"
- // self.contentCopyButton.action = { [unowned self] (view, button) in
- // self.presenter.contentCopyButtonAction(sender: button)
- // }
-
- // self.titleLabel.textColor = NSColor.km_init(hex: "#252629")
- // self.titleLabel.stringValue = NSLocalizedString("Settings", comment: "")
- // self.titleLabel.font = NSFont.SFProTextRegularFont(16.0)
-
- self.encryptButton.wantsLayer = true
- self.encryptButton.layer?.cornerRadius = 4
- self.encryptButton.contentTintColor = NSColor.km_init(hex: "#FFFFFF")
- self.encryptButton.stringValue = NSLocalizedString("Compress", comment: "")
- self.encryptButton.font = NSFont.SFProTextRegularFont(14.0)
- self.encryptButton.layer?.backgroundColor = NSColor.km_init(hex: "#BDDFFD").cgColor
-
- // self.openPasswordButton.titleLabel.textColor = NSColor.km_init(hex: "#252629")
- // self.openPasswordButton.titleLabel.font = NSFont.SFProTextRegularFont(14.0)
-
- // self.permissionButton.titleLabel.textColor = NSColor.km_init(hex: "#252629")
- // self.permissionButton.titleLabel.font = NSFont.SFProTextRegularFont(14.0)
- //
- // self.documentPrintButton.titleLabel.textColor = NSColor.km_init(hex: "#252629")
- // self.documentPrintButton.titleLabel.font = NSFont.SFProTextRegularFont(14.0)
- //
- // self.contentCopyButton.titleLabel.textColor = NSColor.km_init(hex: "#252629")
- // self.contentCopyButton.titleLabel.font = NSFont.SFProTextRegularFont(14.0)
- }
-
- override func reloadData() {
-
- // if data.isOpenPassword {
- // self.openPasswordButton.imageName = "btn_checkbox_sel_on"
- //// self.openPasswordTextField.isEnabled = true
- // } else {
- // self.openPasswordButton.imageName = "btn_checkbox_unsel_on"
- //// self.openPasswordTextField.isEnabled = false
- // }
- //
- // if data.isPermission {
- // self.permissionButton.imageName = "btn_checkbox_sel_on"
- //// self.permissionTextfield.isEnabled = true
- // self.documentPrintButton.isEnabled = true
- // self.contentCopyButton.isEnabled = true
- // } else {
- // self.permissionButton.imageName = "btn_checkbox_unsel_on"
- //// self.permissionTextfield.isEnabled = false
- // self.documentPrintButton.isEnabled = false
- // self.contentCopyButton.isEnabled = false
- // }
- //
- // if data.restrictOptions.contains(.print) {
- // self.documentPrintButton.imageName = "btn_checkbox_sel_on"
- // } else {
- // self.documentPrintButton.imageName = "btn_checkbox_unsel_on"
- // }
- //
- // if data.restrictOptions.contains(.copy) {
- // self.contentCopyButton.imageName = "btn_checkbox_sel_on"
- // } else {
- // self.contentCopyButton.imageName = "btn_checkbox_unsel_on"
- // }
-
- if (self.filesData.count != 0) {
- self.encryptButton.layer?.backgroundColor = NSColor.km_init(hex: "#1770F4").cgColor
- self.encryptButton.isEnabled = true
- } else {
- self.encryptButton.layer?.backgroundColor = NSColor.km_init(hex: "#BDDFFD").cgColor
- self.encryptButton.isEnabled = false
- }
- }
- }
- protocol KMBatchSecurityViewAction { }
- extension KMBatchSecurityView: KMBatchCompressViewAction {
- @IBAction func encryptButtonAction(_ sender: NSButton) {
- // guard self.presenter.changePermissionString(self.permissionTextfield.stringValue) else {
- // return
- // }
-
- // guard self.presenter.changeOpenPasswordString(self.openPasswordTextField.stringValue) else {
- // return
- // }
-
- if self.batchExport != nil {
- self.batchExport!(self, self.data)
- }
- }
- }
- extension KMBatchSecurityView: KMBatchSecurityViewPresenterDelegate {
- func showData(presenter: KMBatchSecurityViewPresenter, data: KMBatchSecurityViewModel) {
- self.data = data
- self.reloadData()
- }
- }
- //class FocusAwareSecureTextField: NSSecureTextField {
- // var onFocus: () -> Void = {}
- // var onUnfocus: () -> Void = {}
- //
- // override func becomeFirstResponder() -> Bool {
- // onFocus()
- // let textView = window?.fieldEditor(true, for: nil) as? NSTextView
- // textView?.insertionPointColor = NSColor.km_init(hex: "#252629")
- // return super.becomeFirstResponder()
- // }
- //
- // override func resignFirstResponder() -> Bool {
- // onUnfocus()
- // return super.resignFirstResponder()
- // }
- //}
|