KMToolbarCustomWindowController.swift 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //
  2. // KMToolbarCustomWindowController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2023/10/26.
  6. //
  7. import Cocoa
  8. class KMToolbarCustomWindowController: NSWindowController {
  9. weak var toolbar: KMToolbarView?
  10. var toolbarCustomViewController: KMToolbarCustomViewController?
  11. var resetCallback: KMEmptyBlock?
  12. deinit {
  13. Swift.debugPrint("KMToolbarCustomWindowController deinit")
  14. }
  15. convenience init() {
  16. self.init(windowNibName: "KMToolbarCustomWindowController")
  17. }
  18. override func windowDidLoad() {
  19. super.windowDidLoad()
  20. self.toolbarCustomViewController = KMToolbarCustomViewController()
  21. self.toolbarCustomViewController?.toolbar = self.toolbar
  22. if self.responds(to: NSSelectorFromString("setContentViewController:")) {
  23. self.contentViewController = self.toolbarCustomViewController
  24. } else {
  25. self.toolbarCustomViewController?.view.frame = self.window?.contentView?.bounds ?? .zero
  26. if let sview = self.toolbarCustomViewController?.view {
  27. self.window?.contentView?.addSubview(sview)
  28. }
  29. }
  30. self.toolbarCustomViewController?.itemClick = { [weak self] idx, _ in
  31. if idx == 0 { // cancel
  32. self?.km_quick_endSheet(.cancel)
  33. } else if idx == 1 { // ok
  34. self?.km_quick_endSheet(.OK)
  35. } else if idx == 2 { // reset
  36. self?.resetCallback?()
  37. }
  38. }
  39. }
  40. }