vlc | branch: master | Felix Paul Kühne <[email protected]> | Fri Jul 5 15:43:55 2019 +0200| [6764184e8b30e2a54e3eb6d447c53ec81a321a76] | committer: Felix Paul Kühne
macosx: add basic implementation to drag library items from the library view to the playlist > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=6764184e8b30e2a54e3eb6d447c53ec81a321a76 --- .../gui/macosx/library/VLCLibraryVideoDataSource.m | 35 ++++++++++++++++++ modules/gui/macosx/library/VLCLibraryWindow.m | 1 + .../gui/macosx/playlist/VLCPlaylistDataSource.h | 1 + .../gui/macosx/playlist/VLCPlaylistDataSource.m | 41 +++++++++++++++++++++- 4 files changed, 77 insertions(+), 1 deletion(-) diff --git a/modules/gui/macosx/library/VLCLibraryVideoDataSource.m b/modules/gui/macosx/library/VLCLibraryVideoDataSource.m index f99d37ffd9..fd3f6afb09 100644 --- a/modules/gui/macosx/library/VLCLibraryVideoDataSource.m +++ b/modules/gui/macosx/library/VLCLibraryVideoDataSource.m @@ -25,6 +25,7 @@ #import "library/VLCLibraryCollectionViewItem.h" #import "library/VLCLibraryCollectionViewSupplementaryElementView.h" #import "library/VLCLibraryModel.h" +#import "library/VLCLibraryDataTypes.h" #import "main/CompatibilityFixes.h" #import "extensions/NSString+Helpers.h" @@ -83,4 +84,38 @@ viewForSupplementaryElementOfKind:(NSCollectionViewSupplementaryElementKind)kind NSLog(@"library selection changed: %@", indexPaths); } +#pragma mark - drag and drop support + +- (BOOL)collectionView:(NSCollectionView *)collectionView +canDragItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths + withEvent:(NSEvent *)event +{ + return YES; +} + +- (BOOL)collectionView:(NSCollectionView *)collectionView +writeItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths + toPasteboard:(NSPasteboard *)pasteboard +{ + NSArray *mediaArray; + if (collectionView == self.recentMediaCollectionView) { + mediaArray = [_libraryModel listOfRecentMedia]; + } else { + mediaArray = [_libraryModel listOfVideoMedia]; + } + + NSMutableArray *mutableArray = [NSMutableArray arrayWithCapacity:indexPaths.count]; + for (NSIndexPath *indexPath in indexPaths) { + VLCMediaLibraryMediaItem *mediaItem = mediaArray[indexPath.item]; + [mutableArray addObject:mediaItem]; + } + + NSData *data = [NSKeyedArchiver archivedDataWithRootObject:mutableArray]; + NSString *pasteboardType = NSStringFromClass([VLCMediaLibraryMediaItem class]); + [pasteboard declareTypes:@[pasteboardType] owner:self]; + [pasteboard setData:data forType:pasteboardType]; + + return YES; +} + @end diff --git a/modules/gui/macosx/library/VLCLibraryWindow.m b/modules/gui/macosx/library/VLCLibraryWindow.m index 79d4b2d8ed..500cebcd55 100644 --- a/modules/gui/macosx/library/VLCLibraryWindow.m +++ b/modules/gui/macosx/library/VLCLibraryWindow.m @@ -196,6 +196,7 @@ static int ShowController(vlc_object_t *p_this, const char *psz_variable, _playlistDataSource.tableView = _playlistTableView; _playlistDataSource.dragDropView = _playlistDragDropView; _playlistDataSource.counterTextField = _playlistCounterTextField; + [_playlistDataSource prepareForUse]; _playlistController.playlistDataSource = _playlistDataSource; _playlistTableView.dataSource = _playlistDataSource; diff --git a/modules/gui/macosx/playlist/VLCPlaylistDataSource.h b/modules/gui/macosx/playlist/VLCPlaylistDataSource.h index 884e195d0b..119fed075c 100644 --- a/modules/gui/macosx/playlist/VLCPlaylistDataSource.h +++ b/modules/gui/macosx/playlist/VLCPlaylistDataSource.h @@ -34,6 +34,7 @@ NS_ASSUME_NONNULL_BEGIN @property (readwrite, assign) VLCDragDropView *dragDropView; @property (readwrite, assign) NSTextField *counterTextField; +- (void)prepareForUse; - (void)playlistUpdated; @end diff --git a/modules/gui/macosx/playlist/VLCPlaylistDataSource.m b/modules/gui/macosx/playlist/VLCPlaylistDataSource.m index 5ccef8232a..c3110fde3c 100644 --- a/modules/gui/macosx/playlist/VLCPlaylistDataSource.m +++ b/modules/gui/macosx/playlist/VLCPlaylistDataSource.m @@ -28,6 +28,8 @@ #import "playlist/VLCPlaylistItem.h" #import "playlist/VLCPlaylistModel.h" #import "views/VLCDragDropView.h" +#import "library/VLCLibraryDataTypes.h" +#import "library/VLCInputItem.h" static NSString *VLCPlaylistCellIdentifier = @"VLCPlaylistCellIdentifier"; @@ -45,6 +47,12 @@ static NSString *VLCPlaylistCellIdentifier = @"VLCPlaylistCellIdentifier"; _playlistModel = _playlistController.playlistModel; } +- (void)prepareForUse +{ + NSString *pasteboardType = NSStringFromClass([VLCMediaLibraryMediaItem class]); + [_tableView registerForDraggedTypes:@[pasteboardType]]; +} + - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView { return _playlistModel.numberOfPlaylistItems; @@ -94,5 +102,36 @@ static NSString *VLCPlaylistCellIdentifier = @"VLCPlaylistCellIdentifier"; [_tableView reloadData]; } -@end +- (NSDragOperation)tableView:(NSTableView *)tableView + validateDrop:(id<NSDraggingInfo>)info + proposedRow:(NSInteger)row + proposedDropOperation:(NSTableViewDropOperation)dropOperation +{ + return NSDragOperationCopy; +} +- (BOOL)tableView:(NSTableView *)tableView + acceptDrop:(id<NSDraggingInfo>)info + row:(NSInteger)row + dropOperation:(NSTableViewDropOperation)dropOperation +{ + NSString *pasteboardType = NSStringFromClass([VLCMediaLibraryMediaItem class]); + NSData *data = [info.draggingPasteboard dataForType:pasteboardType]; + if (!data) { + return NO; + } + NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:data]; + if (!data) { + return NO; + } + NSUInteger arrayCount = array.count; + + for (NSUInteger x = 0; x < arrayCount; x++) { + VLCMediaLibraryMediaItem *mediaItem = array[x]; + [_playlistController addInputItem:mediaItem.inputItem.vlcInputItem atPosition:row startPlayback:NO]; + } + + return YES; +} + +@end _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
