123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- //
- // 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!
- var contentView: NSView? {
- didSet {
- if let view = self.contentView {
- self.box.contentView = view
- }
- }
- }
- @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!
-
- 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.searchDomeButton.hidden = YES;
-
- self.searchField.wantsLayer = true
- // self.searchField.layer.backgroundColor = [KMAppearance KMColor_Layout_L1].CGColor;
- 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.searchField.hidden = YES;
- 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
- }
- }
|