Changed the Mark as Read toolbar item to toggle back and forth between read and unread states. Issue #46.

This commit is contained in:
Maurice Parker
2018-09-13 15:00:33 -05:00
parent cd8c7a2b0c
commit 7c37ed5d88
3 changed files with 62 additions and 13 deletions

View File

@@ -129,8 +129,8 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
return canMarkAllAsRead()
}
if item.action == #selector(markRead(_:)) {
return canMarkRead()
if item.action == #selector(toggleRead(_:)) {
return validateToggleRead(item)
}
if item.action == #selector(toggleStarred(_:)) {
@@ -223,9 +223,9 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
timelineViewController?.markAllAsRead()
}
@IBAction func markRead(_ sender: Any?) {
@IBAction func toggleRead(_ sender: Any?) {
timelineViewController?.markSelectedArticlesAsRead(sender)
timelineViewController?.toggleReadStatusForSelectedArticles()
}
@IBAction func markUnread(_ sender: Any?) {
@@ -407,9 +407,35 @@ private extension MainWindowController {
return timelineViewController?.canMarkAllAsRead() ?? false
}
func canMarkRead() -> Bool {
func validateToggleRead(_ item: NSValidatedUserInterfaceItem) -> Bool {
return timelineViewController?.canMarkSelectedArticlesAsRead() ?? false
let validationStatus = timelineViewController?.markReadCommandStatus() ?? .canDoNothing
let markingRead: Bool
let result: Bool
switch validationStatus {
case .canMark:
markingRead = true
result = true
case .canUnmark:
markingRead = false
result = true
case .canDoNothing:
markingRead = true
result = false
}
let commandName = markingRead ? NSLocalizedString("Mark as Read", comment: "Command") : NSLocalizedString("Mark as Unread", comment: "Command")
if let toolbarItem = item as? NSToolbarItem {
toolbarItem.toolTip = commandName
}
if let menuItem = item as? NSMenuItem {
menuItem.title = commandName
}
return result
}
func canMarkOlderArticlesAsRead() -> Bool {