Skip to content

Commit 2669366

Browse files
committed
updated
1 parent 7db7ac5 commit 2669366

File tree

42 files changed

+335
-169
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+335
-169
lines changed

Example/Example/OutlineSidebarViewController.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ class OutlineSidebarViewController: NSViewController {
2525

2626
override func viewDidLoad() {
2727
super.viewDidLoad()
28-
28+
2929
outlineView.dataSource = dataSource
3030

31+
dataSource.applyHeaderRegistration(cellRegistration)
32+
3133
/// Enables reordering selected rows by dragging them.
3234
dataSource.reorderingHandlers.canReorder = { _, _ in return true }
3335

@@ -39,9 +41,10 @@ class OutlineSidebarViewController: NSViewController {
3941

4042
func applySnapshot() {
4143
var snapshot = dataSource.emptySnapshot()
44+
4245
let rootItems: [OutlineItem] = ["Root 1", "Root 2", "Root 3", "Root 4", "Root 5"]
4346
snapshot.append(rootItems)
44-
47+
4548
rootItems.forEach { rootItem in
4649
let childItems = (1...5).map { OutlineItem("\(rootItem.title).\($0)") }
4750
snapshot.append(childItems, to: rootItem)

Example/Example/SidebarViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class TableSidebarViewController: NSViewController {
3838
super.viewDidLoad()
3939

4040
tableView.dataSource = dataSource
41+
dataSource.applySectionHeaderRegistration(sectionHeaderRegistration)
4142

4243
/// Enables reordering selected rows by dragging them.
4344
dataSource.reorderingHandlers.canReorder = { selectedItems in return selectedItems }

Sources/AdvancedCollectionTableView/Configuration/Configurations/NSItemContentConfiguration/NSItemContentView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import FZUIKit
1515

1616
A item content view relies on its item content configuration to supply its styling and content. You create a item content view by passing in a ``NSItemContentConfiguration`` to ``init(configuration:)``. To update the content view, you set a new configuration on it through its ``configuration`` property.
1717

18-
If you’re using a ``AppKit/NSCollectionView`` or ``AppKit/NSTableView``, you don’t need to manually create a item content view to take advantage of the item configuration. Instead, you assign a ``NSItemContentConfiguration`` to the ``AppKit/NSCollectionViewItem/contentConfiguration`` property of the collection view items or table view cells.
18+
If you’re using a [NSCollectionView](https://developer.apple.com/documentation/appkit/nscollectionview) or [NSTableView](https://developer.apple.com/documentation/appkit/nstableview), you don’t need to manually create a item content view to take advantage of the item configuration. Instead, you assign a ``NSItemContentConfiguration`` to the ``AppKit/NSCollectionViewItem/contentConfiguration`` property of the collection view items or table view cells.
1919
*/
2020
open class NSItemContentView: NSView, NSContentView, EditingContentView {
2121

Sources/AdvancedCollectionTableView/Configuration/Configurations/NSListContentConfiguration/NSListContentView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import FZUIKit
1616

1717
A list content view relies on its list content configuration to supply its styling and content. You create a list content view by passing in a ``NSListContentConfiguration`` to ``init(configuration:)``. To update the content view, you set a new configuration on it through its ``configuration`` property.
1818

19-
If you’re using a ``AppKit/NSTableView`` or ``AppKit/NSCollectionView``, you don’t need to manually create a list content view to take advantage of the list configuration. Instead, you assign a ``NSListContentConfiguration`` to the ``AppKit/NSTableCellView/contentConfiguration`` property of the table view cells or collection view items.
19+
If you’re using a [NSTableView](https://developer.apple.com/documentation/appkit/nstableview) or [NSCollectionView](https://developer.apple.com/documentation/appkit/nscollectionview), you don’t need to manually create a list content view to take advantage of the list configuration. Instead, you assign a ``NSListContentConfiguration`` to the ``AppKit/NSTableCellView/contentConfiguration`` property of the table view cells or collection view items.
2020
*/
2121
open class NSListContentView: NSView, NSContentView, EditingContentView {
2222

Sources/AdvancedCollectionTableView/Configuration/Configurations/Shared/TextProperties.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ public struct TextProperties {
108108
public var color: NSUIColor = .labelColor
109109

110110
/// The color transformer for resolving the text color.
111-
public var colorTansform: ColorTransformer?
111+
public var colorTransformer: ColorTransformer?
112112

113113
/// Generates the resolved text color, using the text color and color transformer.
114114
public func resolvedColor() -> NSUIColor {
115-
colorTansform?(color) ?? color
115+
colorTransformer?(color) ?? color
116116
}
117117

118118
/// The tooltip of the text. If set to to an empty string, the text of the textfield is used.
@@ -125,7 +125,7 @@ public struct TextProperties {
125125
var bezel: BezelType = .none
126126

127127
/// The text field bezel.
128-
public enum BezelType: Int, Hashable {
128+
enum BezelType: Int, Hashable {
129129
/// Square bezel.
130130
case square
131131
/// Rounded bezel.
@@ -263,7 +263,7 @@ extension TextProperties: Hashable {
263263
hasher.combine(isEditable)
264264
hasher.combine(isSelectable)
265265
hasher.combine(color)
266-
hasher.combine(colorTansform)
266+
hasher.combine(colorTransformer)
267267
hasher.combine(numberFormatter)
268268
hasher.combine(adjustsFontSizeToFitWidth)
269269
hasher.combine(minimumScaleFactor)

Sources/AdvancedCollectionTableView/DiffableDataSource/NSCollectionView/CollectionViewDiffableDataSource.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import QuickLookUI
1515
A `NSCollectionViewDiffableDataSource` with additional functionality.
1616

1717
The diffable data source provides:
18-
- Reordering elements via ``ReorderingHandlers-swift.struct``.
19-
- Deleting elements via ``DeletingHandlers-swift.struct``.
18+
- Reordering elements via ``reorderingHandlers-swift.property``.
19+
- Deleting elements via ``deletingHandlers-swift.property``.
2020
- Quicklook previews of elements via spacebar by providing elements conforming to `QuicklookPreviewable`.
2121
- A right click menu for selected elements via ``menuProvider``.
2222

@@ -27,7 +27,6 @@ import QuickLookUI
2727
- Highlighting elements via ``highlightHandlers-swift.property``.
2828
- Displaying elements via ``displayHandlers-swift.property``.
2929
- Hovering elements by mouse via ``hoverHandlers-swift.property``.
30-
- Pinching of the collection view via ``pinchHandler``.
3130

3231
### Configurating the data source
3332

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// OutlineItem.swift
3+
//
4+
//
5+
// Created by Florian Zand on 20.01.25.
6+
//
7+
8+
/*
9+
import AppKit
10+
11+
public protocol OutlineItem {
12+
var isGroupRow: Bool { get }
13+
func makeCellView(_ outlineView: NSOutlineView, forColumn tableCoulmn: NSTableColumn, row: Int) -> NSView
14+
}
15+
extension OutlineItem {
16+
public var isGroupRow: Bool {
17+
false
18+
}
19+
}
20+
21+
extension OutlineViewDiffableDataSource {
22+
public convenience init(outlineView: NSOutlineView) where ItemIdentifierType: OutlineItem {
23+
self.init(outlineView: outlineView, cellProvider: {
24+
outlineView, column, item in
25+
item.makeCellView(outlineView, forColumn: column ?? .outline, row: 0)
26+
})
27+
}
28+
}
29+
30+
fileprivate extension NSTableColumn {
31+
static let outline = NSTableColumn()
32+
}
33+
*/

Sources/AdvancedCollectionTableView/DiffableDataSource/NSOutlineView/OutlineViewDiffableDataSource+Delegate.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,15 @@ extension OutlineViewDiffableDataSource {
124124
}
125125

126126
func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? {
127-
dataSource.cellProvider(outlineView, tableColumn, item as! ItemIdentifierType)
127+
if self.outlineView(outlineView, isGroupItem: item), let headerCellProvider = dataSource.headerCellProvider {
128+
return headerCellProvider(outlineView, tableColumn, item as! ItemIdentifierType)
129+
}
130+
return dataSource.cellProvider(outlineView, tableColumn, item as! ItemIdentifierType)
131+
}
132+
133+
func outlineView(_ outlineView: NSOutlineView, isGroupItem item: Any) -> Bool {
134+
guard let item = item as? ItemIdentifierType, dataSource.headerCellProvider != nil else { return false }
135+
return dataSource.currentSnapshot.groupItems.contains(item)
128136
}
129137

130138
init(_ dataSource: OutlineViewDiffableDataSource!) {

Sources/AdvancedCollectionTableView/DiffableDataSource/NSOutlineView/OutlineViewDiffableDataSource.swift

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ import FZSwiftUtils
1414
The object you use to manage data and provide items for a outline view.
1515

1616
The diffable data source provides:
17-
- Expanding/collapsing items via ``ExpansionHandlers-swift.struct``.
18-
- Reordering items via ``ReorderingHandlers-swift.struct``.
19-
- Deleting items via ``DeletingHandlers-swift.struct``.
17+
- Expanding/collapsing items via ``expanionHandlers-swift.property``.
18+
- Reordering items via ``reorderingHandlers-swift.property``.
19+
- Deleting items via ``deletingHandlers-swift.property``.
2020
- Quicklook previews of items via spacebar by providing items conforming to `QuicklookPreviewable`.
2121
- Right click menu provider for selected items via ``menuProvider``.
22-
- Row action provider via ``rowActionProvider``.
2322

2423
__It includes handlers for:__
2524

@@ -54,7 +53,7 @@ public class OutlineViewDiffableDataSource<ItemIdentifierType: Hashable>: NSObje
5453
var draggedIndexes: [Int] = []
5554

5655
/// The closure that configures and returns the outline view’s row views from the diffable data source.
57-
open var rowViewProvider: RowProvider?
56+
open var rowViewProvider: RowViewProvider?
5857

5958
/**
6059
A closure that configures and returns a row view for a outline view from its diffable data source.
@@ -66,7 +65,7 @@ public class OutlineViewDiffableDataSource<ItemIdentifierType: Hashable>: NSObje
6665

6766
- Returns: A configured row view object.
6867
*/
69-
public typealias RowProvider = (_ outlineView: NSOutlineView, _ row: Int, _ item: ItemIdentifierType) -> NSTableRowView
68+
public typealias RowViewProvider = (_ outlineView: NSOutlineView, _ row: Int, _ item: ItemIdentifierType) -> NSTableRowView
7069

7170
/// Applies the row view registration to configure and return outline row views.
7271
open func applyRowViewRegistration<Row: NSTableRowView>(_ registration: NSTableView.RowRegistration<Row, ItemIdentifierType>) {
@@ -75,6 +74,19 @@ public class OutlineViewDiffableDataSource<ItemIdentifierType: Hashable>: NSObje
7574
}
7675
}
7776

77+
open var headerCellProvider: HeaderCellProvider?
78+
79+
/// Uses the specified cell registration to configure and return section header cell views.
80+
open func applyHeaderRegistration<Cell: NSTableCellView>(_ registration: NSTableView.CellRegistration<Cell, ItemIdentifierType>) {
81+
headerCellProvider = { outlineView, column, item in
82+
outlineView.makeCellView(using: registration, forColumn: column ?? .outline, row: 0, item: item)!
83+
}
84+
}
85+
86+
/// ``ExpanionHandlers-swift.struct`` ``expanionHandlers-swift.property``
87+
public typealias HeaderCellProvider = (_ outlineView: NSOutlineView, _ tableColumn: NSTableColumn?, _ identifier: ItemIdentifierType) -> NSView
88+
89+
7890
/**
7991
The right click menu provider.
8092

@@ -548,7 +560,7 @@ public class OutlineViewDiffableDataSource<ItemIdentifierType: Hashable>: NSObje
548560
guard let item = item as? ItemIdentifierType else { return nil }
549561
return NSPasteboardItem(forItem: item)
550562
}
551-
563+
552564
/// Handlers for selecting items.
553565
public struct ExpanionHandlers {
554566
/// The handler that determines if an item should expand. The default value is `nil` which indicates that all items should expand.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
// Created by Florian Zand on 09.01.25.
66
//
77

8+
/*
89
import AppKit
910
import FZSwiftUtils
1011

12+
1113
extension OutlineViewDiffableDataSourceSnapshot where ItemIdentifierType: ExpandingOutlineItem {
1214
public mutating func append(_ items: [ItemIdentifierType], to parent: ItemIdentifierType? = nil) {
1315
validateItems(items + items.flatMap({ $0.descendants() }))
@@ -76,3 +78,4 @@ extension ExpandingOutlineItem {
7678
return nodes
7779
}
7880
}
81+
*/

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public struct OutlineViewDiffableDataSourceSnapshot<ItemIdentifierType: Hashable
3232
struct Node {
3333
var parent: ItemIdentifierType?
3434
var children: [ItemIdentifierType] = []
35-
var isExpanded: Bool = false
35+
var isExpanded = false
36+
var isGroup = false
3637
}
3738

3839
// MARK: - Creating a snapshot
@@ -294,6 +295,8 @@ public struct OutlineViewDiffableDataSourceSnapshot<ItemIdentifierType: Hashable
294295
items.forEach({ nodes[$0]?.isExpanded = false })
295296
}
296297

298+
var groupItems: [ItemIdentifierType] = []
299+
297300
/// Returns a string with an ASCII representation of the snapshot.
298301
public func visualDescription() -> String {
299302
var result = "OutlineViewDiffableDataSourceSnapshot<\(String(describing: ItemIdentifierType.self))>\n"

Sources/AdvancedCollectionTableView/DiffableDataSource/NSTableView/TableViewDiffableDataSource.swift

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ open class TableViewDiffableDataSource<Section, Item>: NSObject, NSTableViewData
9292

9393

9494
/// The closure that configures and returns the table view’s row views from the diffable data source.
95-
open var rowViewProvider: RowProvider? {
95+
open var rowViewProvider: RowViewProvider? {
9696
didSet {
9797
if let rowViewProvider = rowViewProvider {
9898
dataSource.rowViewProvider = { [weak self] tableview, row, identifier in
@@ -115,7 +115,7 @@ open class TableViewDiffableDataSource<Section, Item>: NSObject, NSTableViewData
115115

116116
- Returns: A configured row view object.
117117
*/
118-
public typealias RowProvider = (_ tableView: NSTableView, _ row: Int, _ item: Item) -> NSTableRowView
118+
public typealias RowViewProvider = (_ tableView: NSTableView, _ row: Int, _ item: Item) -> NSTableRowView
119119

120120
/// Applies the row view registration to configure and return table row views.
121121
open func applyRowViewRegistration<Row: NSTableRowView>(_ registration: NSTableView.RowRegistration<Row, Item>) {
@@ -338,6 +338,7 @@ open class TableViewDiffableDataSource<Section, Item>: NSObject, NSTableViewData
338338
})
339339
}
340340

341+
/*
341342
/**
342343
Creates a diffable data source with the specified cell registration, and connects it to the specified table view.
343344

@@ -350,15 +351,16 @@ open class TableViewDiffableDataSource<Section, Item>: NSObject, NSTableViewData
350351
- Parameters:
351352
- tableView: The initialized table view object to connect to the diffable data source.
352353
- cellRegistration: A cell registration which returns each of the cells for the table view from the data the diffable data source provides.
353-
- sectionRegistration: A cell registration which returns each of the table view’s section header views from the data the diffable data source provides.
354+
- sectionHeaderRegistration: A cell registration which returns each of the table view’s section header views from the data the diffable data source provides.
354355
*/
355356
public convenience init<Cell: NSTableCellView, SectionCell: NSTableCellView>(tableView: NSTableView, cellRegistration: NSTableView.CellRegistration<Cell, Item>, sectionHeaderRegistration: NSTableView.CellRegistration<SectionCell, Section>) {
356357
self.init(tableView: tableView, cellProvider: {
357358
tableView, column, row, item in
358359
return tableView.makeCellView(using: cellRegistration, forColumn: column, row: row, item: item)!
359360
})
360361
applySectionHeaderRegistration(sectionHeaderRegistration)
361-
}
362+
}
363+
*/
362364

363365
/**
364366
Creates a diffable data source with the specified cell registrations, and connects it to the specified table view.
@@ -383,6 +385,27 @@ open class TableViewDiffableDataSource<Section, Item>: NSObject, NSTableViewData
383385
})
384386
}
385387

388+
/*
389+
/**
390+
Creates a diffable data source with the specified cell registrations, and connects it to the specified table view.
391+
392+
To connect a diffable data source to a table view, you create the diffable data source using this initializer, passing in the table 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.
393+
394+
```swift
395+
dataSource = TableViewDiffableDataSource<Section, Item>(tableView: tableView, cellRegistrations: cellRegistrations)
396+
```
397+
398+
- Parameters:
399+
- tableView: The initialized table view object to connect to the diffable data source.
400+
- cellRegistrations: Cell registrations which returns each of the cells for the table view from the data the diffable data source provides.
401+
- sectionHeaderRegistration: A cell registration which returns each of the table view’s section header views from the data the diffable data source provides.
402+
*/
403+
public convenience init<SectionCell: NSTableCellView>(tableView: NSTableView, cellRegistrations: [NSTableViewCellRegistration], sectionHeaderRegistration: NSTableView.CellRegistration<SectionCell, Section>) {
404+
self.init(tableView: tableView, cellRegistrations: cellRegistrations)
405+
applySectionHeaderRegistration(sectionHeaderRegistration)
406+
}
407+
*/
408+
386409
/**
387410
Creates a diffable data source with the specified cell provider, and connects it to the specified table view.
388411

Sources/AdvancedCollectionTableView/Documentation/AdvancedCollectionTableView.docc/AdvancedCollectionTableView.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@ A collection of classes and extensions for `NSCollectionView` and `NSTableView`,
88

99
## Topics
1010

11-
### Data Sources
11+
### Collection- & TableView Data Sources
1212

1313
- ``CollectionViewDiffableDataSource``
1414
- ``TableViewDiffableDataSource``
1515
- ``DiffableDataSourceTransaction``
1616
- ``NSDiffableDataSourceSnapshotApplyOption``
1717

18+
### OutlineView Data Source
19+
20+
- ``OutlineViewDiffableDataSource``
21+
- ``OutlineViewDiffableDataSourceSnapshot``
22+
- ``OutlineViewDiffableDataSourceTransaction``
23+
1824
### CollectionView Registration
1925

2026
- ``AppKit/NSCollectionView/ItemRegistration``
@@ -24,7 +30,6 @@ A collection of classes and extensions for `NSCollectionView` and `NSTableView`,
2430

2531
- ``AppKit/NSTableView/CellRegistration``
2632
- ``AppKit/NSTableView/RowRegistration``
27-
- ``AppKit/NSTableView/SectionHeaderRegistration``
2833

2934
### Item Content Configuration
3035

@@ -53,5 +58,4 @@ A collection of classes and extensions for `NSCollectionView` and `NSTableView`,
5358
- <doc:NSTableCellView+>
5459
- <doc:NSTableRowView+>
5560
- <doc:NSTableViewDiffableDataSource+>
56-
- ``NSTableSectionHeaderView``
5761
- ``NSTableViewCellRegistration``

Sources/AdvancedCollectionTableView/Documentation/AdvancedCollectionTableView.docc/Extensions/AppKit Extensions/NSCollecionView/NSCollectionViewItem+.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,3 @@ Extensions for `NSCollectionViewItem`.
2222
- ``AppKit/NSCollectionViewItem/updateConfiguration(using:)``
2323
- ``AppKit/NSCollectionViewItem/configurationUpdateHandler-swift.property``
2424
- ``AppKit/NSCollectionViewItem/ConfigurationUpdateHandler-swift.typealias``
25-
26-
### Managing the view
27-
28-
- ``AppKit/NSCollectionViewItem/loadView()``

Sources/AdvancedCollectionTableView/Documentation/AdvancedCollectionTableView.docc/Extensions/AppKit Extensions/NSTableView/NSTableViewDiffableDataSource+.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Extensions for `NSTableViewDiffableDataSource`.
1313

1414
### Creating Section Views
1515

16-
- ``AppKit/NSTableViewDiffableDataSource/useSectionHeaderViewRegistration(_:)``
16+
- ``applySectionHeaderViewRegistration(_:)``
1717

1818
### Updating data
1919

0 commit comments

Comments
 (0)