Refactor select web feed in sidebar to use the delegate pattern instead of a notification.
This commit is contained in:
parent
d459c0927b
commit
4b2f08e759
|
@ -514,6 +514,11 @@ extension MainWindowController: TimelineContainerViewControllerDelegate {
|
|||
|
||||
detailViewController?.setState(detailState, mode: mode)
|
||||
}
|
||||
|
||||
func timelineRequestedWebFeedSelection(_: TimelineContainerViewController, webFeed: WebFeed) {
|
||||
sidebarViewController?.selectWebFeed(webFeed)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - NSSearchFieldDelegate
|
||||
|
|
|
@ -65,7 +65,6 @@ protocol SidebarDelegate: class {
|
|||
NotificationCenter.default.addObserver(self, selector: #selector(faviconDidBecomeAvailable(_:)), name: .FaviconDidBecomeAvailable, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(webFeedSettingDidChange(_:)), name: .WebFeedSettingDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange(_:)), name: .DisplayNameDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(userDidRequestSidebarSelection(_:)), name: .UserDidRequestSidebarSelection, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(downloadArticlesDidUpdateUnreadCounts(_:)), name: .DownloadArticlesDidUpdateUnreadCounts, object: nil)
|
||||
|
||||
outlineView.reloadData()
|
||||
|
@ -329,6 +328,10 @@ protocol SidebarDelegate: class {
|
|||
}
|
||||
|
||||
// MARK: - API
|
||||
|
||||
func selectWebFeed(_ webFeed: WebFeed) {
|
||||
revealAndSelectRepresentedObject(webFeed as AnyObject)
|
||||
}
|
||||
|
||||
func deepLinkRevealAndSelect(for userInfo: [AnyHashable : Any]) {
|
||||
guard let accountNode = findAccountNode(userInfo), let feedNode = findFeedNode(userInfo, beginningAt: accountNode) else {
|
||||
|
|
|
@ -7,10 +7,12 @@
|
|||
//
|
||||
|
||||
import AppKit
|
||||
import Account
|
||||
import Articles
|
||||
|
||||
protocol TimelineContainerViewControllerDelegate: class {
|
||||
func timelineSelectionDidChange(_: TimelineContainerViewController, articles: [Article]?, mode: TimelineSourceMode)
|
||||
func timelineRequestedWebFeedSelection(_: TimelineContainerViewController, webFeed: WebFeed)
|
||||
}
|
||||
|
||||
final class TimelineContainerViewController: NSViewController {
|
||||
|
@ -96,6 +98,11 @@ extension TimelineContainerViewController: TimelineDelegate {
|
|||
func timelineSelectionDidChange(_ timelineViewController: TimelineViewController, selectedArticles: [Article]?) {
|
||||
delegate?.timelineSelectionDidChange(self, articles: selectedArticles, mode: mode(for: timelineViewController))
|
||||
}
|
||||
|
||||
func timelineRequestedWebFeedSelection(_: TimelineViewController, webFeed: WebFeed) {
|
||||
delegate?.timelineRequestedWebFeedSelection(self, webFeed: webFeed)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private extension TimelineContainerViewController {
|
||||
|
|
|
@ -73,16 +73,10 @@ extension TimelineViewController {
|
|||
}
|
||||
|
||||
@objc func selectFeedInSidebarFromContextualMenu(_ sender: Any?) {
|
||||
|
||||
guard let menuItem = sender as? NSMenuItem, let feed = menuItem.representedObject as? WebFeed else {
|
||||
guard let menuItem = sender as? NSMenuItem, let webFeed = menuItem.representedObject as? WebFeed else {
|
||||
return
|
||||
}
|
||||
|
||||
var userInfo = UserInfoDictionary()
|
||||
userInfo[UserInfoKey.webFeed] = feed
|
||||
|
||||
NotificationCenter.default.post(name: .UserDidRequestSidebarSelection, object: self, userInfo: userInfo)
|
||||
|
||||
delegate?.timelineRequestedWebFeedSelection(self, webFeed: webFeed)
|
||||
}
|
||||
|
||||
@objc func markAllInFeedAsRead(_ sender: Any?) {
|
||||
|
|
|
@ -14,6 +14,7 @@ import os.log
|
|||
|
||||
protocol TimelineDelegate: class {
|
||||
func timelineSelectionDidChange(_: TimelineViewController, selectedArticles: [Article]?)
|
||||
func timelineRequestedWebFeedSelection(_: TimelineViewController, webFeed: WebFeed)
|
||||
}
|
||||
|
||||
final class TimelineViewController: NSViewController, UndoableCommandRunner, UnreadCountProvider {
|
||||
|
@ -58,7 +59,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
|||
}
|
||||
}
|
||||
|
||||
private weak var delegate: TimelineDelegate?
|
||||
weak var delegate: TimelineDelegate?
|
||||
var sharingServiceDelegate: NSSharingServiceDelegate?
|
||||
|
||||
var showsSearchResults = false
|
||||
|
|
|
@ -12,7 +12,6 @@ import Articles
|
|||
extension Notification.Name {
|
||||
static let InspectableObjectsDidChange = Notification.Name("TimelineSelectionDidChangeNotification")
|
||||
static let UserDidAddFeed = Notification.Name("UserDidAddFeedNotification")
|
||||
static let UserDidRequestSidebarSelection = Notification.Name("UserDidRequestSidebarSelectionNotification")
|
||||
|
||||
#if !MAC_APP_STORE
|
||||
static let WebInspectorEnabledDidChange = Notification.Name("WebInspectorEnabledDidChange")
|
||||
|
|
Loading…
Reference in New Issue