2017-05-27 10:43:27 -07:00
|
|
|
|
//
|
|
|
|
|
// 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
|
2017-09-17 12:22:15 -07:00
|
|
|
|
import Data
|
2017-09-24 12:24:44 -07:00
|
|
|
|
import Account
|
2017-05-27 10:43:27 -07: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 can’t have subfolders.
|
|
|
|
|
// This will have to be revised later.
|
|
|
|
|
|
|
|
|
|
var folderNodes = [Node]()
|
|
|
|
|
|
2017-10-07 21:41:21 -07:00
|
|
|
|
for oneRepresentedObject in AccountManager.shared.localAccount.children {
|
2017-05-27 10:43:27 -07:00
|
|
|
|
|
|
|
|
|
if let folder = oneRepresentedObject as? Folder {
|
|
|
|
|
folderNodes += [createNode(folder, parent: node)]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-18 16:56:36 -08:00
|
|
|
|
return folderNodes.sortedAlphabetically()
|
2017-05-27 10:43:27 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func createNode(_ folder: Folder, parent: Node) -> Node {
|
|
|
|
|
|
2017-11-04 15:27:32 -07:00
|
|
|
|
let node = Node(representedObject: folder, parent: parent)
|
2017-05-27 10:43:27 -07:00
|
|
|
|
node.canHaveChildNodes = false
|
|
|
|
|
return node
|
|
|
|
|
}
|
|
|
|
|
}
|