From bc32fc1cb913a2ed22dcbb03caa465ada316b673 Mon Sep 17 00:00:00 2001 From: Nate Weaver Date: Sun, 22 Sep 2019 09:55:19 -0500 Subject: [PATCH 1/3] Add row swipe action for Mark Read/Unread --- .../Timeline/TimelineViewController.swift | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Mac/MainWindow/Timeline/TimelineViewController.swift b/Mac/MainWindow/Timeline/TimelineViewController.swift index 8fdb02647..ae8906d12 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController.swift @@ -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 From f67b7df5a9be1903395ddf2fa31162780de36e13 Mon Sep 17 00:00:00 2001 From: Nate Weaver Date: Tue, 24 Sep 2019 08:50:15 -0500 Subject: [PATCH 2/3] Add row swipe action for Mark/Unmark Starred --- .../Timeline/TimelineViewController.swift | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/Mac/MainWindow/Timeline/TimelineViewController.swift b/Mac/MainWindow/Timeline/TimelineViewController.swift index ae8906d12..215a608c2 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController.swift @@ -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 [] - } + 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") + 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] - 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 [] From ef29334a41b92b9bd05eac3ee9cffb810c5d6533 Mon Sep 17 00:00:00 2001 From: Nate Weaver Date: Wed, 2 Oct 2019 11:18:52 -0500 Subject: [PATCH 3/3] Use os_log() instead of NSLog() --- Mac/MainWindow/Timeline/TimelineViewController.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Mac/MainWindow/Timeline/TimelineViewController.swift b/Mac/MainWindow/Timeline/TimelineViewController.swift index 215a608c2..4684058ef 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController.swift @@ -10,6 +10,7 @@ import Foundation import RSCore import Articles import Account +import os.log protocol TimelineDelegate: class { func timelineSelectionDidChange(_: TimelineViewController, selectedArticles: [Article]?) @@ -785,7 +786,7 @@ extension TimelineViewController: NSTableViewDelegate { return [action] @unknown default: - NSLog("Unknown table row edge: %ld", edge.rawValue) + os_log(.error, "Unknown table row edge: %ld", edge.rawValue) } return []