Add row swipe action for Mark Read/Unread

This commit is contained in:
Nate Weaver 2019-09-22 09:55:19 -05:00
parent 59143c2d8f
commit bc32fc1cb9
1 changed files with 26 additions and 0 deletions

View File

@ -746,6 +746,32 @@ extension TimelineViewController: NSTableViewDelegate {
cell.objectValue = nil
cell.cellData = TimelineCellData()
}
private func toggleArticleRead(_ article: Article) {
guard let undoManager = undoManager, let markUnreadCommand = MarkStatusCommand(initialArticles: [article], markingRead: !article.status.read, undoManager: undoManager) else {
return
}
self.runCommand(markUnreadCommand)
}
func tableView(_ tableView: NSTableView, rowActionsForRow row: Int, edge: NSTableView.RowActionEdge) -> [NSTableViewRowAction] {
if edge == .leading {
guard let article = articles.articleAtRow(row) else {
return []
}
let title = article.status.read ? NSLocalizedString("Mark Unread", comment: "mark unread") : NSLocalizedString("Mark Read", comment: "mark read")
let action = NSTableViewRowAction(style: .regular, title: title) { (action, row) in
self.toggleArticleRead(article);
tableView.rowActionsVisible = false
}
return [action]
}
return []
}
}
// MARK: - Private