|
| 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 */ |
0 commit comments