Add hide read feeds menu option

This commit is contained in:
Maurice Parker 2019-11-22 10:55:54 -06:00
parent 43744ec128
commit 7667dbf60e
5 changed files with 38 additions and 12 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="15504" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="15505" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15504"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15505"/>
</dependencies>
<scenes>
<!--Application-->
@ -362,6 +362,12 @@
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="dZt-2W-gxf"/>
<menuItem title="Hide Read Feeds" id="E9K-zV-nLv">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleReadFilter:" target="Ady-hI-5gd" id="5pI-YT-xai"/>
</connections>
</menuItem>
<menuItem title="Show Sidebar" keyEquivalent="s" id="kIP-vf-haE">
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
<connections>

View File

@ -237,6 +237,10 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
return currentSearchField != nil
}
if item.action == #selector(toggleReadFilter(_:)) {
(item as! NSMenuItem).state = sidebarViewController?.isReadFiltered ?? false ? .on : .off
}
if item.action == #selector(toggleSidebar(_:)) {
guard let splitViewItem = sidebarSplitViewItem else {
return false
@ -438,6 +442,10 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
}
window?.makeFirstResponder(searchField)
}
@IBAction func toggleReadFilter(_ sender: Any?) {
sidebarViewController?.toggleReadFilter()
}
}
// MARK: - SidebarDelegate

View File

@ -30,6 +30,9 @@ protocol SidebarDelegate: class {
lazy var dataSource: SidebarOutlineDataSource = {
return SidebarOutlineDataSource(treeController: treeController)
}()
var isReadFiltered: Bool {
return treeControllerDelegate.isReadFiltered
}
var undoableCommands = [UndoableCommand]()
private var animatingChanges = false
@ -333,7 +336,16 @@ protocol SidebarDelegate: class {
}
revealAndSelectRepresentedObject(feedNode.representedObject)
}
func toggleReadFilter() {
if treeControllerDelegate.isReadFiltered {
treeControllerDelegate.isReadFiltered = false
} else {
treeControllerDelegate.isReadFiltered = true
}
rebuildTreeAndReloadDataIfNeeded()
}
}
// MARK: - NSUserInterfaceValidations

View File

@ -13,7 +13,7 @@ import Account
final class WebFeedTreeControllerDelegate: TreeControllerDelegate {
var isUnreadFiltered = false
var isReadFiltered = false
func treeController(treeController: TreeController, childNodesFor node: Node) -> [Node]? {
if node.isRoot {
@ -36,7 +36,7 @@ private extension WebFeedTreeControllerDelegate {
var topLevelNodes = [Node]()
// Check to see if we should show the SmartFeeds top level by checking the unreadFeed
if !(isUnreadFiltered && SmartFeedsController.shared.unreadFeed.unreadCount == 0) {
if !(isReadFiltered && SmartFeedsController.shared.unreadFeed.unreadCount == 0) {
let smartFeedsNode = rootNode.existingOrNewChildNode(with: SmartFeedsController.shared)
smartFeedsNode.canHaveChildNodes = true
smartFeedsNode.isGroupItem = true
@ -51,7 +51,7 @@ private extension WebFeedTreeControllerDelegate {
func childNodesForSmartFeeds(_ parentNode: Node) -> [Node] {
return SmartFeedsController.shared.smartFeeds.compactMap { (feed) -> Node? in
if isUnreadFiltered && feed.unreadCount == 0 {
if isReadFiltered && feed.unreadCount == 0 {
return nil
}
return parentNode.existingOrNewChildNode(with: feed as AnyObject)
@ -64,14 +64,14 @@ private extension WebFeedTreeControllerDelegate {
var children = [AnyObject]()
for webFeed in container.topLevelWebFeeds {
if !(isUnreadFiltered && webFeed.unreadCount == 0) {
if !(isReadFiltered && webFeed.unreadCount == 0) {
children.append(webFeed)
}
}
if let folders = container.folders {
for folder in folders {
if !(isUnreadFiltered && folder.unreadCount == 0) {
if !(isReadFiltered && folder.unreadCount == 0) {
children.append(folder)
}
}
@ -131,7 +131,7 @@ private extension WebFeedTreeControllerDelegate {
func sortedAccountNodes(_ parent: Node) -> [Node] {
let nodes = AccountManager.shared.sortedActiveAccounts.compactMap { (account) -> Node? in
if isUnreadFiltered && account.unreadCount == 0 {
if isReadFiltered && account.unreadCount == 0 {
return nil
}
let accountNode = parent.existingOrNewChildNode(with: account)

View File

@ -113,7 +113,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
}
var isUnreadFeedsFiltered: Bool {
return treeControllerDelegate.isUnreadFiltered
return treeControllerDelegate.isReadFiltered
}
var articleReadFilterType: ReadFilterType = .none
@ -472,12 +472,12 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
}
func showAllFeeds() {
treeControllerDelegate.isUnreadFiltered = false
treeControllerDelegate.isReadFiltered = false
rebuildBackingStores()
}
func hideUnreadFeeds() {
treeControllerDelegate.isUnreadFiltered = true
treeControllerDelegate.isReadFiltered = true
rebuildBackingStores()
}