Change to mark all as unread for the selected article feed. Issue #657

This commit is contained in:
Maurice Parker 2019-05-22 10:07:00 -05:00
parent a406fa9d4d
commit 43f8e9880c
1 changed files with 20 additions and 16 deletions

View File

@ -85,8 +85,16 @@ extension TimelineViewController {
}
@objc func markAllAsRead(_ sender: Any?) {
markAllAsRead()
@objc func markAllInFeedAsRead(_ sender: Any?) {
guard let menuItem = sender as? NSMenuItem, let feedArticles = menuItem.representedObject as? ArticleArray else {
return
}
guard let undoManager = undoManager, let markReadCommand = MarkStatusCommand(initialArticles: feedArticles, markingRead: true, undoManager: undoManager) else {
return
}
runCommand(markReadCommand)
}
@objc func openInBrowserFromContextualMenu(_ sender: Any?) {
@ -168,10 +176,9 @@ private extension TimelineViewController {
if articles.count == 1, let feed = articles.first!.feed {
menu.addItem(selectFeedInSidebarMenuItem(feed))
}
if let markAllMenuItem = markAllAsReadMenuItem() {
menu.addItem(markAllMenuItem)
if let markAllMenuItem = markAllAsReadMenuItem(feed) {
menu.addItem(markAllMenuItem)
}
}
if articles.count == 1, let link = articles.first!.preferredLink {
@ -246,20 +253,17 @@ private extension TimelineViewController {
return menuItem(formattedMenuText as String, #selector(selectFeedInSidebarFromContextualMenu(_:)), feed)
}
func markAllAsReadMenuItem() -> NSMenuItem? {
guard canMarkAllAsRead() else {
func markAllAsReadMenuItem(_ feed: Feed) -> NSMenuItem? {
let articles = Array(feed.fetchArticles())
guard articles.canMarkAllAsRead() else {
return nil
}
let menuText: String
if representedObjects?.count == 1, let nameProvider = representedObjects!.first! as? DisplayNameProvider {
let localizedMenuText = NSLocalizedString("Mark All as Read in \"%@\"", comment: "Command")
menuText = NSString.localizedStringWithFormat(localizedMenuText as NSString, nameProvider.nameForDisplay) as String
} else {
menuText = NSLocalizedString("Mark All as Read in Timeline", comment: "Command")
}
let localizedMenuText = NSLocalizedString("Mark All as Read in \"%@\"", comment: "Command")
let menuText = NSString.localizedStringWithFormat(localizedMenuText as NSString, feed.nameForDisplay) as String
return menuItem(menuText, #selector(markAllAsRead(_:)), representedObjects as Any)
return menuItem(menuText, #selector(markAllInFeedAsRead(_:)), articles)
}
func openInBrowserMenuItem(_ urlString: String) -> NSMenuItem {