KMSavePanelAccessoryController.swift 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //
  2. // KMSavePanelAccessoryController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by wanjun on 2023/10/10.
  6. //
  7. import Cocoa
  8. private let KMAutoOpenDocumentKey = "KMAutoOpenDocumentKey"
  9. @objcMembers
  10. class KMSavePanelAccessoryController: NSViewController {
  11. @IBOutlet weak var openAutomaticButton: NSButton!
  12. var _needOpen: Bool = false
  13. override init(nibName nibNameOrNil: NSNib.Name?, bundle nibBundleOrNil: Bundle?) {
  14. super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
  15. }
  16. required init?(coder: NSCoder) {
  17. super.init(coder: coder)
  18. }
  19. override func awakeFromNib() {
  20. super.awakeFromNib()
  21. openAutomaticButton.title = NSLocalizedString("Open the document after saving", comment: "")
  22. let autoOpen = KMDataManager.ud_bool(forKey: KMAutoOpenDocumentKey)
  23. openAutomaticButton.state = autoOpen ? .on : .off
  24. _needOpen = autoOpen
  25. }
  26. @IBAction func buttonClickedOpenAutomatic(_ sender: NSButton) {
  27. _needOpen = sender.state == NSControl.StateValue.on
  28. KMDataManager.ud_set(_needOpen, forKey: KMAutoOpenDocumentKey)
  29. }
  30. //MARK: Get、Set
  31. var needOpen: Bool {
  32. return _needOpen
  33. }
  34. }