KMNBaseWindowController.swift 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // KMNBaseWindowController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2023/5/11.
  6. //
  7. import Cocoa
  8. class KMNBaseWindowController: NSWindowController {
  9. public var parentWindow: NSWindow?
  10. public var handler: ((String?) -> Void)!
  11. deinit {
  12. KMPrint(self.className + " deinit.")
  13. self.removeNotification()
  14. }
  15. override func windowDidLoad() {
  16. super.windowDidLoad()
  17. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  18. self.initContentView()
  19. self.initNotification()
  20. }
  21. func initNotification() {
  22. updateUIThemeColor()
  23. NotificationCenter.default.addObserver(self, selector: #selector(updateUIThemeColor), name: APPAppearanceChangedNotificationName, object: nil)
  24. updateUILanguage()
  25. NotificationCenter.default.addObserver(self, selector: #selector(updateUILanguage), name: APPLanguageChangedNotificationName, object: nil)
  26. }
  27. func removeNotification() {
  28. DistributedNotificationCenter.default().removeObserver(self)
  29. }
  30. @objc func updateUIThemeColor() {}
  31. @objc func updateUILanguage() {}
  32. func beginSheetFinish() {}
  33. func initContentView() {}
  34. func own_beginSheetModal(for window: NSWindow?, completionHandler handler: ((String?) -> Void)?) {
  35. if window != nil {
  36. parentWindow = window
  37. window!.beginSheet(self.window!) { ModalResponse in
  38. self.handler?(nil)
  39. }
  40. }
  41. self.handler = handler
  42. beginSheetFinish()
  43. }
  44. func own_closeEndSheet() {
  45. parentWindow?.endSheet(self.window!)
  46. }
  47. }