2017-05-27 19:43:27 +02:00
|
|
|
//
|
|
|
|
// FolderTreeControllerDelegate.swift
|
2018-08-29 07:18:24 +02:00
|
|
|
// NetNewsWire
|
2017-05-27 19:43:27 +02:00
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 8/10/16.
|
|
|
|
// Copyright © 2016 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
2024-03-22 01:21:50 +01:00
|
|
|
import Tree
|
2018-07-24 03:29:08 +02:00
|
|
|
import Articles
|
2017-09-24 21:24:44 +02:00
|
|
|
import Account
|
2017-05-27 19:43:27 +02:00
|
|
|
|
2024-03-22 01:21:50 +01:00
|
|
|
@MainActor final class FolderTreeControllerDelegate: TreeControllerDelegate {
|
|
|
|
|
2024-03-20 07:05:30 +01:00
|
|
|
@MainActor func treeController(treeController: TreeController, childNodesFor node: Node) -> [Node]? {
|
2017-05-27 19:43:27 +02:00
|
|
|
|
2019-05-01 21:03:59 +02:00
|
|
|
return node.isRoot ? childNodesForRootNode(node) : childNodes(node)
|
2017-05-27 19:43:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private extension FolderTreeControllerDelegate {
|
|
|
|
|
2024-03-22 01:21:50 +01:00
|
|
|
func childNodesForRootNode(_ node: Node) -> [Node]? {
|
2024-03-20 07:05:30 +01:00
|
|
|
|
2019-05-13 18:31:04 +02:00
|
|
|
let accountNodes: [Node] = AccountManager.shared.sortedActiveAccounts.map { account in
|
2019-05-01 21:03:59 +02:00
|
|
|
let accountNode = Node(representedObject: account, parent: node)
|
|
|
|
accountNode.canHaveChildNodes = true
|
|
|
|
return accountNode
|
|
|
|
}
|
2024-03-22 01:21:50 +01:00
|
|
|
|
2019-05-13 18:31:04 +02:00
|
|
|
return accountNodes
|
2019-05-01 21:03:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func childNodes(_ node: Node) -> [Node]? {
|
|
|
|
|
|
|
|
guard let account = node.representedObject as? Account, let folders = account.folders else {
|
2018-09-17 02:54:42 +02:00
|
|
|
return nil
|
2017-05-27 19:43:27 +02:00
|
|
|
}
|
2019-05-01 21:03:59 +02:00
|
|
|
|
|
|
|
let folderNodes: [Node] = folders.map { createNode($0, parent: node) }
|
2017-11-19 01:56:36 +01:00
|
|
|
return folderNodes.sortedAlphabetically()
|
2017-05-27 19:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func createNode(_ folder: Folder, parent: Node) -> Node {
|
2017-11-04 23:27:32 +01:00
|
|
|
let node = Node(representedObject: folder, parent: parent)
|
2017-05-27 19:43:27 +02:00
|
|
|
node.canHaveChildNodes = false
|
|
|
|
return node
|
|
|
|
}
|
|
|
|
}
|