NetNewsWire/Shared/Tree/FolderTreeControllerDelegat...

44 lines
1.1 KiB
Swift
Raw Normal View History

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
import RSCore
import RSTree
import Articles
2017-09-24 21:24:44 +02:00
import Account
2017-05-27 19:43:27 +02:00
final class FolderTreeControllerDelegate: TreeControllerDelegate {
func treeController(treeController: TreeController, childNodesFor node: Node) -> [Node]? {
return node.isRoot ? childNodesForRootNode(node) : nil
}
}
private extension FolderTreeControllerDelegate {
func childNodesForRootNode(_ node: Node) -> [Node]? {
// Root node is Top Level and children are folders. Folders cant have subfolders.
// This will have to be revised later.
guard let folders = AccountManager.shared.defaultAccount.folders else {
return nil
2017-05-27 19:43:27 +02:00
}
let folderNodes = 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 {
let node = Node(representedObject: folder, parent: parent)
2017-05-27 19:43:27 +02:00
node.canHaveChildNodes = false
return node
}
}