Update sidebar when favicon becomes available. Fix #125.

This commit is contained in:
Brent Simmons 2017-11-25 11:14:42 -08:00
parent 22ec7d670a
commit 5ddf9ea284

View File

@ -37,6 +37,7 @@ import RSCore
NotificationCenter.default.addObserver(self, selector: #selector(containerChildrenDidChange(_:)), name: .ChildrenDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(userDidAddFeed(_:)), name: .UserDidAddFeed, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(batchUpdateDidPerform(_:)), name: .BatchUpdateDidPerform, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(faviconDidBecomeAvailable(_:)), name: .FaviconDidBecomeAvailable, object: nil)
outlineView.reloadData()
@ -82,6 +83,11 @@ import RSCore
revealAndSelectRepresentedObject(feed)
}
@objc func faviconDidBecomeAvailable(_ note: Notification) {
configureAvailableCells()
}
// MARK: Actions
@IBAction func delete(_ sender: AnyObject?) {
@ -358,20 +364,35 @@ private extension SidebarViewController {
return 0
}
func cellForRowView(_ rowView: NSTableRowView) -> SidebarCell? {
return rowView.view(atColumn: 0) as? SidebarCell
}
func availableSidebarCells() -> [SidebarCell] {
var cells = [SidebarCell]()
outlineView.enumerateAvailableRowViews { (rowView: NSTableRowView, _: Int) -> Void in
if let oneSidebarCell = rowView.view(atColumn: 0) as? SidebarCell {
cells += [oneSidebarCell]
if let cell = cellForRowView(rowView) {
cells += [cell]
}
}
return cells
}
func configureAvailableCells() {
outlineView.enumerateAvailableRowViews { (rowView: NSTableRowView, row: Int) -> Void in
guard let cell = cellForRowView(rowView), let node = nodeForRow(row) else {
return
}
configure(cell, node)
}
}
func cellsForRepresentedObject(_ representedObject: AnyObject) -> [SidebarCell] {
let availableCells = availableSidebarCells()