From 78e98e4c032ea0d0d600b6acc3a8c0873af28110 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Wed, 1 May 2019 17:33:08 -0500 Subject: [PATCH] Make single non-local drops work with multiple accounts --- Mac/AppDelegate.swift | 8 ++++---- Mac/MainWindow/AddFeed/AddFeedController.swift | 4 ++-- Mac/MainWindow/AddFeed/AddFeedWindowController.swift | 8 +++++--- Mac/MainWindow/AddFeed/FolderTreeMenu.swift | 12 ++++++++---- Mac/MainWindow/MainWindowController.swift | 2 +- .../Sidebar/SidebarOutlineDataSource.swift | 10 ++++++++-- 6 files changed, 28 insertions(+), 16 deletions(-) diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index f1b7d87e6..b569cb758 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -94,10 +94,10 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, addFolderWindowController!.runSheetOnWindow(window) } - func showAddFeedSheetOnWindow(_ window: NSWindow, urlString: String?, name: String?, folder: Folder?) { + func showAddFeedSheetOnWindow(_ window: NSWindow, urlString: String?, name: String?, account: Account?, folder: Folder?) { addFeedController = AddFeedController(hostWindow: window) - addFeedController?.showAddFeedSheet(urlString, name, folder) + addFeedController?.showAddFeedSheet(urlString, name, account, folder) } // MARK: - NSApplicationDelegate @@ -280,14 +280,14 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, // MARK: Add Feed - func addFeed(_ urlString: String?, name: String? = nil, folder: Folder? = nil) { + func addFeed(_ urlString: String?, name: String? = nil, account: Account? = nil, folder: Folder? = nil) { createAndShowMainWindow() if mainWindowController!.isDisplayingSheet { return } - showAddFeedSheetOnWindow(mainWindowController!.window!, urlString: urlString, name: name, folder: folder) + showAddFeedSheetOnWindow(mainWindowController!.window!, urlString: urlString, name: name, account: account, folder: folder) } // MARK: - Dock Badge diff --git a/Mac/MainWindow/AddFeed/AddFeedController.swift b/Mac/MainWindow/AddFeed/AddFeedController.swift index ff759c8ec..da0c9d7ca 100644 --- a/Mac/MainWindow/AddFeed/AddFeedController.swift +++ b/Mac/MainWindow/AddFeed/AddFeedController.swift @@ -40,12 +40,12 @@ class AddFeedController: AddFeedWindowControllerDelegate, FeedFinderDelegate { self.hostWindow = hostWindow } - func showAddFeedSheet(_ urlString: String?, _ name: String?, _ folder: Folder?) { + func showAddFeedSheet(_ urlString: String?, _ name: String?, _ account: Account?, _ folder: Folder?) { let folderTreeControllerDelegate = FolderTreeControllerDelegate() let folderTreeController = TreeController(delegate: folderTreeControllerDelegate) - addFeedWindowController = AddFeedWindowController(urlString: urlString ?? urlStringFromPasteboard, name: name, folder: folder, folderTreeController: folderTreeController, delegate: self) + addFeedWindowController = AddFeedWindowController(urlString: urlString ?? urlStringFromPasteboard, name: name, account: account, folder: folder, folderTreeController: folderTreeController, delegate: self) addFeedWindowController!.runSheetOnWindow(hostWindow) } diff --git a/Mac/MainWindow/AddFeed/AddFeedWindowController.swift b/Mac/MainWindow/AddFeed/AddFeedWindowController.swift index 8ba07d2fb..41a18fa26 100644 --- a/Mac/MainWindow/AddFeed/AddFeedWindowController.swift +++ b/Mac/MainWindow/AddFeed/AddFeedWindowController.swift @@ -29,6 +29,7 @@ class AddFeedWindowController : NSWindowController { private var urlString: String? private var initialName: String? + private var initialAccount: Account? private var initialFolder: Folder? private weak var delegate: AddFeedWindowControllerDelegate? private var folderTreeController: TreeController! @@ -44,10 +45,11 @@ class AddFeedWindowController : NSWindowController { var hostWindow: NSWindow! - convenience init(urlString: String?, name: String?, folder: Folder?, folderTreeController: TreeController, delegate: AddFeedWindowControllerDelegate?) { + convenience init(urlString: String?, name: String?, account: Account?, folder: Folder?, folderTreeController: TreeController, delegate: AddFeedWindowControllerDelegate?) { self.init(windowNibName: NSNib.Name("AddFeedSheet")) self.urlString = urlString self.initialName = name + self.initialAccount = account self.initialFolder = folder self.delegate = delegate self.folderTreeController = folderTreeController @@ -67,8 +69,8 @@ class AddFeedWindowController : NSWindowController { } folderPopupButton.menu = FolderTreeMenu.createFolderPopupMenu(with: folderTreeController.rootNode) - if let folder = initialFolder { - FolderTreeMenu.select(folder, in: folderPopupButton) + if let account = initialAccount { + FolderTreeMenu.select(account: account, folder: initialFolder, in: folderPopupButton) } updateUI() diff --git a/Mac/MainWindow/AddFeed/FolderTreeMenu.swift b/Mac/MainWindow/AddFeed/FolderTreeMenu.swift index 91ad09831..c094eb5f2 100644 --- a/Mac/MainWindow/AddFeed/FolderTreeMenu.swift +++ b/Mac/MainWindow/AddFeed/FolderTreeMenu.swift @@ -32,17 +32,21 @@ class FolderTreeMenu { } - - return menu } - static func select(_ folder: Folder, in popupButton: NSPopUpButton) { + static func select(account: Account, folder: Folder?, in popupButton: NSPopUpButton) { for menuItem in popupButton.itemArray { - if let oneFolder = menuItem.representedObject as? Folder, oneFolder == folder { + if let oneAccount = menuItem.representedObject as? Account, oneAccount == account && folder == nil { popupButton.select(menuItem) return } + if let oneFolder = menuItem.representedObject as? Folder, oneFolder == folder { + if oneFolder.account == account { + popupButton.select(menuItem) + return + } + } } } diff --git a/Mac/MainWindow/MainWindowController.swift b/Mac/MainWindow/MainWindowController.swift index 42668e8f7..d866b2511 100644 --- a/Mac/MainWindow/MainWindowController.swift +++ b/Mac/MainWindow/MainWindowController.swift @@ -248,7 +248,7 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations { } @IBAction func showAddFeedWindow(_ sender: Any?) { - appDelegate.showAddFeedSheetOnWindow(window!, urlString: nil, name: nil, folder: nil) + appDelegate.showAddFeedSheetOnWindow(window!, urlString: nil, name: nil, account: nil, folder: nil) } @IBAction func openArticleInBrowser(_ sender: Any?) { diff --git a/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift b/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift index 7201d2061..ff8350fe1 100644 --- a/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift +++ b/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift @@ -295,8 +295,14 @@ private extension SidebarOutlineDataSource { } // Show the add-feed sheet. - let folder = parentNode.representedObject as? Folder - appDelegate.addFeed(draggedFeed.url, name: draggedFeed.editedName ?? draggedFeed.name, folder: folder) + if let account = parentNode.representedObject as? Account { + appDelegate.addFeed(draggedFeed.url, name: draggedFeed.editedName ?? draggedFeed.name, account: account, folder: nil) + } else { + let account = parentNode.parent?.representedObject as? Account + let folder = parentNode.representedObject as? Folder + appDelegate.addFeed(draggedFeed.url, name: draggedFeed.editedName ?? draggedFeed.name, account: account, folder: folder) + } + return true }