Changed the Mark as Read toolbar item to toggle back and forth between read and unread states. Issue #46.
This commit is contained in:
parent
cd8c7a2b0c
commit
7c37ed5d88
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14313.3.2" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14313.3.2"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14313.18"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
|
@ -120,7 +120,7 @@
|
|||
</buttonCell>
|
||||
</button>
|
||||
<connections>
|
||||
<action selector="markRead:" target="Oky-zY-oP4" id="yFY-gd-FOd"/>
|
||||
<action selector="toggleRead:" target="B8D-0N-5wS" id="r02-sN-noB"/>
|
||||
</connections>
|
||||
</toolbarItem>
|
||||
<toolbarItem implicitItemIdentifier="09CE2FC7-B9B6-4A74-85B3-2DED57082923" label="Star" paletteLabel="Star" toolTip="Star or Unstar" image="star" id="Gxg-WQ-ufC" customClass="RSToolbarItem" customModule="RSCore">
|
||||
|
@ -349,11 +349,11 @@
|
|||
<constraints>
|
||||
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="150" id="pzy-wh-tgi"/>
|
||||
</constraints>
|
||||
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="vs5-5h-CXe">
|
||||
<scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="vs5-5h-CXe">
|
||||
<rect key="frame" x="-100" y="-100" width="238" height="15"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</scroller>
|
||||
<scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="NO" id="FWV-kB-qct">
|
||||
<scroller key="verticalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="FWV-kB-qct">
|
||||
<rect key="frame" x="224" y="17" width="15" height="102"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</scroller>
|
||||
|
@ -517,11 +517,11 @@
|
|||
</subviews>
|
||||
<nil key="backgroundColor"/>
|
||||
</clipView>
|
||||
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="9r2-h4-K46">
|
||||
<scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="9r2-h4-K46">
|
||||
<rect key="frame" x="-100" y="-100" width="223" height="15"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</scroller>
|
||||
<scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="NO" id="hSI-DO-hVu">
|
||||
<scroller key="verticalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="hSI-DO-hVu">
|
||||
<rect key="frame" x="224" y="17" width="15" height="102"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</scroller>
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -208,6 +208,29 @@ class TimelineViewController: NSViewController, UndoableCommandRunner {
|
|||
NSPasteboard.general.copyObjects(selectedArticles)
|
||||
}
|
||||
|
||||
func toggleReadStatusForSelectedArticles() {
|
||||
|
||||
// If any one of the selected articles is unread, then mark them as read.
|
||||
// If all articles are read, then mark them as unread them.
|
||||
|
||||
let commandStatus = markReadCommandStatus()
|
||||
let markingRead: Bool
|
||||
switch commandStatus {
|
||||
case .canMark:
|
||||
markingRead = true
|
||||
case .canUnmark:
|
||||
markingRead = false
|
||||
case .canDoNothing:
|
||||
return
|
||||
}
|
||||
|
||||
guard let undoManager = undoManager, let markStarredCommand = MarkStatusCommand(initialArticles: selectedArticles, markingRead: markingRead, undoManager: undoManager) else {
|
||||
return
|
||||
}
|
||||
|
||||
runCommand(markStarredCommand)
|
||||
}
|
||||
|
||||
func toggleStarredStatusForSelectedArticles() {
|
||||
|
||||
// If any one of the selected articles is not starred, then star them.
|
||||
|
|
Loading…
Reference in New Issue