Skip to content

Commit 77ab171

Browse files
committed
Add initial cut for diffable data source.
1 parent 4af196f commit 77ab171

File tree

5 files changed

+882
-2
lines changed

5 files changed

+882
-2
lines changed

Headers/AppKit/AppKit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
#import <AppKit/NSClickGestureRecognizer.h>
164164
#import <AppKit/NSColorPickerTouchBarItem.h>
165165
#import <AppKit/NSCustomTouchBarItem.h>
166+
#import <AppKit/NSDiffableDataSource.h>
166167
#import <AppKit/NSDatePicker.h>
167168
#import <AppKit/NSDatePickerCell.h>
168169
#import <AppKit/NSDockTile.h>
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
NSDiffableDataSource.h
3+
4+
Diffable data source support for NSCollectionView and NSTableView.
5+
6+
Copyright (C) 2026 Free Software Foundation, Inc.
7+
8+
This file is part of the GNUstep GUI Library.
9+
10+
This library is free software; you can redistribute it and/or
11+
modify it under the terms of the GNU Lesser General Public
12+
License as published by the Free Software Foundation; either
13+
version 2 of the License, or (at your option) any later version.
14+
15+
This library is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18+
Lesser General Public License for more details.
19+
20+
You should have received a copy of the GNU Lesser General Public
21+
License along with this library; see the file COPYING.LIB.
22+
If not, see <http://www.gnu.org/licenses/> or write to the
23+
Free Software Foundation, 51 Franklin Street, Fifth Floor,
24+
Boston, MA 02110-1301, USA.
25+
*/
26+
27+
#ifndef _GNUstep_H_NSDiffableDataSource
28+
#define _GNUstep_H_NSDiffableDataSource
29+
#import <AppKit/AppKitDefines.h>
30+
#import <Foundation/Foundation.h>
31+
32+
#if OS_API_VERSION(MAC_OS_X_VERSION_10_15, GS_API_LATEST)
33+
34+
@class NSCollectionView;
35+
@class NSCollectionViewItem;
36+
@class NSTableView;
37+
@class NSTableColumn;
38+
@class NSIndexPath;
39+
@class NSView;
40+
41+
@protocol NSCollectionViewDataSource;
42+
@protocol NSCollectionViewPrefetching;
43+
@protocol NSTableViewDataSource;
44+
45+
APPKIT_EXPORT_CLASS
46+
@interface NSDiffableDataSourceSnapshot : NSObject <NSCopying, NSMutableCopying>
47+
- (NSArray *)sectionIdentifiers;
48+
- (NSArray *)itemIdentifiers;
49+
- (NSArray *)itemIdentifiersInSectionWithIdentifier: (id)sectionIdentifier;
50+
- (NSInteger)numberOfSections;
51+
- (NSInteger)numberOfItems;
52+
- (void)appendSectionsWithIdentifiers: (NSArray *)sectionIdentifiers;
53+
- (void)insertSectionsWithIdentifiers: (NSArray *)sectionIdentifiers
54+
beforeSectionWithIdentifier: (id)sectionIdentifier;
55+
- (void)insertSectionsWithIdentifiers: (NSArray *)sectionIdentifiers
56+
afterSectionWithIdentifier: (id)sectionIdentifier;
57+
- (void)deleteSectionsWithIdentifiers: (NSArray *)sectionIdentifiers;
58+
- (void)moveSectionWithIdentifier: (id)sectionIdentifier
59+
beforeSectionWithIdentifier: (id)otherSectionIdentifier;
60+
- (void)moveSectionWithIdentifier: (id)sectionIdentifier
61+
afterSectionWithIdentifier: (id)otherSectionIdentifier;
62+
- (void)appendItemsWithIdentifiers: (NSArray *)itemIdentifiers;
63+
- (void)appendItemsWithIdentifiers: (NSArray *)itemIdentifiers
64+
intoSectionWithIdentifier: (id)sectionIdentifier;
65+
- (void)insertItemsWithIdentifiers: (NSArray *)itemIdentifiers
66+
beforeItemWithIdentifier: (id)beforeIdentifier;
67+
- (void)insertItemsWithIdentifiers: (NSArray *)itemIdentifiers
68+
afterItemWithIdentifier: (id)afterIdentifier;
69+
- (void)deleteItemsWithIdentifiers: (NSArray *)itemIdentifiers;
70+
- (void)reloadSectionsWithIdentifiers: (NSArray *)sectionIdentifiers;
71+
- (void)reloadItemsWithIdentifiers: (NSArray *)itemIdentifiers;
72+
@end
73+
74+
@protocol NSCollectionViewDiffableItemProvider
75+
- (NSCollectionViewItem *)collectionView: (NSCollectionView *)collectionView
76+
itemForIdentifier: (id)itemIdentifier
77+
atIndexPath: (NSIndexPath *)indexPath;
78+
@end
79+
80+
@protocol NSTableViewDiffableCellProvider
81+
- (NSView *)tableView: (NSTableView *)tableView
82+
viewForIdentifier: (id)itemIdentifier
83+
tableColumn: (NSTableColumn *)tableColumn
84+
row: (NSInteger)row;
85+
@end
86+
87+
APPKIT_EXPORT_CLASS
88+
@interface NSCollectionViewDiffableDataSource : NSObject <NSCollectionViewDataSource, NSCollectionViewPrefetching>
89+
{
90+
NSCollectionView *_collectionView;
91+
NSDiffableDataSourceSnapshot *_snapshot;
92+
id _itemProvider;
93+
NSMutableDictionary *_identifierToIndexPath;
94+
}
95+
- (id)initWithCollectionView: (NSCollectionView *)collectionView
96+
itemProvider: (id)itemProvider;
97+
- (void)applySnapshot: (NSDiffableDataSourceSnapshot *)snapshot
98+
animatingDifferences: (BOOL)animatingDifferences;
99+
- (NSDiffableDataSourceSnapshot *)snapshot;
100+
- (NSIndexPath *)indexPathForItemIdentifier: (id)itemIdentifier;
101+
- (id)itemIdentifierForIndexPath: (NSIndexPath *)indexPath;
102+
@end
103+
104+
APPKIT_EXPORT_CLASS
105+
@interface NSTableViewDiffableDataSource : NSObject <NSTableViewDataSource>
106+
{
107+
NSTableView *_tableView;
108+
NSDiffableDataSourceSnapshot *_snapshot;
109+
id _cellProvider;
110+
NSMutableDictionary *_identifierToIndexPath;
111+
}
112+
- (id)initWithTableView: (NSTableView *)tableView
113+
cellProvider: (id)cellProvider;
114+
- (void)applySnapshot: (NSDiffableDataSourceSnapshot *)snapshot
115+
animatingDifferences: (BOOL)animatingDifferences;
116+
- (NSDiffableDataSourceSnapshot *)snapshot;
117+
- (NSIndexPath *)indexPathForItemIdentifier: (id)itemIdentifier;
118+
- (id)itemIdentifierForIndexPath: (NSIndexPath *)indexPath;
119+
- (id)itemIdentifierForRow: (NSInteger)row;
120+
@end
121+
122+
#endif /* OS_API_VERSION(MAC_OS_X_VERSION_10_15, GS_API_LATEST) */
123+
124+
#endif /* _GNUstep_H_NSDiffableDataSource */

