Skip to content

Commit 1ed2df0

Browse files
committed
updated
1 parent a972df8 commit 1ed2df0

File tree

6 files changed

+26
-15
lines changed

6 files changed

+26
-15
lines changed

Example/Example/Base.lproj/Main.storyboard

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@
731731
<rect key="frame" x="0.0" y="0.0" width="220" height="376"/>
732732
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
733733
<subviews>
734-
<outlineView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" tableStyle="sourceList" selectionHighlightStyle="sourceList" columnReordering="NO" columnResizing="NO" autosaveColumns="NO" rowHeight="24" rowSizeStyle="automatic" viewBased="YES" indentationPerLevel="13" outlineTableColumn="dkC-fw-nsz" id="OL6-2g-mY0">
734+
<outlineView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" tableStyle="sourceList" selectionHighlightStyle="sourceList" columnReordering="NO" columnResizing="NO" autosaveColumns="NO" rowHeight="24" rowSizeStyle="automatic" viewBased="YES" floatsGroupRows="NO" indentationPerLevel="13" outlineTableColumn="dkC-fw-nsz" id="OL6-2g-mY0">
735735
<rect key="frame" x="0.0" y="0.0" width="220" height="376"/>
736736
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
737737
<size key="intercellSpacing" width="3" height="0.0"/>

