Hook up new search toolbar item

This commit is contained in:
Maurice Parker 2020-08-09 16:40:44 -05:00
parent 656d327692
commit 8ee33c34b3
1 changed files with 29 additions and 10 deletions

View File

@ -764,6 +764,14 @@ extension MainWindowController: NSToolbarDelegate {
button.sendAction(on: .leftMouseDown)
}
if #available(macOS 10.16, *) {
if item.itemIdentifier == .search, let searchItem = item as? NSSearchToolbarItem {
searchItem.searchField.delegate = self
searchItem.searchField.target = self
searchItem.searchField.action = #selector(runSearch(_:))
currentSearchField = searchItem.searchField
}
} else {
if item.itemIdentifier == .search, let searchField = item.view as? NSSearchField {
searchField.delegate = self
searchField.target = self
@ -771,12 +779,21 @@ extension MainWindowController: NSToolbarDelegate {
currentSearchField = searchField
}
}
}
func toolbarDidRemoveItem(_ notification: Notification) {
guard let item = notification.userInfo?["item"] as? NSToolbarItem else {
return
}
if #available(macOS 10.16, *) {
if item.itemIdentifier == .search, let searchItem = item as? NSSearchToolbarItem {
searchItem.searchField.delegate = nil
searchItem.searchField.target = nil
searchItem.searchField.action = nil
currentSearchField = nil
}
} else {
if item.itemIdentifier == .search, let searchField = item.view as? NSSearchField {
searchField.delegate = nil
searchField.target = nil
@ -784,6 +801,8 @@ extension MainWindowController: NSToolbarDelegate {
currentSearchField = nil
}
}
}
}
// MARK: - Private