Show favicons in the Feed Directory. Fix #109.

This commit is contained in:
Brent Simmons 2017-11-25 11:33:07 -08:00
parent 5ddf9ea284
commit 8fe2810a90
2 changed files with 56 additions and 3 deletions

View File

@ -206,7 +206,7 @@
<imageView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="8NA-xf-HSF">
<rect key="frame" x="3" y="0.0" width="17" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<imageCell key="cell" refusesFirstResponder="YES" imageScaling="proportionallyDown" id="eJc-Zr-x65"/>
<imageCell key="cell" refusesFirstResponder="YES" imageScaling="proportionallyUpOrDown" id="eJc-Zr-x65"/>
</imageView>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="HwU-Ta-d1b" userLabel="Text field">
<rect key="frame" x="25" y="0.0" width="120" height="17"/>
@ -251,6 +251,9 @@
<constraint firstItem="uLp-jc-nMQ" firstAttribute="top" secondItem="4Vf-sw-YId" secondAttribute="top" id="tvf-eA-0KS"/>
</constraints>
</view>
<connections>
<outlet property="outlineView" destination="n3L-hE-QVt" id="5bh-jo-RY2"/>
</connections>
</viewController>
<customObject id="JQS-ie-zPj" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>

View File

@ -13,11 +13,26 @@ import RSCore
final class FeedListViewController: NSViewController {
@IBOutlet var outlineView: NSOutlineView!
private var sidebarCellAppearance: SidebarCellAppearance!
private let treeControllerDelegate = FeedListTreeControllerDelegate()
lazy var treeController: TreeController = {
TreeController(delegate: treeControllerDelegate)
}()
// MARK: NSViewController
override func viewDidLoad() {
sidebarCellAppearance = SidebarCellAppearance(theme: appDelegate.currentTheme, fontSize: AppDefaults.shared.sidebarFontSize)
NotificationCenter.default.addObserver(self, selector: #selector(faviconDidBecomeAvailable(_:)), name: .FaviconDidBecomeAvailable, object: nil)
}
// MARK: - Notifications
@objc func faviconDidBecomeAvailable(_ note: Notification) {
configureAvailableCells()
}
}
// MARK: - NSOutlineViewDataSource
@ -80,14 +95,19 @@ extension FeedListViewController: NSOutlineViewDelegate {
private func configure(_ cell: SidebarCell, _ node: Node) {
cell.cellAppearance = sidebarCellAppearance
cell.objectValue = node
cell.name = nameFor(node)
cell.image = imageFor(node)
cell.shouldShowImage = node.representedObject is FeedListFeed
}
func imageFor(_ node: Node) -> NSImage? {
return nil
guard let feed = node.representedObject as? FeedListFeed else {
return nil
}
return appDelegate.faviconDownloader.favicon(withHomePageURL: feed.homePageURL)
}
func nameFor(_ node: Node) -> String {
@ -97,5 +117,35 @@ extension FeedListViewController: NSOutlineViewDelegate {
}
return ""
}
}
private extension FeedListViewController {
func nodeForRow(_ row: Int) -> Node? {
if row < 0 || row >= outlineView.numberOfRows {
return nil
}
if let node = outlineView.item(atRow: row) as? Node {
return node
}
return nil
}
func cellForRowView(_ rowView: NSTableRowView) -> SidebarCell? {
return rowView.view(atColumn: 0) as? SidebarCell
}
func configureAvailableCells() {
outlineView.enumerateAvailableRowViews { (rowView: NSTableRowView, row: Int) -> Void in
guard let cell = cellForRowView(rowView), let node = nodeForRow(row) else {
return
}
configure(cell, node)
}
}
}