KMTabbingHintWindowController.swift 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // KMTabbingHintWindowController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by liujiajie on 2/28/24.
  6. //
  7. import Cocoa
  8. typealias homeClickedTabbingShowBlock = (_ continueOrNot: Bool) -> Void
  9. let KMTabbingHintShowFlag = "KMTabbingHintShowFlag"
  10. class KMTabbingHintWindowController: NSWindowController{
  11. @IBOutlet var hintLabel: NSTextField!
  12. @IBOutlet var newTabInWindowButton: NSButton!
  13. @IBOutlet var newWindowButton: NSButton!
  14. @IBOutlet var notShowAgainButton: NSButton!
  15. @IBOutlet var gapView: NSView!
  16. @IBOutlet var cancelButton: NSButton!
  17. @IBOutlet var doneButton: NSButton!
  18. var selectCallBack: homeClickedTabbingShowBlock?
  19. convenience init() {
  20. self.init(windowNibName: "KMTabbingHintWindowController")
  21. }
  22. override func windowDidLoad() {
  23. super.windowDidLoad()
  24. localiedLanguage()
  25. configuViewsUI()
  26. }
  27. func localiedLanguage() {
  28. hintLabel.stringValue = String(format: "%@:", NSLocalizedString("Open a document in", comment: ""))
  29. newTabInWindowButton.title = NSLocalizedString("a new tab in the same window", comment: "")
  30. newWindowButton.title = NSLocalizedString("a new window", comment: "")
  31. notShowAgainButton.title = NSLocalizedString("No longer prompt", comment: "")
  32. cancelButton.title = NSLocalizedString("Cancel", comment: "")
  33. doneButton.title = NSLocalizedString("Done", comment: "")
  34. }
  35. func configuViewsUI() {
  36. hintLabel.font = NSFont.boldSystemFont(ofSize: 16)
  37. newTabInWindowButton.state = .off
  38. newWindowButton.state = .on
  39. notShowAgainButton.state = .off
  40. gapView.wantsLayer = true
  41. gapView.layer?.backgroundColor = NSColor(red: 218/255.0, green: 218/255.0, blue: 218/255.0, alpha: 1).cgColor
  42. window?.contentView?.wantsLayer = true
  43. var color = NSColor.white
  44. if #available(macOS 10.14, *) {
  45. if let appearanceName = NSApp.effectiveAppearance.bestMatch(from: [.aqua, .darkAqua]),
  46. appearanceName == .darkAqua {
  47. color = KMAppearance.viewBackgroundColor()
  48. }
  49. }
  50. color = NSColor(deviceRed: 74.0/255.0, green: 74.0/255.0, blue: 74.0/255.0, alpha: 1.0)
  51. if #available(macOS 10.14, *) {
  52. if let appearanceName = NSApp.effectiveAppearance.bestMatch(from: [.aqua, .darkAqua]),
  53. appearanceName == .darkAqua {
  54. color = NSColor(deviceRed: 1.0, green: 1.0, blue: 1.0, alpha: 0.7)
  55. }
  56. }
  57. hintLabel.textColor = color
  58. newTabInWindowButton?.setTitleColor(color)
  59. newWindowButton?.setTitleColor(color)
  60. notShowAgainButton?.setTitleColor(color)
  61. }
  62. @IBAction func buttonClicked_NewTabInWindowButton(_ sender: NSButton) {
  63. sender.state = NSControl.StateValue.off;
  64. let winC = KMPurchaseCompareWindowController.sharedInstance()
  65. winC?.kEventName = "Reading_MultiTab_BuyNow"
  66. winC?.showWindow(nil)
  67. }
  68. @IBAction func buttonClicked_NewWindow(_ sender: NSButton) {
  69. sender.state = NSControl.StateValue.on;
  70. }
  71. @IBAction func buttonClicked_DonotHintAgain(_ sender: NSButton) {
  72. }
  73. @IBAction func buttonClicked_Cancel(_ sender: NSButton) {
  74. self.km_quick_endSheet()
  75. if let callback = self.selectCallBack {
  76. callback(false)
  77. }
  78. }
  79. @IBAction func buttonClicked_Done(_ sender: NSButton) {
  80. UserDefaults.standard.set(self.notShowAgainButton.state, forKey: KMTabbingHintShowFlag)
  81. UserDefaults.standard.synchronize()
  82. self.km_quick_endSheet()
  83. if let callback = self.selectCallBack {
  84. callback(true)
  85. }
  86. }
  87. }