Merge pull request #484 from vincode-io/issue-225

Added "Select feed in Sidebar" to timeline content menu.  Issue #225
This commit is contained in:
Brent Simmons 2018-09-26 21:37:05 -07:00 committed by GitHub
commit 796074986d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 1 deletions

View File

@ -15,6 +15,7 @@ extension Notification.Name {
static let TimelineSelectionDidChange = Notification.Name("TimelineSelectionDidChangeNotification")
static let UserDidAddFeed = Notification.Name("UserDidAddFeedNotification")
static let UserDidRequestSidebarSelection = Notification.Name("UserDidRequestSidebarSelectionNotification")
// Sent by DetailViewController when mouse hovers over link in web view.
static let MouseDidEnterLink = Notification.Name("MouseDidEnterLinkNotification")

View File

@ -54,6 +54,7 @@ import RSCore
NotificationCenter.default.addObserver(self, selector: #selector(faviconDidBecomeAvailable(_:)), name: .FaviconDidBecomeAvailable, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(feedSettingDidChange(_:)), name: .FeedSettingDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange(_:)), name: .DisplayNameDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(userDidRequestSidebarSelection(_:)), name: .UserDidRequestSidebarSelection, object: nil)
outlineView.reloadData()
@ -120,6 +121,14 @@ import RSCore
configureCellsForRepresentedObject(object as AnyObject)
}
@objc func userDidRequestSidebarSelection(_ note: Notification) {
guard let feed = note.userInfo?[UserInfoKey.feed] else {
return
}
revealAndSelectRepresentedObject(feed as AnyObject)
}
// MARK: - Actions
@IBAction func delete(_ sender: AnyObject?) {

View File

@ -71,6 +71,19 @@ extension TimelineViewController {
markArticles(articles, starred: false)
}
@objc func selectFeedInSidebarFromContextualMenu(_ sender: Any?) {
guard let menuItem = sender as? NSMenuItem, let feed = menuItem.representedObject as? Feed else {
return
}
var userInfo = UserInfoDictionary()
userInfo[UserInfoKey.feed] = feed
NotificationCenter.default.post(name: .UserDidRequestSidebarSelection, object: self, userInfo: userInfo)
}
@objc func openInBrowserFromContextualMenu(_ sender: Any?) {
guard let menuItem = sender as? NSMenuItem, let urlString = menuItem.representedObject as? String else {
@ -145,9 +158,15 @@ private extension TimelineViewController {
if articles.count > 0 {
menu.addItem(markOlderReadMenuItem(articles))
}
menu.addSeparatorIfNeeded()
menu.addSeparatorIfNeeded()
if articles.count == 1, let feed = articles.first!.feed {
menu.addItem(selectFeedInSidebar(feed))
}
if articles.count == 1, let link = articles.first!.preferredLink {
menu.addSeparatorIfNeeded()
menu.addItem(openInBrowserMenuItem(link))
}
@ -212,6 +231,11 @@ private extension TimelineViewController {
return menuItem(NSLocalizedString("Mark Older as Read", comment: "Command"), #selector(markOlderArticlesReadFromContextualMenu(_:)), articles)
}
func selectFeedInSidebar(_ feed: Feed) -> NSMenuItem {
let menuText = "Select “\(feed.nameForDisplay)” in Sidebar"
return menuItem(NSLocalizedString(menuText, comment: "Command"), #selector(selectFeedInSidebarFromContextualMenu(_:)), feed)
}
func openInBrowserMenuItem(_ urlString: String) -> NSMenuItem {
return menuItem(NSLocalizedString("Open in Browser", comment: "Command"), #selector(openInBrowserFromContextualMenu(_:)), urlString)