KMPropertiesViewPopController.swift 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // KMPropertiesViewPopController.swift
  3. // PDF Master
  4. //
  5. // Created by lizhe on 2023/10/12.
  6. //
  7. import Cocoa
  8. @objcMembers class KMPropertiesViewPopController: NSViewController {
  9. @IBOutlet var titleLabel: NSTextField!
  10. @IBOutlet var titlesubLabel: NSTextField!
  11. @IBOutlet var closeBtn: NSButton!
  12. var popOver: NSPopover?
  13. var block: (() -> Void)?
  14. class func defaultManager() -> KMPropertiesViewPopController {
  15. let singleton = KMPropertiesViewPopController()
  16. return singleton
  17. }
  18. class func showChangeColorDetails() -> Bool {
  19. let isOpenConvertDetails = UserDefaults.standard.bool(forKey: "KMPropertiesHaveChangeColorDetails")
  20. if !isOpenConvertDetails {
  21. return true
  22. }
  23. return false
  24. }
  25. func showChangeColorDetailsView(_ view: NSView) {
  26. let popViewController = KMPropertiesViewPopController()
  27. popViewController.block = { [unowned self] in
  28. self.popOver?.close()
  29. }
  30. self.popOver = NSPopover()
  31. self.popOver?.contentViewController = popViewController
  32. self.popOver?.animates = false
  33. self.popOver?.behavior = .transient
  34. // self.popOver?.appearance = .minimal
  35. self.popOver?.contentSize = popViewController.view.frame.size
  36. DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
  37. if view.superview?.window == nil {
  38. return
  39. }
  40. UserDefaults.standard.set(true, forKey: "KMPropertiesHaveChangeColorDetails")
  41. UserDefaults.standard.synchronize()
  42. self.popOver?.show(relativeTo: view.bounds, of: view, preferredEdge: .maxY)
  43. }
  44. }
  45. override func viewDidLoad() {
  46. super.viewDidLoad()
  47. view.wantsLayer = true
  48. view.layer?.backgroundColor = NSColor.gray.cgColor
  49. titleLabel.stringValue = NSLocalizedString("Customize colors", comment: "")
  50. titlesubLabel.stringValue = NSLocalizedString("Right click a color and select \"Change Color...\".", comment: "")
  51. closeBtn.title = NSLocalizedString("Close", comment: "")
  52. closeBtn.wantsLayer = true
  53. closeBtn.layer?.cornerRadius = 1.0
  54. closeBtn.layer?.backgroundColor = NSColor.gray.cgColor
  55. closeBtn.contentTintColor = NSColor.white
  56. }
  57. @IBAction func buttonItemClick_Close(_ sender: Any) {
  58. block?()
  59. block = nil
  60. }
  61. }