Make single non-local drops work with multiple accounts

This commit is contained in:
Maurice Parker 2019-05-01 17:33:08 -05:00
parent 73f035c5b7
commit 78e98e4c03
6 changed files with 28 additions and 16 deletions

View File

@ -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

View File

@ -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)
}

View File

@ -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()

View File

@ -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
}
}
}
}

View File

@ -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?) {

View File

@ -295,8 +295,14 @@ private extension SidebarOutlineDataSource {
}
// Show the add-feed sheet.
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, folder: folder)
appDelegate.addFeed(draggedFeed.url, name: draggedFeed.editedName ?? draggedFeed.name, account: account, folder: folder)
}
return true
}