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