Restore functionality to mark older as read using keyboard shortcut. Issue #2451

This commit is contained in:
Maurice Parker 2020-09-22 19:42:14 -05:00
parent cb714d6781
commit e575aeca3c
2 changed files with 36 additions and 1 deletions

View File

@ -402,7 +402,11 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
sidebarViewController?.focus() sidebarViewController?.focus()
} }
} }
@IBAction func markOlderArticlesAsRead(_ sender: Any?) {
currentTimelineViewController?.markOlderArticlesRead()
}
@IBAction func markAboveArticlesAsRead(_ sender: Any?) { @IBAction func markAboveArticlesAsRead(_ sender: Any?) {
currentTimelineViewController?.markAboveArticlesRead() currentTimelineViewController?.markAboveArticlesRead()
} }

View File

@ -460,6 +460,10 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
return .canDoNothing return .canDoNothing
} }
func markOlderArticlesRead() {
markOlderArticlesRead(selectedArticles)
}
func markAboveArticlesRead() { func markAboveArticlesRead() {
markAboveArticlesRead(selectedArticles) markAboveArticlesRead(selectedArticles)
} }
@ -478,6 +482,33 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
return articles.articlesBelow(article: last).canMarkAllAsRead() return articles.articlesBelow(article: last).canMarkAllAsRead()
} }
func markOlderArticlesRead(_ selectedArticles: [Article]) {
// Mark articles older than the selectedArticles(s) as read.
var cutoffDate: Date? = nil
for article in selectedArticles {
if cutoffDate == nil {
cutoffDate = article.logicalDatePublished
}
else if cutoffDate! > article.logicalDatePublished {
cutoffDate = article.logicalDatePublished
}
}
if cutoffDate == nil {
return
}
let articlesToMark = articles.filter { $0.logicalDatePublished < cutoffDate! }
if articlesToMark.isEmpty {
return
}
guard let undoManager = undoManager, let markReadCommand = MarkStatusCommand(initialArticles: articlesToMark, markingRead: true, undoManager: undoManager) else {
return
}
runCommand(markReadCommand)
}
func markAboveArticlesRead(_ selectedArticles: [Article]) { func markAboveArticlesRead(_ selectedArticles: [Article]) {
guard let first = selectedArticles.first else { return } guard let first = selectedArticles.first else { return }
let articlesToMark = articles.articlesAbove(article: first) let articlesToMark = articles.articlesAbove(article: first)