Add row swipe action for Mark/Unmark Starred

This commit is contained in:
Nate Weaver 2019-09-24 08:50:15 -05:00
parent bc32fc1cb9
commit f67b7df5a9
1 changed files with 28 additions and 10 deletions

View File

@ -754,20 +754,38 @@ extension TimelineViewController: NSTableViewDelegate {
self.runCommand(markUnreadCommand)
}
private func toggleArticleStarred(_ article: Article) {
guard let undoManager = undoManager, let markUnreadCommand = MarkStatusCommand(initialArticles: [article], markingStarred: !article.status.starred, 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 []
}
switch edge {
case .leading:
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]
case .trailing:
let title = article.status.starred ? NSLocalizedString("Mark Unstarred", comment: "mark unstarred") : NSLocalizedString("Mark Starred", comment: "mark starred")
let action = NSTableViewRowAction(style: .regular, title: title) { (action, row) in
self.toggleArticleStarred(article);
tableView.rowActionsVisible = false
}
return [action]
@unknown default:
NSLog("Unknown table row edge: %ld", edge.rawValue)
}
return []