KMPropertiesViewPopController.swift 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // KMPropertiesViewPopController.swift
  3. // PDF Reader Pro
  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 guideInfoWindowController: KMGuideInfoWindowController?
  13. var popOver: NSPopover?
  14. var block: (() -> Void)?
  15. // class func defaultManager() -> KMPropertiesViewPopController {
  16. // let singleton = KMPropertiesViewPopController()
  17. // return singleton
  18. // }
  19. static let defaultManager = KMPropertiesViewPopController()
  20. class func showChangeColorDetails() -> Bool {
  21. // let isOpenConvertDetails = UserDefaults.standard.bool(forKey: "KMPropertiesHaveChangeColorDetails")
  22. // if !isOpenConvertDetails {
  23. return true
  24. // }
  25. // return false
  26. }
  27. func showChangeColorDetailsView(_ view: NSView) {
  28. DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
  29. if KMGuideInfoWindowController.availableShow(.customColor) {
  30. self.guideInfoWindowController = KMGuideInfoWindowController.currentWC()
  31. guard let guideWC = self.guideInfoWindowController else { return }
  32. guideWC.type = .customColor
  33. guideWC.digitalBoxRect = view.superview?.convert(view.frame, to: view.window?.contentView) ?? .zero
  34. if NSLocalizedString("Right click a color and select “Change Color...“.", comment: "") == "انقر بزر الماوس الأيمن فوق اللون وحدد \"تغيير اللون...\"." {
  35. // 阿拉伯语适配
  36. var frame = guideWC.digitalBoxRect
  37. let offset: CGFloat = 15
  38. let winFrame = view.window?.frame ?? .zero
  39. frame.origin.x = winFrame.size.width - frame.origin.x - offset
  40. guideWC.digitalBoxRect = frame
  41. }
  42. var beh = view.window?.collectionBehavior ?? []
  43. beh.insert(.canJoinAllSpaces)
  44. guideWC.window?.collectionBehavior = beh
  45. var rect = view.window?.frame ?? .zero
  46. rect.size.height -= 20
  47. guideWC.window?.setFrame(rect, display: false)
  48. guideWC.window?.minSize = rect.size
  49. guideWC.window?.maxSize = rect.size
  50. view.window?.addChildWindow(guideWC.window!, ordered: .above)
  51. guideWC.show()
  52. }
  53. }
  54. }
  55. override func viewDidLoad() {
  56. super.viewDidLoad()
  57. view.wantsLayer = true
  58. view.layer?.backgroundColor = NSColor.gray.cgColor
  59. titleLabel.stringValue = NSLocalizedString("Customize colors", comment: "")
  60. titlesubLabel.stringValue = NSLocalizedString("Right click a color and select \"Change Color...\".", comment: "")
  61. closeBtn.title = NSLocalizedString("Close", comment: "")
  62. closeBtn.wantsLayer = true
  63. closeBtn.layer?.cornerRadius = 1.0
  64. closeBtn.layer?.backgroundColor = NSColor.gray.cgColor
  65. closeBtn.contentTintColor = NSColor.white
  66. }
  67. @IBAction func buttonItemClick_Close(_ sender: Any) {
  68. block?()
  69. block = nil
  70. }
  71. }