Clear undoableCommands when the articles array changes.

This commit is contained in:
Brent Simmons 2017-10-29 11:44:35 -07:00
parent 5f848f568a
commit 9fbce42959
1 changed files with 15 additions and 4 deletions

View File

@ -27,9 +27,12 @@ class TimelineViewController: NSViewController, NSTableViewDelegate, NSTableView
private var articles = [Article]() {
didSet {
if articles != oldValue {
clearUndoableCommands()
tableView.reloadData()
}
}
}
private var representedObjects: [AnyObject]? {
didSet {
@ -123,10 +126,16 @@ class TimelineViewController: NSViewController, NSTableViewDelegate, NSTableView
guard let undoManager = undoManager, let markAllReadCommand = MarkAllReadCommand(initialArticles: articles, undoManager: undoManager) else {
return
}
markAllReadCommand.perform()
runCommand(markAllReadCommand)
}
// MARK: - Actions
// MARK: - Undoable Commands
private func runCommand(_ undoableCommand: UndoableCommand) {
pushUndoableCommand(undoableCommand)
undoableCommand.perform()
}
private func pushUndoableCommand(_ undoableCommand: UndoableCommand) {
@ -147,6 +156,8 @@ class TimelineViewController: NSViewController, NSTableViewDelegate, NSTableView
undoableCommands = [UndoableCommand]()
}
// MARK: - Actions
@objc func openArticleInBrowser(_ sender: AnyObject) {
if let link = oneSelectedArticle?.preferredLink {