Enable add feed for multiple accounts
This commit is contained in:
parent
93630a7b72
commit
6ede5b7c3d
|
@ -17,12 +17,22 @@ class FolderTreeMenu {
|
|||
|
||||
let menu = NSMenu(title: "Folders")
|
||||
|
||||
let menuItem = NSMenuItem(title: NSLocalizedString("Top Level", comment: "Add Feed Sheet"), action: nil, keyEquivalent: "")
|
||||
menuItem.representedObject = rootNode.representedObject
|
||||
menu.addItem(menuItem)
|
||||
for childNode in rootNode.childNodes {
|
||||
|
||||
guard let nameProvider = childNode.representedObject as? DisplayNameProvider else {
|
||||
continue
|
||||
}
|
||||
|
||||
let menuItem = NSMenuItem(title: nameProvider.nameForDisplay, action: nil, keyEquivalent: "")
|
||||
menuItem.representedObject = childNode.representedObject
|
||||
menu.addItem(menuItem)
|
||||
|
||||
let childNodes = childNode.childNodes
|
||||
addFolderItemsToMenuWithNodes(menu: menu, nodes: childNodes, indentationLevel: 1)
|
||||
|
||||
}
|
||||
|
||||
|
||||
let childNodes = rootNode.childNodes
|
||||
addFolderItemsToMenuWithNodes(menu: menu, nodes: childNodes, indentationLevel: 1)
|
||||
|
||||
return menu
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ final class FolderTreeControllerDelegate: TreeControllerDelegate {
|
|||
|
||||
func treeController(treeController: TreeController, childNodesFor node: Node) -> [Node]? {
|
||||
|
||||
return node.isRoot ? childNodesForRootNode(node) : nil
|
||||
return node.isRoot ? childNodesForRootNode(node) : childNodes(node)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,20 +24,30 @@ private extension FolderTreeControllerDelegate {
|
|||
|
||||
func childNodesForRootNode(_ node: Node) -> [Node]? {
|
||||
|
||||
// Root node is “Top Level” and children are folders. Folders can’t have subfolders.
|
||||
// This will have to be revised later.
|
||||
|
||||
guard let folders = AccountManager.shared.defaultAccount.folders else {
|
||||
let accountNodes: [Node] = AccountManager.shared.accounts.map { account in
|
||||
let accountNode = Node(representedObject: account, parent: node)
|
||||
accountNode.canHaveChildNodes = true
|
||||
return accountNode
|
||||
}
|
||||
return accountNodes.sortedAlphabetically()
|
||||
|
||||
}
|
||||
|
||||
func childNodes(_ node: Node) -> [Node]? {
|
||||
|
||||
guard let account = node.representedObject as? Account, let folders = account.folders else {
|
||||
return nil
|
||||
}
|
||||
let folderNodes = folders.map { createNode($0, parent: node) }
|
||||
|
||||
let folderNodes: [Node] = folders.map { createNode($0, parent: node) }
|
||||
return folderNodes.sortedAlphabetically()
|
||||
|
||||
}
|
||||
|
||||
func createNode(_ folder: Folder, parent: Node) -> Node {
|
||||
|
||||
let node = Node(representedObject: folder, parent: parent)
|
||||
node.canHaveChildNodes = false
|
||||
return node
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,21 +25,27 @@ struct AddFeedFolderPickerData {
|
|||
rootNode.canHaveChildNodes = true
|
||||
let treeController = TreeController(delegate: treeControllerDelegate, rootNode: rootNode)
|
||||
|
||||
guard let rootNameProvider = treeController.rootNode.representedObject as? DisplayNameProvider else {
|
||||
return
|
||||
}
|
||||
|
||||
let rootName = rootNameProvider.nameForDisplay
|
||||
containerNames.append(rootName)
|
||||
containers.append(treeController.rootNode.representedObject as! Container)
|
||||
|
||||
treeController.rootNode.childNodes.forEach { node in
|
||||
guard let childContainer = node.representedObject as? Container else {
|
||||
|
||||
guard let acctNameProvider = node.representedObject as? DisplayNameProvider else {
|
||||
return
|
||||
}
|
||||
let childName = (childContainer as! DisplayNameProvider).nameForDisplay
|
||||
containerNames.append("\(rootName) / \(childName)")
|
||||
containers.append(childContainer)
|
||||
|
||||
let acctName = acctNameProvider.nameForDisplay
|
||||
containerNames.append(acctName)
|
||||
containers.append(node.representedObject as! Container)
|
||||
|
||||
for child in node.childNodes {
|
||||
|
||||
guard let childContainer = child.representedObject as? Container else {
|
||||
return
|
||||
}
|
||||
let childName = (childContainer as! DisplayNameProvider).nameForDisplay
|
||||
containerNames.append("\(acctName) / \(childName)")
|
||||
containers.append(childContainer)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue