Move undoable commands into TimelineViewController private extension.

This commit is contained in:
Brent Simmons 2017-11-04 10:39:47 -07:00
parent b2ad739caf
commit 0960477be6
1 changed files with 32 additions and 30 deletions

View File

@ -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 {