KMBotaSearchViewController.swift 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. var contentView: NSView? {
  12. didSet {
  13. if let view = self.contentView {
  14. self.box.contentView = view
  15. }
  16. }
  17. }
  18. @IBOutlet weak var emptyBox: NSBox!
  19. @IBOutlet weak var searchBox: KMBox!
  20. @IBOutlet weak var searchResultsView: NSView!
  21. @IBOutlet weak var searchResultsLabel: NSTextField!
  22. @IBOutlet weak var searchDomeButton: NSButton!
  23. @IBOutlet weak var box: NSBox!
  24. @IBOutlet weak var emptySearchLabel: NSTextField!
  25. @IBOutlet weak var searchLabel: NSTextField!
  26. @IBOutlet weak var searchTips: NSTextField!
  27. @IBOutlet weak var pageLabel: NSTextField!
  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.searchDomeButton.hidden = YES;
  52. self.searchField.wantsLayer = true
  53. // self.searchField.layer.backgroundColor = [KMAppearance KMColor_Layout_L1].CGColor;
  54. self.searchField.layer?.cornerRadius = 1.0
  55. self.searchField.layer?.borderWidth = 1.0
  56. self.searchField.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
  57. self.searchBox.fillColor = KMAppearance.Interactive.s0Color()
  58. // self.searchField.hidden = YES;
  59. self.searchBox.downCallback = { [unowned self] downEntered, box, _ in
  60. if (downEntered) {
  61. self.searchField.isHidden = false
  62. self.searchDomeButton.isHidden = false
  63. self.searchBox.isHidden = true
  64. self.searchField.becomeFirstResponder()
  65. }
  66. }
  67. self.searchBox.isHidden = true
  68. }
  69. override func viewDidLoad() {
  70. super.viewDidLoad()
  71. // Do view setup here.
  72. }
  73. override func viewDidAppear() {
  74. super.viewDidAppear()
  75. self.searchField.becomeFirstResponder()
  76. self.updateViewColor()
  77. DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChanged), name: NSApplication.interfaceThemeChangedNotification, object: nil)
  78. }
  79. func updateViewColor() {
  80. if (KMAppearance.isDarkMode()) {
  81. self.searchField.layer?.backgroundColor = NSColor(red: 57.0/255.0, green: 60.0/255.0, blue: 62.0/255.0, alpha: 1).cgColor
  82. } else {
  83. self.searchField.layer?.backgroundColor = .white
  84. }
  85. }
  86. @objc func themeChanged(_ notification: NSNotification) {
  87. DispatchQueue.main.asyncAfter(deadline: .now()+0.3) {
  88. self.updateViewColor()
  89. }
  90. }
  91. @IBAction func searchDomeButtonAtion(_ sender: AnyObject) {
  92. self.searchField.isHidden = true
  93. self.searchDomeButton.isHidden = true
  94. self.searchBox.isHidden = false
  95. }
  96. }