MISSING

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
MISSING HEADERS ( * = difficult, - = quick, + = placeholder, x = won't do )
22
---
33
> NSATSTypesetter.h +
4-
> NSDiffableDataSource.h *
54
> NSDraggingItem.h -
65
> NSDraggingSession.h -
76
> NSFilePromiseProvider.h -
87
> NSFilePromiseReceiver.h -
98
> NSItemProvider.h +
109
> NSOpenGLLayer.h +
1110
> NSTypesetter.h +
12-
> NSUserActivity.h -
1311
> NSWindowTab.h +
1412
> NSWindowTabGroup.h +

Source/GNUmakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ NSController.m \
100100
NSCursor.m \
101101
NSCustomImageRep.m \
102102
NSCustomTouchBarItem.m \
103+
NSDiffableDataSource.m \
103104
NSDataAsset.m \
104105
NSDataLink.m \
105106
NSDataLinkManager.m \
@@ -464,6 +465,7 @@ NSDataLinkPanel.h \
464465
NSDatePicker.h \
465466
NSDatePickerCell.h \
466467
NSDictionaryController.h \
468+
NSDiffableDataSource.h \
467469
NSDockTile.h \
468470
NSDocument.h \
469471
NSDocumentController.h \

0 commit comments

Comments
 (0)