Add NSOutlineView extension methods: canSelectItem and selectItemAndScrollToVisible.

This commit is contained in:
Brent Simmons 2018-01-27 12:34:53 -08:00
parent 7ba2fe72dd
commit ef8f508ee4
1 changed files with 19 additions and 0 deletions

View File

@ -159,9 +159,28 @@ public extension NSOutlineView {
guard let item = item(atRow: row) else { guard let item = item(atRow: row) else {
return false return false
} }
return canSelectItem(item)
}
func canSelectItem(_ item: Any) -> Bool {
let isSelectable = delegate?.outlineView?(self, shouldSelectItem: item) ?? true let isSelectable = delegate?.outlineView?(self, shouldSelectItem: item) ?? true
return isSelectable return isSelectable
} }
func selectItemAndScrollToVisible(_ item: Any) {
guard canSelectItem(item) else {
return
}
let rowToSelect = row(forItem: item)
guard rowToSelect != -1 else {
return
}
rs_selectRowAndScrollToVisible(rowToSelect)
}
} }