diff --git a/Commands/MarkAllReadCommand.swift b/Commands/MarkAllReadCommand.swift new file mode 100644 index 000000000..3c00f3816 --- /dev/null +++ b/Commands/MarkAllReadCommand.swift @@ -0,0 +1,46 @@ +// +// MarkAllReadCommand.swift +// Evergreen +// +// Created by Brent Simmons on 10/26/17. +// Copyright © 2017 Ranchero Software. All rights reserved. +// + +import Foundation +import RSCore +import Data + +final class MarkAllReadCommand: UndoableCommand { + + static private let actionName = NSLocalizedString("Mark All as Read", comment: "command") + let undoActionName = actionName + let redoActionName = actionName + let articles: Set
+ + init(initialArticles: [Article]) { + + // Filter out articles already read. + let unreadArticles = initialArticles.filter { !$0.status.read } + self.articles = Set(unreadArticles) + } + + func perform() { + mark(read: true) + } + + func undo() { + mark(read: false) + } + + func redo() { + perform() + } +} + +private extension MarkAllReadCommand { + + func mark(read: Bool) { + + markArticles(articles, statusKey: .read, flag: read) + } +} diff --git a/Evergreen.xcodeproj/project.pbxproj b/Evergreen.xcodeproj/project.pbxproj index 0b2ac254e..d4c024066 100644 --- a/Evergreen.xcodeproj/project.pbxproj +++ b/Evergreen.xcodeproj/project.pbxproj @@ -17,6 +17,7 @@ 846E773E1F6EF67A00A165E2 /* Account.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 846E773A1F6EF5D700A165E2 /* Account.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 846E77411F6EF6A100A165E2 /* Database.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 846E77211F6EF5D100A165E2 /* Database.framework */; }; 846E77421F6EF6A100A165E2 /* Database.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 846E77211F6EF5D100A165E2 /* Database.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 84702AA41FA27AC0006B8943 /* MarkAllReadCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84702AA31FA27AC0006B8943 /* MarkAllReadCommand.swift */; }; 849A97431ED9EAA9007D329B /* AddFolderWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849A97421ED9EAA9007D329B /* AddFolderWindowController.swift */; }; 849A97531ED9EAC0007D329B /* AddFeedController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849A97511ED9EAC0007D329B /* AddFeedController.swift */; }; 849A97541ED9EAC0007D329B /* AddFeedWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849A97521ED9EAC0007D329B /* AddFeedWindowController.swift */; }; @@ -382,6 +383,7 @@ 846A7BEB1F872C5600FEFD30 /* BatchUpdate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BatchUpdate.swift; path = Evergreen/BatchUpdate.swift; sourceTree = ""; }; 846E77161F6EF5D000A165E2 /* Database.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Database.xcodeproj; path = Frameworks/Database/Database.xcodeproj; sourceTree = ""; }; 846E77301F6EF5D600A165E2 /* Account.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Account.xcodeproj; path = Frameworks/Account/Account.xcodeproj; sourceTree = ""; }; + 84702AA31FA27AC0006B8943 /* MarkAllReadCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkAllReadCommand.swift; sourceTree = ""; }; 849A97421ED9EAA9007D329B /* AddFolderWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AddFolderWindowController.swift; sourceTree = ""; }; 849A97511ED9EAC0007D329B /* AddFeedController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AddFeedController.swift; path = AddFeed/AddFeedController.swift; sourceTree = ""; }; 849A97521ED9EAC0007D329B /* AddFeedWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AddFeedWindowController.swift; path = AddFeed/AddFeedWindowController.swift; sourceTree = ""; }; @@ -520,6 +522,14 @@ name = Products; sourceTree = ""; }; + 84702AB31FA27AE8006B8943 /* Commands */ = { + isa = PBXGroup; + children = ( + 84702AA31FA27AC0006B8943 /* MarkAllReadCommand.swift */, + ); + path = Commands; + sourceTree = ""; + }; 849A97411ED9EAA9007D329B /* Add Folder */ = { isa = PBXGroup; children = ( @@ -676,6 +686,7 @@ 84DAEE311F870B390058304B /* DockBadge.swift */, 842E45DC1ED8C54B000A8B52 /* Browser.swift */, 846A7BEB1F872C5600FEFD30 /* BatchUpdate.swift */, + 84702AB31FA27AE8006B8943 /* Commands */, 842E45E11ED8C681000A8B52 /* MainWindow */, 842E45E01ED8C587000A8B52 /* Preferences */, 849A97861ED9ECEF007D329B /* Article Styles */, @@ -1174,6 +1185,7 @@ 842E45E51ED8C6B7000A8B52 /* MainWindowSplitView.swift in Sources */, 849A97661ED9EB96007D329B /* SidebarViewController.swift in Sources */, 849A97641ED9EB96007D329B /* SidebarOutlineView.swift in Sources */, + 84702AA41FA27AC0006B8943 /* MarkAllReadCommand.swift in Sources */, 849A979F1ED9F130007D329B /* SidebarCell.swift in Sources */, 849A97651ED9EB96007D329B /* SidebarTreeControllerDelegate.swift in Sources */, 849A97671ED9EB96007D329B /* UnreadCountView.swift in Sources */,