macosx: Move delegate methods in VLCLibraryVideoCollectionViewContainerViewDataSource to general VLCLibraryCollectionViewDelegate

Signed-off-by: Claudio Cambra <developer@claudiocambra.com>
This commit is contained in:
Claudio Cambra 2022-12-18 01:46:09 +01:00 committed by Felix Paul Kühne
parent 623d1226fc
commit b069be4532
3 changed files with 47 additions and 58 deletions

View File

@ -22,7 +22,9 @@
#import "VLCLibraryCollectionViewDelegate.h"
#import "VLCLibraryCollectionViewDataSource.h"
#import "VLCLibraryCollectionViewFlowLayout.h"
#import "VLCLibraryDataTypes.h"
@implementation VLCLibraryCollectionViewDelegate
@ -115,4 +117,48 @@
return NSMakeSize(itemWidth, itemWidth + 46); // Text fields height needed
}
- (BOOL)collectionView:(NSCollectionView *)collectionView
canDragItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths
withEvent:(NSEvent *)event
{
return YES;
}
- (BOOL)collectionView:(NSCollectionView *)collectionView
writeItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths
toPasteboard:(NSPasteboard *)pasteboard
{
if (![collectionView.dataSource conformsToProtocol:@protocol(VLCLibraryCollectionViewDataSource)]) {
return NO;
}
NSObject<VLCLibraryCollectionViewDataSource> *vlcDataSource = (NSObject<VLCLibraryCollectionViewDataSource>*)collectionView.dataSource;
NSUInteger numberOfIndexPaths = indexPaths.count;
NSMutableArray *encodedLibraryItemsArray = [NSMutableArray arrayWithCapacity:numberOfIndexPaths];
NSMutableArray *filePathsArray = [NSMutableArray arrayWithCapacity:numberOfIndexPaths];
for (NSIndexPath *indexPath in indexPaths) {
id<VLCMediaLibraryItemProtocol> libraryItem = [vlcDataSource libraryItemAtIndexPath:indexPath
forCollectionView:collectionView];
VLCMediaLibraryMediaItem *mediaItem = libraryItem.firstMediaItem;
[encodedLibraryItemsArray addObject:mediaItem];
VLCMediaLibraryFile *file = mediaItem.files.firstObject;
if (file) {
NSURL *url = [NSURL URLWithString:file.MRL];
[filePathsArray addObject:url.path];
}
}
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:encodedLibraryItemsArray];
[pasteboard declareTypes:@[VLCMediaLibraryMediaItemPasteboardType, NSFilenamesPboardType] owner:self];
[pasteboard setPropertyList:filePathsArray forType:NSFilenamesPboardType];
[pasteboard setData:data forType:VLCMediaLibraryMediaItemPasteboardType];
return YES;
}
@end

View File

@ -29,7 +29,7 @@
NS_ASSUME_NONNULL_BEGIN
@interface VLCLibraryVideoCollectionViewContainerViewDataSource : NSObject <VLCLibraryCollectionViewDataSource, NSCollectionViewDelegate>
@interface VLCLibraryVideoCollectionViewContainerViewDataSource : NSObject <VLCLibraryCollectionViewDataSource>
@property (readwrite, assign) NSCollectionView *collectionView;
@property (readwrite, assign, nonatomic) VLCLibraryVideoCollectionViewGroupDescriptor *groupDescriptor;

View File

@ -104,7 +104,6 @@
_collectionViewFlowLayout = collectionViewLayout;
_collectionView.dataSource = self;
_collectionView.delegate = self;
[_collectionView registerClass:[VLCLibraryCollectionViewItem class]
forItemWithIdentifier:VLCLibraryCellIdentifier];
@ -165,62 +164,6 @@ viewForSupplementaryElementOfKind:(NSCollectionViewSupplementaryElementKind)kind
return nil;
}
- (void)collectionView:(NSCollectionView *)collectionView didSelectItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths
{
NSIndexPath *indexPath = indexPaths.anyObject;
if (!indexPath) {
NSLog(@"Bad index path on item selection");
return;
}
[_collectionViewFlowLayout expandDetailSectionAtIndex:indexPath];
}
- (void)collectionView:(NSCollectionView *)collectionView didDeselectItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths
{
NSIndexPath *indexPath = indexPaths.anyObject;
if (!indexPath) {
NSLog(@"Bad index path on item deselection");
return;
}
[_collectionViewFlowLayout collapseDetailSectionAtIndex:indexPath];
}
- (BOOL)collectionView:(NSCollectionView *)collectionView
canDragItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths
withEvent:(NSEvent *)event
{
return YES;
}
- (BOOL)collectionView:(NSCollectionView *)collectionView
writeItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths
toPasteboard:(NSPasteboard *)pasteboard
{
NSUInteger numberOfIndexPaths = indexPaths.count;
NSMutableArray *encodedLibraryItemsArray = [NSMutableArray arrayWithCapacity:numberOfIndexPaths];
NSMutableArray *filePathsArray = [NSMutableArray arrayWithCapacity:numberOfIndexPaths];
for (NSIndexPath *indexPath in indexPaths) {
VLCMediaLibraryMediaItem *mediaItem = _collectionArray[indexPath.item];
[encodedLibraryItemsArray addObject:mediaItem];
VLCMediaLibraryFile *file = mediaItem.files.firstObject;
if (file) {
NSURL *url = [NSURL URLWithString:file.MRL];
[filePathsArray addObject:url.path];
}
}
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:encodedLibraryItemsArray];
[pasteboard declareTypes:@[VLCMediaLibraryMediaItemPasteboardType, NSFilenamesPboardType] owner:self];
[pasteboard setPropertyList:filePathsArray forType:NSFilenamesPboardType];
[pasteboard setData:data forType:VLCMediaLibraryMediaItemPasteboardType];
return YES;
}
- (id<VLCMediaLibraryItemProtocol>)libraryItemAtIndexPath:(NSIndexPath *)indexPath
forCollectionView:(NSCollectionView *)collectionView
{