NetNewsWire/Evergreen/MainWindow/AddFeed/FolderTreeControllerDelegate.swift
2017-09-24 12:24:44 -07:00

50 lines
1.2 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// FolderTreeControllerDelegate.swift
// Evergreen
//
// Created by Brent Simmons on 8/10/16.
// Copyright © 2016 Ranchero Software, LLC. All rights reserved.
//
import Foundation
import RSCore
import RSTree
import Data
import Account
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.
var folderNodes = [Node]()
let _ = AccountManager.shared.localAccount.visitChildren { (oneRepresentedObject) in
if let folder = oneRepresentedObject as? Folder {
folderNodes += [createNode(folder, parent: node)]
}
return false
}
return Node.nodesSortedAlphabetically(folderNodes)
}
func createNode(_ folder: Folder, parent: Node) -> Node {
let node = Node(representedObject: folder as AnyObject, parent: parent)
node.canHaveChildNodes = false
return node
}
}