KMTabbingHintWindowController.swift 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // KMTabbingHintWindowController.swift
  3. // Cisdem PDFMaster
  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. KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
  65. }
  66. @IBAction func buttonClicked_NewWindow(_ sender: NSButton) {
  67. sender.state = NSControl.StateValue.on;
  68. }
  69. @IBAction func buttonClicked_DonotHintAgain(_ sender: NSButton) {
  70. }
  71. @IBAction func buttonClicked_Cancel(_ sender: NSButton) {
  72. self.km_quick_endSheet()
  73. if let callback = self.selectCallBack {
  74. callback(false)
  75. }
  76. }
  77. @IBAction func buttonClicked_Done(_ sender: NSButton) {
  78. UserDefaults.standard.set(self.notShowAgainButton.state, forKey: KMTabbingHintShowFlag)
  79. UserDefaults.standard.synchronize()
  80. self.km_quick_endSheet()
  81. if let callback = self.selectCallBack {
  82. callback(true)
  83. }
  84. }
  85. }