From f8cf5676e9d4d8b0c3e59c01d1857a05d92afc69 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Tue, 11 Aug 2020 20:19:17 -0500 Subject: [PATCH] Don't allow Twitter or Reddit feeds to be added to accounts that can't handle them --- Mac/AppDelegate.swift | 5 +++-- Mac/MainWindow/AddFeed/AddTwitterFeedWindowController.swift | 2 +- Mac/MainWindow/AddFeed/FolderTreeMenu.swift | 6 +++++- Mac/MainWindow/AddRedditFeedWindowController.swift | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index 33960838d..335ab4617 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -405,6 +405,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, } let isDisplayingSheet = mainWindowController?.isDisplayingSheet ?? false + let isSpecialAccountAvailable = AccountManager.shared.activeAccounts.contains(where: { $0.type == .onMyMac || $0.type == .cloudKit }) if item.action == #selector(refreshAll(_:)) { return !AccountManager.shared.refreshInProgress && !AccountManager.shared.activeAccounts.isEmpty @@ -419,13 +420,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, return !isDisplayingSheet && !AccountManager.shared.activeAccounts.isEmpty } if item.action == #selector(showAddRedditFeedWindow(_:)) { - guard !isDisplayingSheet && !AccountManager.shared.activeAccounts.isEmpty else { + guard !isDisplayingSheet && isSpecialAccountAvailable else { return false } return ExtensionPointManager.shared.isRedditEnabled } if item.action == #selector(showAddTwitterFeedWindow(_:)) { - guard !isDisplayingSheet && !AccountManager.shared.activeAccounts.isEmpty else { + guard !isDisplayingSheet && isSpecialAccountAvailable else { return false } return ExtensionPointManager.shared.isTwitterEnabled diff --git a/Mac/MainWindow/AddFeed/AddTwitterFeedWindowController.swift b/Mac/MainWindow/AddFeed/AddTwitterFeedWindowController.swift index 7698659fd..31748d6b0 100644 --- a/Mac/MainWindow/AddFeed/AddTwitterFeedWindowController.swift +++ b/Mac/MainWindow/AddFeed/AddTwitterFeedWindowController.swift @@ -71,7 +71,7 @@ class AddTwitterFeedWindowController : NSWindowController, AddFeedWindowControll } accountPopupButton.menu = accountMenu - folderPopupButton.menu = FolderTreeMenu.createFolderPopupMenu(with: folderTreeController.rootNode) + folderPopupButton.menu = FolderTreeMenu.createFolderPopupMenu(with: folderTreeController.rootNode, restrictToSpecialAccounts: true) if let container = AddWebFeedDefaultContainer.defaultContainer { if let folder = container as? Folder, let account = folder.account { diff --git a/Mac/MainWindow/AddFeed/FolderTreeMenu.swift b/Mac/MainWindow/AddFeed/FolderTreeMenu.swift index 3216619c2..87250dd6b 100644 --- a/Mac/MainWindow/AddFeed/FolderTreeMenu.swift +++ b/Mac/MainWindow/AddFeed/FolderTreeMenu.swift @@ -13,7 +13,7 @@ import Account class FolderTreeMenu { - static func createFolderPopupMenu(with rootNode: Node) -> NSMenu { + static func createFolderPopupMenu(with rootNode: Node, restrictToSpecialAccounts: Bool = false) -> NSMenu { let menu = NSMenu(title: "Folders") menu.autoenablesItems = false @@ -24,6 +24,10 @@ class FolderTreeMenu { continue } + if restrictToSpecialAccounts && !(account.type == .onMyMac || account.type == .cloudKit) { + continue + } + let menuItem = NSMenuItem(title: account.nameForDisplay, action: nil, keyEquivalent: "") menuItem.representedObject = childNode.representedObject diff --git a/Mac/MainWindow/AddRedditFeedWindowController.swift b/Mac/MainWindow/AddRedditFeedWindowController.swift index 8bf7c9288..55056ad34 100644 --- a/Mac/MainWindow/AddRedditFeedWindowController.swift +++ b/Mac/MainWindow/AddRedditFeedWindowController.swift @@ -90,7 +90,7 @@ class AddRedditFeedWindowController : NSWindowController, AddFeedWindowControlle } accountPopupButton.menu = accountMenu - folderPopupButton.menu = FolderTreeMenu.createFolderPopupMenu(with: folderTreeController.rootNode) + folderPopupButton.menu = FolderTreeMenu.createFolderPopupMenu(with: folderTreeController.rootNode, restrictToSpecialAccounts: true) if let container = AddWebFeedDefaultContainer.defaultContainer { if let folder = container as? Folder, let account = folder.account {