From 0da916fa68cdab862828778f09191d73f423210c Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Tue, 21 May 2019 14:57:22 -0500 Subject: [PATCH] Add Mark All as Read contextual menu item. Issue #657 --- ...melineViewController+ContextualMenus.swift | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/Mac/MainWindow/Timeline/TimelineViewController+ContextualMenus.swift b/Mac/MainWindow/Timeline/TimelineViewController+ContextualMenus.swift index c2a947230..422cd4f95 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController+ContextualMenus.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController+ContextualMenus.swift @@ -7,6 +7,7 @@ // import AppKit +import RSCore import Articles import Account @@ -84,6 +85,10 @@ extension TimelineViewController { } + @objc func markAllAsRead(_ sender: Any?) { + markAllAsRead() + } + @objc func openInBrowserFromContextualMenu(_ sender: Any?) { guard let menuItem = sender as? NSMenuItem, let urlString = menuItem.representedObject as? String else { @@ -162,7 +167,11 @@ private extension TimelineViewController { menu.addSeparatorIfNeeded() if articles.count == 1, let feed = articles.first!.feed { - menu.addItem(selectFeedInSidebar(feed)) + menu.addItem(selectFeedInSidebarMenuItem(feed)) + } + + if let markAllMenuItem = markAllAsReadMenuItem() { + menu.addItem(markAllMenuItem) } if articles.count == 1, let link = articles.first!.preferredLink { @@ -231,11 +240,28 @@ 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 selectFeedInSidebarMenuItem(_ feed: Feed) -> NSMenuItem { + let localizedMenuText = NSLocalizedString("Select \"%@\" in Sidebar", comment: "Command") + let formattedMenuText = NSString.localizedStringWithFormat(localizedMenuText as NSString, feed.nameForDisplay) + return menuItem(formattedMenuText as String, #selector(selectFeedInSidebarFromContextualMenu(_:)), feed) } + func markAllAsReadMenuItem() -> NSMenuItem? { + guard 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") + } + + return menuItem(menuText, #selector(markAllAsRead(_:)), representedObjects as Any) + } + func openInBrowserMenuItem(_ urlString: String) -> NSMenuItem { return menuItem(NSLocalizedString("Open in Browser", comment: "Command"), #selector(openInBrowserFromContextualMenu(_:)), urlString)