Rename MarkAllReadCommand to MarkReadOrUnreadCommand and make it handle both cases.
This commit is contained in:
parent
9fbce42959
commit
17b84ec57c
@ -1,54 +0,0 @@
|
|||||||
//
|
|
||||||
// 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<Article>
|
|
||||||
let undoManager: UndoManager
|
|
||||||
|
|
||||||
init?(initialArticles: [Article], undoManager: UndoManager) {
|
|
||||||
|
|
||||||
// Filter out articles already read.
|
|
||||||
let unreadArticles = initialArticles.filter { !$0.status.read }
|
|
||||||
if unreadArticles.isEmpty {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
self.articles = Set(unreadArticles)
|
|
||||||
self.undoManager = undoManager
|
|
||||||
}
|
|
||||||
|
|
||||||
func perform() {
|
|
||||||
mark(read: true)
|
|
||||||
registerUndo()
|
|
||||||
}
|
|
||||||
|
|
||||||
func undo() {
|
|
||||||
mark(read: false)
|
|
||||||
registerRedo()
|
|
||||||
}
|
|
||||||
|
|
||||||
func redo() {
|
|
||||||
perform()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private extension MarkAllReadCommand {
|
|
||||||
|
|
||||||
func mark(read: Bool) {
|
|
||||||
|
|
||||||
markArticles(articles, statusKey: .read, flag: read)
|
|
||||||
}
|
|
||||||
}
|
|
63
Commands/MarkReadOrUnreadCommand.swift
Normal file
63
Commands/MarkReadOrUnreadCommand.swift
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
//
|
||||||
|
// MarkReadOrUnreadCommand.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 MarkReadOrUnreadCommand: UndoableCommand {
|
||||||
|
|
||||||
|
static private let markReadActionName = NSLocalizedString("Mark Read", comment: "command")
|
||||||
|
static private let markUnreadActionName = NSLocalizedString("Mark Unread", comment: "command")
|
||||||
|
let undoActionName: String
|
||||||
|
let redoActionName: String
|
||||||
|
let articles: Set<Article>
|
||||||
|
let undoManager: UndoManager
|
||||||
|
let markingRead: Bool
|
||||||
|
|
||||||
|
init?(initialArticles: [Article], markingRead: Bool, undoManager: UndoManager) {
|
||||||
|
|
||||||
|
// Filter out articles already read.
|
||||||
|
let articlesToMark = initialArticles.filter { markingRead ? !$0.status.read : $0.status.read }
|
||||||
|
if articlesToMark.isEmpty {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
self.articles = Set(articlesToMark)
|
||||||
|
|
||||||
|
self.markingRead = markingRead
|
||||||
|
|
||||||
|
self.undoManager = undoManager
|
||||||
|
|
||||||
|
if markingRead {
|
||||||
|
self.undoActionName = MarkReadOrUnreadCommand.markReadActionName
|
||||||
|
self.redoActionName = MarkReadOrUnreadCommand.markReadActionName
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
self.undoActionName = MarkReadOrUnreadCommand.markUnreadActionName
|
||||||
|
self.redoActionName = MarkReadOrUnreadCommand.markUnreadActionName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func perform() {
|
||||||
|
mark(read: markingRead)
|
||||||
|
registerUndo()
|
||||||
|
}
|
||||||
|
|
||||||
|
func undo() {
|
||||||
|
mark(read: !markingRead)
|
||||||
|
registerRedo()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private extension MarkReadOrUnreadCommand {
|
||||||
|
|
||||||
|
func mark(read: Bool) {
|
||||||
|
|
||||||
|
markArticles(articles, statusKey: .read, flag: read)
|
||||||
|
}
|
||||||
|
}
|
@ -17,7 +17,7 @@
|
|||||||
846E773E1F6EF67A00A165E2 /* Account.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 846E773A1F6EF5D700A165E2 /* Account.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
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 */; };
|
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, ); }; };
|
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 */; };
|
84702AA41FA27AC0006B8943 /* MarkReadOrUnreadCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84702AA31FA27AC0006B8943 /* MarkReadOrUnreadCommand.swift */; };
|
||||||
849A97431ED9EAA9007D329B /* AddFolderWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849A97421ED9EAA9007D329B /* AddFolderWindowController.swift */; };
|
849A97431ED9EAA9007D329B /* AddFolderWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849A97421ED9EAA9007D329B /* AddFolderWindowController.swift */; };
|
||||||
849A97531ED9EAC0007D329B /* AddFeedController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849A97511ED9EAC0007D329B /* AddFeedController.swift */; };
|
849A97531ED9EAC0007D329B /* AddFeedController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849A97511ED9EAC0007D329B /* AddFeedController.swift */; };
|
||||||
849A97541ED9EAC0007D329B /* AddFeedWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849A97521ED9EAC0007D329B /* AddFeedWindowController.swift */; };
|
849A97541ED9EAC0007D329B /* AddFeedWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849A97521ED9EAC0007D329B /* AddFeedWindowController.swift */; };
|
||||||
@ -383,7 +383,7 @@
|
|||||||
846A7BEB1F872C5600FEFD30 /* BatchUpdate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BatchUpdate.swift; path = Evergreen/BatchUpdate.swift; sourceTree = "<group>"; };
|
846A7BEB1F872C5600FEFD30 /* BatchUpdate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BatchUpdate.swift; path = Evergreen/BatchUpdate.swift; sourceTree = "<group>"; };
|
||||||
846E77161F6EF5D000A165E2 /* Database.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Database.xcodeproj; path = Frameworks/Database/Database.xcodeproj; sourceTree = "<group>"; };
|
846E77161F6EF5D000A165E2 /* Database.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Database.xcodeproj; path = Frameworks/Database/Database.xcodeproj; sourceTree = "<group>"; };
|
||||||
846E77301F6EF5D600A165E2 /* Account.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Account.xcodeproj; path = Frameworks/Account/Account.xcodeproj; sourceTree = "<group>"; };
|
846E77301F6EF5D600A165E2 /* Account.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Account.xcodeproj; path = Frameworks/Account/Account.xcodeproj; sourceTree = "<group>"; };
|
||||||
84702AA31FA27AC0006B8943 /* MarkAllReadCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkAllReadCommand.swift; sourceTree = "<group>"; };
|
84702AA31FA27AC0006B8943 /* MarkReadOrUnreadCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkReadOrUnreadCommand.swift; sourceTree = "<group>"; };
|
||||||
849A97421ED9EAA9007D329B /* AddFolderWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AddFolderWindowController.swift; sourceTree = "<group>"; };
|
849A97421ED9EAA9007D329B /* AddFolderWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AddFolderWindowController.swift; sourceTree = "<group>"; };
|
||||||
849A97511ED9EAC0007D329B /* AddFeedController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AddFeedController.swift; path = AddFeed/AddFeedController.swift; sourceTree = "<group>"; };
|
849A97511ED9EAC0007D329B /* AddFeedController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AddFeedController.swift; path = AddFeed/AddFeedController.swift; sourceTree = "<group>"; };
|
||||||
849A97521ED9EAC0007D329B /* AddFeedWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AddFeedWindowController.swift; path = AddFeed/AddFeedWindowController.swift; sourceTree = "<group>"; };
|
849A97521ED9EAC0007D329B /* AddFeedWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AddFeedWindowController.swift; path = AddFeed/AddFeedWindowController.swift; sourceTree = "<group>"; };
|
||||||
@ -525,7 +525,7 @@
|
|||||||
84702AB31FA27AE8006B8943 /* Commands */ = {
|
84702AB31FA27AE8006B8943 /* Commands */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
84702AA31FA27AC0006B8943 /* MarkAllReadCommand.swift */,
|
84702AA31FA27AC0006B8943 /* MarkReadOrUnreadCommand.swift */,
|
||||||
);
|
);
|
||||||
path = Commands;
|
path = Commands;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -1185,7 +1185,7 @@
|
|||||||
842E45E51ED8C6B7000A8B52 /* MainWindowSplitView.swift in Sources */,
|
842E45E51ED8C6B7000A8B52 /* MainWindowSplitView.swift in Sources */,
|
||||||
849A97661ED9EB96007D329B /* SidebarViewController.swift in Sources */,
|
849A97661ED9EB96007D329B /* SidebarViewController.swift in Sources */,
|
||||||
849A97641ED9EB96007D329B /* SidebarOutlineView.swift in Sources */,
|
849A97641ED9EB96007D329B /* SidebarOutlineView.swift in Sources */,
|
||||||
84702AA41FA27AC0006B8943 /* MarkAllReadCommand.swift in Sources */,
|
84702AA41FA27AC0006B8943 /* MarkReadOrUnreadCommand.swift in Sources */,
|
||||||
849A979F1ED9F130007D329B /* SidebarCell.swift in Sources */,
|
849A979F1ED9F130007D329B /* SidebarCell.swift in Sources */,
|
||||||
849A97651ED9EB96007D329B /* SidebarTreeControllerDelegate.swift in Sources */,
|
849A97651ED9EB96007D329B /* SidebarTreeControllerDelegate.swift in Sources */,
|
||||||
849A97671ED9EB96007D329B /* UnreadCountView.swift in Sources */,
|
849A97671ED9EB96007D329B /* UnreadCountView.swift in Sources */,
|
||||||
|
@ -123,10 +123,10 @@ class TimelineViewController: NSViewController, NSTableViewDelegate, NSTableView
|
|||||||
|
|
||||||
func markAllAsRead() {
|
func markAllAsRead() {
|
||||||
|
|
||||||
guard let undoManager = undoManager, let markAllReadCommand = MarkAllReadCommand(initialArticles: articles, undoManager: undoManager) else {
|
guard let undoManager = undoManager, let markReadCommand = MarkReadOrUnreadCommand(initialArticles: articles, markingRead: true, undoManager: undoManager) else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
runCommand(markAllReadCommand)
|
runCommand(markReadCommand)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Undoable Commands
|
// MARK: - Undoable Commands
|
||||||
@ -144,9 +144,9 @@ class TimelineViewController: NSViewController, NSTableViewDelegate, NSTableView
|
|||||||
|
|
||||||
private func clearUndoableCommands() {
|
private func clearUndoableCommands() {
|
||||||
|
|
||||||
// When the timeline is reloaded based on a different sidebar selection,
|
// When the timeline is reloaded and the list of articles changes,
|
||||||
// undoable commands should be dropped — otherwise things like
|
// undoable commands should be dropped — otherwise things like
|
||||||
// Redo Mark All as Read are ambiguous. (Do they apply to the previous articles
|
// Redo Mark Read are ambiguous. (Do they apply to the previous articles
|
||||||
// or to the current articles?)
|
// or to the current articles?)
|
||||||
|
|
||||||
guard let undoManager = undoManager else {
|
guard let undoManager = undoManager else {
|
||||||
@ -174,17 +174,28 @@ class TimelineViewController: NSViewController, NSTableViewDelegate, NSTableView
|
|||||||
let status = articles.first!.status
|
let status = articles.first!.status
|
||||||
let markAsRead = !status.read
|
let markAsRead = !status.read
|
||||||
|
|
||||||
markArticles(Set(articles), statusKey: .read, flag: markAsRead)
|
if markAsRead {
|
||||||
|
markSelectedArticlesAsRead(sender)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
markSelectedArticlesAsUnread(sender)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func markSelectedArticlesAsRead(_ sender: AnyObject) {
|
@IBAction func markSelectedArticlesAsRead(_ sender: AnyObject) {
|
||||||
|
|
||||||
markArticles(Set(selectedArticles), statusKey: .read, flag: true)
|
guard let undoManager = undoManager, let markReadCommand = MarkReadOrUnreadCommand(initialArticles: selectedArticles, markingRead: true, undoManager: undoManager) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
runCommand(markReadCommand)
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func markSelectedArticlesAsUnread(_ sender: AnyObject) {
|
@IBAction func markSelectedArticlesAsUnread(_ sender: AnyObject) {
|
||||||
|
|
||||||
markArticles(Set(selectedArticles), statusKey: .read, flag: false)
|
guard let undoManager = undoManager, let markUnreadCommand = MarkReadOrUnreadCommand(initialArticles: selectedArticles, markingRead: false, undoManager: undoManager) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
runCommand(markUnreadCommand)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Navigation
|
// MARK: - Navigation
|
||||||
|
@ -14,9 +14,8 @@ public protocol UndoableCommand: class {
|
|||||||
var redoActionName: String { get }
|
var redoActionName: String { get }
|
||||||
var undoManager: UndoManager { get }
|
var undoManager: UndoManager { get }
|
||||||
|
|
||||||
func perform()
|
func perform() // must call registerUndo()
|
||||||
func undo()
|
func undo() // must call registerRedo()
|
||||||
func redo()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension UndoableCommand {
|
extension UndoableCommand {
|
||||||
@ -33,7 +32,7 @@ extension UndoableCommand {
|
|||||||
|
|
||||||
undoManager.setActionName(redoActionName)
|
undoManager.setActionName(redoActionName)
|
||||||
undoManager.registerUndo(withTarget: self) { (target) in
|
undoManager.registerUndo(withTarget: self) { (target) in
|
||||||
self.redo()
|
self.perform()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user