Hook up new search toolbar item
This commit is contained in:
parent
656d327692
commit
8ee33c34b3
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue