KMBotaSearchViewController.swift 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // KMBotaSearchViewController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2023/11/16.
  6. //
  7. import Cocoa
  8. class KMBotaSearchViewController: NSViewController {
  9. @IBOutlet weak var searchField: NSSearchField!
  10. @IBOutlet weak var segmentedControl: KMSegmentedControl!
  11. @IBOutlet weak var emptyBox: NSBox!
  12. @IBOutlet weak var searchBox: KMBox!
  13. @IBOutlet weak var searchResultsView: NSView!
  14. @IBOutlet weak var searchResultsLabel: NSTextField!
  15. @IBOutlet weak var searchDomeButton: NSButton!
  16. @IBOutlet weak var box: NSBox!
  17. @IBOutlet weak var emptySearchLabel: NSTextField!
  18. @IBOutlet weak var searchLabel: NSTextField!
  19. @IBOutlet weak var searchTips: NSTextField!
  20. @IBOutlet weak var pageLabel: NSTextField!
  21. var contentView: NSView? {
  22. didSet {
  23. if let view = self.contentView {
  24. self.box.contentView = view
  25. }
  26. }
  27. }
  28. deinit {
  29. KMPrint("KMBotaSearchViewController deinit.")
  30. NotificationCenter.default.removeObserver(self)
  31. }
  32. override func loadView() {
  33. super.loadView()
  34. self.emptySearchLabel.stringValue = KMLocalizedString("No Results",nil)
  35. self.emptySearchLabel.textColor = KMAppearance.Layout.h1Color()
  36. self.emptyBox.fillColor = KMAppearance.Layout.l0Color()
  37. self.searchLabel.stringValue = KMLocalizedString("Search", nil)
  38. self.searchLabel.textColor = KMAppearance.Layout.h0Color()
  39. self.searchTips.stringValue = KMLocalizedString("Search", nil)
  40. self.searchTips.textColor = KMAppearance.Layout.h2Color()
  41. self.searchResultsLabel.textColor = KMAppearance.Layout.h1Color()
  42. self.pageLabel.stringValue = KMLocalizedString("Page", nil)
  43. self.pageLabel.textColor = KMAppearance.Layout.h1Color()
  44. self.searchResultsView.isHidden = true
  45. self.searchDomeButton.title = KMLocalizedString("Done", nil)
  46. self.searchDomeButton.toolTip = KMLocalizedString("Done", nil)
  47. self.searchDomeButton.setTitleColor(KMAppearance.Layout.w0Color())
  48. self.searchDomeButton.wantsLayer = true
  49. self.searchDomeButton.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor
  50. self.searchDomeButton.layer?.cornerRadius = 4.0
  51. self.searchField.wantsLayer = true
  52. self.searchField.layer?.cornerRadius = 1.0
  53. self.searchField.layer?.borderWidth = 1.0
  54. self.searchField.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
  55. self.searchBox.fillColor = KMAppearance.Interactive.s0Color()
  56. self.searchBox.downCallback = { [unowned self] downEntered, box, _ in
  57. if (downEntered) {
  58. self.searchField.isHidden = false
  59. self.searchDomeButton.isHidden = false
  60. self.searchBox.isHidden = true
  61. self.searchField.becomeFirstResponder()
  62. }
  63. }
  64. self.searchBox.isHidden = true
  65. }
  66. override func viewDidLoad() {
  67. super.viewDidLoad()
  68. // Do view setup here.
  69. }
  70. override func viewDidAppear() {
  71. super.viewDidAppear()
  72. self.searchField.becomeFirstResponder()
  73. self.updateViewColor()
  74. DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChanged), name: NSApplication.interfaceThemeChangedNotification, object: nil)
  75. }
  76. func updateViewColor() {
  77. if (KMAppearance.isDarkMode()) {
  78. self.searchField.layer?.backgroundColor = NSColor(red: 57.0/255.0, green: 60.0/255.0, blue: 62.0/255.0, alpha: 1).cgColor
  79. } else {
  80. self.searchField.layer?.backgroundColor = .white
  81. }
  82. }
  83. @objc func themeChanged(_ notification: NSNotification) {
  84. DispatchQueue.main.asyncAfter(deadline: .now()+0.3) {
  85. self.updateViewColor()
  86. }
  87. }
  88. @IBAction func searchDomeButtonAtion(_ sender: AnyObject) {
  89. self.searchField.isHidden = true
  90. self.searchDomeButton.isHidden = true
  91. self.searchBox.isHidden = false
  92. }
  93. }