Add row swipe action for Mark/Unmark Starred
This commit is contained in:
parent
bc32fc1cb9
commit
f67b7df5a9
|
@ -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 []
|
||||
|
|
Loading…
Reference in New Issue