// // KMBotaSearchViewController.swift // PDF Reader Pro // // Created by tangchao on 2023/11/16. // import Cocoa class KMBotaSearchViewController: NSViewController { @IBOutlet weak var searchField: NSSearchField! @IBOutlet weak var segmentedControl: KMSegmentedControl! @IBOutlet weak var emptyBox: NSBox! @IBOutlet weak var searchBox: KMBox! @IBOutlet weak var searchResultsView: NSView! @IBOutlet weak var searchResultsLabel: NSTextField! @IBOutlet weak var searchDomeButton: NSButton! @IBOutlet weak var box: NSBox! @IBOutlet weak var emptySearchLabel: NSTextField! @IBOutlet weak var searchLabel: NSTextField! @IBOutlet weak var searchTips: NSTextField! @IBOutlet weak var pageLabel: NSTextField! var contentView: NSView? { didSet { if let view = self.contentView { self.box.contentView = view } } } deinit { KMPrint("KMBotaSearchViewController deinit.") NotificationCenter.default.removeObserver(self) } override func loadView() { super.loadView() self.emptySearchLabel.stringValue = KMLocalizedString("No Results",nil) self.emptySearchLabel.textColor = KMAppearance.Layout.h1Color() self.emptyBox.fillColor = KMAppearance.Layout.l0Color() self.searchLabel.stringValue = KMLocalizedString("Search", nil) self.searchLabel.textColor = KMAppearance.Layout.h0Color() self.searchTips.stringValue = KMLocalizedString("Search", nil) self.searchTips.textColor = KMAppearance.Layout.h2Color() self.searchResultsLabel.textColor = KMAppearance.Layout.h1Color() self.pageLabel.stringValue = KMLocalizedString("Page", nil) self.pageLabel.textColor = KMAppearance.Layout.h1Color() self.searchResultsView.isHidden = true self.searchDomeButton.title = KMLocalizedString("Done", nil) self.searchDomeButton.toolTip = KMLocalizedString("Done", nil) self.searchDomeButton.setTitleColor(KMAppearance.Layout.w0Color()) self.searchDomeButton.wantsLayer = true self.searchDomeButton.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor self.searchDomeButton.layer?.cornerRadius = 4.0 self.searchField.wantsLayer = true self.searchField.layer?.cornerRadius = 1.0 self.searchField.layer?.borderWidth = 1.0 self.searchField.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor self.searchBox.fillColor = KMAppearance.Interactive.s0Color() self.searchBox.downCallback = { [unowned self] downEntered, box, _ in if (downEntered) { self.searchField.isHidden = false self.searchDomeButton.isHidden = false self.searchBox.isHidden = true self.searchField.becomeFirstResponder() } } self.searchBox.isHidden = true } override func viewDidLoad() { super.viewDidLoad() // Do view setup here. } override func viewDidAppear() { super.viewDidAppear() self.searchField.becomeFirstResponder() self.updateViewColor() DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChanged), name: NSApplication.interfaceThemeChangedNotification, object: nil) } func updateViewColor() { if (KMAppearance.isDarkMode()) { self.searchField.layer?.backgroundColor = NSColor(red: 57.0/255.0, green: 60.0/255.0, blue: 62.0/255.0, alpha: 1).cgColor } else { self.searchField.layer?.backgroundColor = .white } } @objc func themeChanged(_ notification: NSNotification) { DispatchQueue.main.asyncAfter(deadline: .now()+0.3) { self.updateViewColor() } } @IBAction func searchDomeButtonAtion(_ sender: AnyObject) { self.searchField.isHidden = true self.searchDomeButton.isHidden = true self.searchBox.isHidden = false } }