diff --git a/Evergreen/MainWindow/Timeline/TimelineViewController.swift b/Evergreen/MainWindow/Timeline/TimelineViewController.swift index 6beda8936..7d3a17635 100644 --- a/Evergreen/MainWindow/Timeline/TimelineViewController.swift +++ b/Evergreen/MainWindow/Timeline/TimelineViewController.swift @@ -121,31 +121,9 @@ class TimelineViewController: NSViewController, KeyboardDelegate { runCommand(markReadCommand) } - // MARK: - Undoable Commands + func canMarkAllAsRead() -> Bool { - private func runCommand(_ undoableCommand: UndoableCommand) { - - pushUndoableCommand(undoableCommand) - undoableCommand.perform() - } - - private func pushUndoableCommand(_ undoableCommand: UndoableCommand) { - - undoableCommands += [undoableCommand] - } - - private func clearUndoableCommands() { - - // When the timeline is reloaded and the list of articles changes, - // undoable commands should be dropped — otherwise things like - // Redo Mark Read are ambiguous. (Do they apply to the previous articles - // or to the current articles?) - - guard let undoManager = undoManager else { - return - } - undoableCommands.forEach { undoManager.removeAllActions(withTarget: $0) } - undoableCommands = [UndoableCommand]() + return articles.canMarkAllAsRead() } // MARK: - Actions @@ -199,7 +177,6 @@ class TimelineViewController: NSViewController, KeyboardDelegate { } tableView.rs_selectRow(ix) tableView.scrollTo(row: ix) -// tableView.rs_selectRowAndScrollToVisible(ix) } func canGoToNextUnread() -> Bool { @@ -210,11 +187,6 @@ class TimelineViewController: NSViewController, KeyboardDelegate { return true } - func canMarkAllAsRead() -> Bool { - - return articles.canMarkAllAsRead() - } - func indexOfNextUnreadArticle() -> Int? { return articles.rowOfNextUnreadArticle(tableView.selectedRow) @@ -347,6 +319,36 @@ class TimelineViewController: NSViewController, KeyboardDelegate { } +// MARK: - Undoable Commands + +private extension TimelineViewController { + + func runCommand(_ undoableCommand: UndoableCommand) { + + pushUndoableCommand(undoableCommand) + undoableCommand.perform() + } + + func pushUndoableCommand(_ undoableCommand: UndoableCommand) { + + undoableCommands += [undoableCommand] + } + + func clearUndoableCommands() { + + // When the timeline is reloaded and the list of articles changes, + // undoable commands should be dropped — otherwise things like + // Redo Mark Read are ambiguous. (Do they apply to the previous articles + // or to the current articles?) + + guard let undoManager = undoManager else { + return + } + undoableCommands.forEach { undoManager.removeAllActions(withTarget: $0) } + undoableCommands = [UndoableCommand]() + } +} + // MARK: - NSTableViewDataSource extension TimelineViewController: NSTableViewDataSource {