Fix lint issues.

This commit is contained in:
Brent Simmons
2025-01-22 22:13:20 -08:00
parent d210692d7d
commit 72a5e46dcc
115 changed files with 584 additions and 711 deletions

View File

@@ -21,7 +21,7 @@ public extension NSOutlineView {
if numberOfNodes < 2 {
return false
}
let indexOfNodeToSelect = numberOfNodes - 1
for i in 1...indexOfNodeToSelect { // Start at 1 to skip root node.
@@ -36,8 +36,7 @@ public extension NSOutlineView {
selectRowIndexes(NSIndexSet(index: oneRow) as IndexSet, byExtendingSelection: false)
scrollRowToVisible(oneRow)
return true
}
else {
} else {
expandItem(oneNode)
}
}

View File

@@ -11,7 +11,7 @@ import Foundation
// Main thread only.
public final class Node: Hashable {
public weak var parent: Node?
public let representedObject: AnyObject
public var canHaveChildNodes = false
@@ -26,11 +26,11 @@ public final class Node: Hashable {
}
return true
}
public var numberOfChildNodes: Int {
return childNodes.count
}
public var indexPath: IndexPath {
if let parent = parent {
let parentPath = parent.indexPath
@@ -39,22 +39,22 @@ public final class Node: Hashable {
}
preconditionFailure("A Nodes parent must contain it as a child.")
}
return IndexPath(index: 0) //root node
return IndexPath(index: 0) // root node
}
public var level: Int {
if let parent = parent {
return parent.level + 1
}
return 0
}
public var isLeaf: Bool {
return numberOfChildNodes < 1
}
public init(representedObject: AnyObject, parent: Node?) {
precondition(Thread.isMainThread)
self.representedObject = representedObject
@@ -63,9 +63,9 @@ public final class Node: Hashable {
self.uniqueID = Node.incrementingID
Node.incrementingID += 1
}
public class func genericRootNode() -> Node {
let node = Node(representedObject: TopLevelRepresentedObject(), parent: nil)
node.canHaveChildNodes = true
return node
@@ -86,7 +86,7 @@ public final class Node: Hashable {
}
public func childAtIndex(_ index: Int) -> Node? {
if index >= childNodes.count || index < 0 {
return nil
}
@@ -94,12 +94,12 @@ public final class Node: Hashable {
}
public func indexOfChild(_ node: Node) -> Int? {
return childNodes.firstIndex{ (oneChildNode) -> Bool in
return childNodes.firstIndex { (oneChildNode) -> Bool in
oneChildNode === node
}
}
public func childNodeRepresentingObject(_ obj: AnyObject) -> Node? {
return findNodeRepresentingObject(obj, recursively: false)
}
@@ -182,12 +182,11 @@ public final class Node: Hashable {
}
}
public extension Array where Element == Node {
func representedObjects() -> [AnyObject] {
return self.map{ $0.representedObject }
return self.map { $0.representedObject }
}
}

View File

@@ -21,8 +21,7 @@ public struct NodePath {
if let parent = nomad.parent {
tempArray.append(parent)
nomad = parent
}
else {
} else {
break
}
}
@@ -34,8 +33,7 @@ public struct NodePath {
if let node = treeController.nodeInTreeRepresentingObject(representedObject) {
self.init(node: node)
}
else {
} else {
return nil
}
}

View File

@@ -9,11 +9,11 @@
import Foundation
public protocol TreeControllerDelegate: AnyObject {
func treeController(treeController: TreeController, childNodesFor: Node) -> [Node]?
}
public typealias NodeVisitBlock = (_ : Node) -> Void
public typealias NodeVisitBlock = (_: Node) -> Void
public final class TreeController {
@@ -21,32 +21,32 @@ public final class TreeController {
public let rootNode: Node
public init(delegate: TreeControllerDelegate, rootNode: Node) {
self.delegate = delegate
self.rootNode = rootNode
rebuild()
}
public convenience init(delegate: TreeControllerDelegate) {
self.init(delegate: delegate, rootNode: Node.genericRootNode())
}
@discardableResult
public func rebuild() -> Bool {
// Rebuild and re-sort. Return true if any changes in the entire tree.
return rebuildChildNodes(node: rootNode)
}
public func visitNodes(_ visitBlock: NodeVisitBlock) {
visitNode(rootNode, visitBlock)
}
public func nodeInArrayRepresentingObject(nodes: [Node], representedObject: AnyObject, recurse: Bool = false) -> Node? {
for oneNode in nodes {
if oneNode.representedObject === representedObject {
@@ -85,17 +85,17 @@ public final class TreeController {
}
private extension TreeController {
func visitNode(_ node: Node, _ visitBlock: NodeVisitBlock) {
visitBlock(node)
for oneChildNode in node.childNodes {
visitNode(oneChildNode, visitBlock)
}
}
func nodeArraysAreEqual(_ nodeArray1: [Node]?, _ nodeArray2: [Node]?) -> Bool {
if nodeArray1 == nil && nodeArray2 == nil {
return true
}
@@ -105,25 +105,25 @@ private extension TreeController {
if nodeArray1 == nil && nodeArray2 != nil {
return false
}
return nodeArray1! == nodeArray2!
}
func rebuildChildNodes(node: Node) -> Bool {
if !node.canHaveChildNodes {
return false
}
var childNodesDidChange = false
let childNodes = delegate?.treeController(treeController: self, childNodesFor: node) ?? [Node]()
childNodesDidChange = !nodeArraysAreEqual(childNodes, node.childNodes)
if (childNodesDidChange) {
if childNodesDidChange {
node.childNodes = childNodes
}
for oneChildNode in childNodes {
if rebuildChildNodes(node: oneChildNode) {
childNodesDidChange = true