From b3a5929d6d16bff1a3bde2b89465b6e13f37074e Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Fri, 4 Oct 2019 11:41:30 -0500 Subject: [PATCH] Fix places in iOS app that need to be using the undo manager --- iOS/SceneCoordinator.swift | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 7170a21f5..9a0b79878 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -711,10 +711,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { } func markAllAsRead(_ articles: [Article]) { - guard let undoManager = undoManager, let markReadCommand = MarkStatusCommand(initialArticles: articles, markingRead: true, undoManager: undoManager) else { - return - } - runCommand(markReadCommand) + markArticlesWithUndo(articles, statusKey: .read, flag: true) } func markAllAsRead() { @@ -747,42 +744,34 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { func markAsReadForCurrentArticle() { if let article = currentArticle { - markArticles(Set([article]), statusKey: .read, flag: true) + markArticlesWithUndo([article], statusKey: .read, flag: true) } } func markAsUnreadForCurrentArticle() { if let article = currentArticle { - markArticles(Set([article]), statusKey: .read, flag: false) + markArticlesWithUndo([article], statusKey: .read, flag: false) } } func toggleReadForCurrentArticle() { if let article = currentArticle { - markArticles(Set([article]), statusKey: .read, flag: !article.status.read) + toggleRead(article) } } func toggleRead(_ article: Article) { - guard let undoManager = undoManager, - let markReadCommand = MarkStatusCommand(initialArticles: [article], markingRead: !article.status.read, undoManager: undoManager) else { - return - } - runCommand(markReadCommand) + markArticlesWithUndo([article], statusKey: .read, flag: !article.status.read) } func toggleStarredForCurrentArticle() { if let article = currentArticle { - markArticles(Set([article]), statusKey: .starred, flag: !article.status.starred) + toggleStar(article) } } func toggleStar(_ article: Article) { - guard let undoManager = undoManager, - let markReadCommand = MarkStatusCommand(initialArticles: [article], markingStarred: !article.status.starred, undoManager: undoManager) else { - return - } - runCommand(markReadCommand) + markArticlesWithUndo([article], statusKey: .starred, flag: !article.status.starred) } func discloseFeed(_ feed: Feed, completion: (() -> Void)? = nil) { @@ -981,6 +970,13 @@ extension SceneCoordinator: ArticleExtractorDelegate { private extension SceneCoordinator { + func markArticlesWithUndo(_ articles: [Article], statusKey: ArticleStatus.Key, flag: Bool) { + guard let undoManager = undoManager, let markReadCommand = MarkStatusCommand(initialArticles: articles, statusKey: statusKey, flag: flag, undoManager: undoManager) else { + return + } + runCommand(markReadCommand) + } + func updateUnreadCount() { var count = 0 for article in articles {