Example/Example/OutlineSidebarViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class OutlineSidebarViewController: NSViewController {
3232
outlineView.dataSource = dataSource
3333

3434
/// Enables reordering selected rows by dragging them.
35-
dataSource.reorderingHandlers.canReorder = { _, _ in return true }
35+
dataSource.reorderingHandlers.canReorder = { _,_ in return true }
3636

3737
/// Enables deleting selected items via backspace key.
3838
dataSource.deletingHandlers.canDelete = { items in return items }

Sources/AdvancedCollectionTableView/Configuration/Extensions/NSTableView+/NSTableCellVew+.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,12 @@ extension NSTableCellView {
8484
contentView = contentConfiguration.makeContentView()
8585
translatesAutoresizingMaskIntoConstraints = false
8686
addSubview(withConstraint: contentView!)
87+
/*
8788
if let contentView = contentView as? NSListContentView {
88-
// textField = contentView.textField
89-
// imageView = contentView.imageView
89+
textField = contentView.textField
90+
imageView = contentView.imageView
9091
}
92+
*/
9193
}
9294
setNeedsDisplay()
9395
contentView?.setNeedsDisplay()

Sources/AdvancedCollectionTableView/DiffableDataSource/NSOutlineView/OutlineViewDiffableDataSource.swift

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ import FZSwiftUtils
3131
To connect a diffable data source to a outline view, you create the diffable data source using its ``init(outlineView:cellProvider:)`` or ``init(outlineView:cellRegistration:)`` initializer, passing in the outline view you want to associate with that data source.
3232

3333
```swift
34-
outlineView.dataSource = OutlineViewDiffableDataSource<Section, Item>(outlineView: outlineView, cellRegistration: cellRegistration)
34+
outlineView.dataSource = OutlineViewDiffableDataSource<Item>(outlineView: outlineView, cellRegistration: cellRegistration)
3535
```
3636

3737
Then, you generate the current state of the data and display the data in the UI by constructing and applying a snapshot. For more information, see `NSDiffableDataSourceSnapshot`.
3838

39-
- Note: Each of your sections and items must have unique identifiers.
39+
- Note: Each of your items must have unique identifiers.
4040

4141
- Note: Don’t change the `dataSource` or `delegate` on the outline view after you configure it with a diffable data source. If the outline view needs a new data source after you configure it initially, create and configure a new outline view and diffable data source.
4242
*/
@@ -431,7 +431,7 @@ public class OutlineViewDiffableDataSource<ItemIdentifierType: Hashable>: NSObje
431431
To connect a diffable data source to a outline view, you create the diffable data source using this initializer, passing in the outline view you want to associate with that data source. You also pass in a item provider, where you configure each of your cells to determine how to display your data in the UI.
432432

433433
```swift
434-
dataSource = OutlineViewDiffableDataSource<Section, Item>(outlineView: outlineView, cellProvider: {
434+
dataSource = OutlineViewDiffableDataSource<Item>(outlineView: outlineView, cellProvider: {
435435
(outlineView, tableColumn, item) in
436436
// configure and return cell
437437
})
@@ -459,7 +459,7 @@ public class OutlineViewDiffableDataSource<ItemIdentifierType: Hashable>: NSObje
459459
To connect a diffable data source to a outline view, you create the diffable data source using this initializer, passing in the outline view you want to associate with that data source. You also pass in a cell registration, where each of your cells gets determine how to display your data in the UI.
460460

461461
```swift
462-
dataSource = OutlineViewDiffableDataSource<Section, Item>(outlineView: outlineView, cellRegistration: cellRegistration)
462+
dataSource = OutlineViewDiffableDataSource<Item>(outlineView: outlineView, cellRegistration: cellRegistration)
463463
```
464464

465465
- Parameters:
@@ -485,15 +485,23 @@ public class OutlineViewDiffableDataSource<ItemIdentifierType: Hashable>: NSObje
485485
*/
486486
public typealias CellProvider = (_ outlineView: NSOutlineView, _ tableColumn: NSTableColumn?, _ identifier: ItemIdentifierType) -> NSView
487487

488-
/**
489-
Returns a representation of the current state of the data in the outline view.
490-
491-
A snapshot containing section and item identifiers in the order that they appear in the UI.
492-
*/
488+
/// Returns a representation of the current state of the data in the outline view.
493489
public func snapshot() -> OutlineViewDiffableDataSourceSnapshot<ItemIdentifierType> {
494490
currentSnapshot
495491
}
496492

493+
/// Returns a representation of the current state of the data in the specified item of the collection view.
494+
public func snapshot(for item: ItemIdentifierType) -> OutlineViewDiffableDataSourceSnapshot<ItemIdentifierType> {
495+
guard currentSnapshot.nodes[item] != nil else { return emptySnapshot() }
496+
let current = snapshot()
497+
var snapshot = emptySnapshot()
498+
snapshot.nodes[item] = .init()
499+
current.descendants(of: item).forEach({ snapshot.nodes[$0] = current.nodes[$0] })
500+
current.children(of: item).forEach({ snapshot.nodes[$0]?.parent = item })
501+
snapshot.updateOrderedItems()
502+
return snapshot
503+
}
504+
497505
/// Returns an empty snapshot.
498506
public func emptySnapshot() -> OutlineViewDiffableDataSourceSnapshot<ItemIdentifierType> {
499507
.init()
@@ -660,7 +668,7 @@ public class OutlineViewDiffableDataSource<ItemIdentifierType: Hashable>: NSObje
660668
if draggedParent == item as? ItemIdentifierType, let last = draggedIndexes.last, (draggedIndexes + [last+1]).contains(index) {
661669
return []
662670
}
663-
if index == -1, delegate.outlineView(outlineView, isGroupItem: item) {
671+
if index == -1, let item = item, delegate.outlineView(outlineView, isGroupItem: item) {
664672
return []
665673
}
666674
if let item = item as? ItemIdentifierType, draggedItems.contains(where: { currentSnapshot.isDescendant(item, of: $0) }) {

Sources/AdvancedCollectionTableView/DiffableDataSource/NSOutlineView/Snapshot/OutlineViewDiffableDataSourceSnapshot.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ public struct OutlineViewDiffableDataSourceSnapshot<ItemIdentifierType: Hashable
398398
}
399399

400400
/// All descendants of a given item in depth-first order.
401-
private func descendants(of parent: ItemIdentifierType) -> [ItemIdentifierType] {
401+
func descendants(of parent: ItemIdentifierType) -> [ItemIdentifierType] {
402402
var result: [ItemIdentifierType] = []
403403
var stack: [ItemIdentifierType] = [parent]
404404

Sources/AdvancedCollectionTableView/DiffableDataSource/NSOutlineView/Snapshot/OutlineViewDiffableDataSourceTransaction.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import Foundation
99

10+
/// A transaction that describes the changes after reordering the items of a outline view..
1011
public struct OutlineViewDiffableDataSourceTransaction<ItemIdentifierType: Hashable> {
1112
/// The section snapshot before the transaction occured.
1213
public let initialSnapshot: OutlineViewDiffableDataSourceSnapshot<ItemIdentifierType>

0 commit comments

Comments
 (0)