From 5ded56fc28be9cebee0fb98a24383b8d51c6d810 Mon Sep 17 00:00:00 2001 From: Phil Viso Date: Sun, 19 May 2019 09:10:19 -0500 Subject: [PATCH 1/2] Fixed a crash that occurs when trying to add a new feed with no active accounts --- Mac/MainWindow/MainWindowController.swift | 8 ++++++++ Mac/MainWindow/Sidebar/SidebarViewController.swift | 14 +++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Mac/MainWindow/MainWindowController.swift b/Mac/MainWindow/MainWindowController.swift index d866b2511..1a7cf28c7 100644 --- a/Mac/MainWindow/MainWindowController.swift +++ b/Mac/MainWindow/MainWindowController.swift @@ -227,6 +227,10 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations { return true } + + if item.action == #selector(showAddFeedWindow(_:)) { + return canAddNewFeed() + } return true } @@ -591,6 +595,10 @@ private extension MainWindowController { return currentTimelineViewController?.canMarkAllAsRead() ?? false } + + func canAddNewFeed() -> Bool { + return sidebarViewController?.canAddNewFeed() ?? false + } func validateToggleRead(_ item: NSValidatedUserInterfaceItem) -> Bool { diff --git a/Mac/MainWindow/Sidebar/SidebarViewController.swift b/Mac/MainWindow/Sidebar/SidebarViewController.swift index 8e2be6b86..19a66cdcd 100644 --- a/Mac/MainWindow/Sidebar/SidebarViewController.swift +++ b/Mac/MainWindow/Sidebar/SidebarViewController.swift @@ -345,10 +345,9 @@ protocol SidebarDelegate: class { // MARK: - API func rebuildTreeAndRestoreSelection() { - - let savedAccounts = treeController.rootNode.childNodes.compactMap { $0.representedObject as? Account } - + let savedAccounts = accountNodes let savedSelection = selectedNodes + rebuildTreeAndReloadDataIfNeeded() restoreSelection(to: savedSelection, sendNotificationIfChanged: true) @@ -361,6 +360,11 @@ protocol SidebarDelegate: class { } } + + func canAddNewFeed() -> Bool { + return !accountNodes.isEmpty + } + } // MARK: - NSUserInterfaceValidations @@ -380,6 +384,10 @@ extension SidebarViewController: NSUserInterfaceValidations { private extension SidebarViewController { + var accountNodes: [Account] { + return treeController.rootNode.childNodes.compactMap { $0.representedObject as? Account } + } + var selectedNodes: [Node] { if let nodes = outlineView.selectedItems as? [Node] { return nodes From eb5c1a49f7b04df97b0f173083b264f62366b57f Mon Sep 17 00:00:00 2001 From: Phil Viso Date: Sun, 19 May 2019 09:14:40 -0500 Subject: [PATCH 2/2] Disable adding a new folder if there are no active accounts --- Mac/MainWindow/MainWindowController.swift | 8 ++++++++ Mac/MainWindow/Sidebar/SidebarViewController.swift | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/Mac/MainWindow/MainWindowController.swift b/Mac/MainWindow/MainWindowController.swift index 1a7cf28c7..7cb1edc7a 100644 --- a/Mac/MainWindow/MainWindowController.swift +++ b/Mac/MainWindow/MainWindowController.swift @@ -231,6 +231,10 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations { if item.action == #selector(showAddFeedWindow(_:)) { return canAddNewFeed() } + + if item.action == #selector(showAddFolderWindow(_:)) { + return canAddNewFolder() + } return true } @@ -599,6 +603,10 @@ private extension MainWindowController { func canAddNewFeed() -> Bool { return sidebarViewController?.canAddNewFeed() ?? false } + + func canAddNewFolder() -> Bool { + return sidebarViewController?.canAddNewFolder() ?? false + } func validateToggleRead(_ item: NSValidatedUserInterfaceItem) -> Bool { diff --git a/Mac/MainWindow/Sidebar/SidebarViewController.swift b/Mac/MainWindow/Sidebar/SidebarViewController.swift index 19a66cdcd..3489172df 100644 --- a/Mac/MainWindow/Sidebar/SidebarViewController.swift +++ b/Mac/MainWindow/Sidebar/SidebarViewController.swift @@ -365,6 +365,10 @@ protocol SidebarDelegate: class { return !accountNodes.isEmpty } + func canAddNewFolder() -> Bool { + return !accountNodes.isEmpty + } + } // MARK: - NSUserInterfaceValidations