diff --git a/Mac/MainWindow/Timeline/TimelineViewController+ContextualMenus.swift b/Mac/MainWindow/Timeline/TimelineViewController+ContextualMenus.swift index 422cd4f95..dd2302aec 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController+ContextualMenus.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController+ContextualMenus.swift @@ -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 {