Browse Source

macosx: Add new header delegate property to audio data source

Signed-off-by: Claudio Cambra <developer@claudiocambra.com>
pull/192/head
Claudio Cambra 9 months ago
committed by Steve Lhomme
parent
commit
ce3ffce98e
  1. 5
      modules/gui/macosx/library/audio-library/VLCLibraryAudioDataSource.h
  2. 51
      modules/gui/macosx/library/audio-library/VLCLibraryAudioDataSource.m

5
modules/gui/macosx/library/audio-library/VLCLibraryAudioDataSource.h

@ -24,6 +24,7 @@
#import "library/VLCLibraryCollectionViewDataSource.h"
#import "library/VLCLibraryTableViewDataSource.h"
#import "library/audio-library/VLCLibraryAudioDataSourceHeaderDelegate.h"
#include "views/iCarousel/iCarousel.h"
@ -60,6 +61,8 @@ extern NSString * const VLCLibraryYearSortDescriptorKey;
extern NSString * const VLCLibraryAudioDataSourceDisplayedCollectionChangedNotification;
@class VLCLibraryRepresentedItem;
@interface VLCLibraryAudioDataSource : NSObject <VLCLibraryTableViewDataSource, VLCLibraryCollectionViewDataSource, iCarouselDataSource>
@property (readwrite, weak) VLCLibraryModel *libraryModel;
@ -68,6 +71,7 @@ extern NSString * const VLCLibraryAudioDataSourceDisplayedCollectionChangedNotif
@property (readwrite, weak) NSCollectionView *collectionView;
@property (readwrite, weak) iCarousel *carouselView;
@property (readwrite, weak) NSTableView *gridModeListTableView;
@property (readwrite, weak, nullable) id<VLCLibraryAudioDataSourceHeaderDelegate> headerDelegate;
@property (nonatomic, readwrite, assign) VLCAudioLibrarySegment audioLibrarySegment;
@property (readwrite, strong) VLCLibraryAudioGroupDataSource *audioGroupDataSource;
@ -80,6 +84,7 @@ extern NSString * const VLCLibraryAudioDataSourceDisplayedCollectionChangedNotif
- (void)setup;
- (void)reloadData;
- (void)tableView:(NSTableView * const)tableView selectRowIndices:(NSIndexSet * const)indices;
- (void)applySelectionForTableView:(NSTableView *)tableView;
@end

51
modules/gui/macosx/library/audio-library/VLCLibraryAudioDataSource.m

@ -693,6 +693,48 @@ NSString * const VLCLibraryAudioDataSourceDisplayedCollectionChangedNotification
return self.displayedCollection[row];
}
- (void)applySelectionForTableView:(NSTableView *)tableView
{
if (tableView == nil ||
(tableView != self.collectionSelectionTableView && tableView != self.gridModeListTableView)) {
return;
}
const NSInteger selectedRow = tableView.selectedRow;
if (selectedRow >= 0 && (NSUInteger)selectedRow >= self.displayedCollection.count) {
return;
}
const BOOL shouldClearSelection = self.currentParentType == VLCMediaLibraryParentGroupTypeAudioLibrary ||
self.currentParentType == VLCMediaLibraryParentGroupTypeRecentAudios ||
selectedRow < 0 ||
self.displayedCollectionUpdating;
const id<VLCMediaLibraryAudioGroupProtocol> selectedItem =
shouldClearSelection ? nil : self.displayedCollection[selectedRow];
self.audioGroupDataSource.representedAudioGroup = selectedItem;
VLCLibraryRepresentedItem *representedItem = nil;
NSString *fallbackTitle = nil;
NSString *fallbackDetail = nil;
if (self.displayAllArtistsGenresTableEntry && selectedRow == 0) {
fallbackTitle = (self.currentParentType == VLCMediaLibraryParentGroupTypeGenre)
? _NS("All genres")
: _NS("All artists");
} else if (selectedItem != nil) {
representedItem = [[VLCLibraryRepresentedItem alloc] initWithItem:selectedItem parentType:self.currentParentType];
fallbackTitle = selectedItem.displayString;
fallbackDetail = selectedItem.primaryDetailString;
}
[self.headerDelegate audioDataSource:self
updateHeaderForTableView:tableView
withRepresentedItem:representedItem
fallbackTitle:fallbackTitle
fallbackDetail:fallbackDetail];
}
- (void)tableView:(NSTableView * const)tableView selectRowIndices:(NSIndexSet * const)indices
{
NSParameterAssert(tableView);
@ -711,14 +753,7 @@ NSString * const VLCLibraryAudioDataSourceDisplayedCollectionChangedNotification
return;
}
if (self.currentParentType == VLCMediaLibraryParentGroupTypeAudioLibrary ||
self.currentParentType == VLCMediaLibraryParentGroupTypeRecentAudios ||
selectedRow < 0 ||
self.displayedCollectionUpdating) {
self.audioGroupDataSource.representedAudioGroup = nil;
} else {
self.audioGroupDataSource.representedAudioGroup = self.displayedCollection[selectedRow];
}
[self applySelectionForTableView:tableView];
}
- (void)tableView:(NSTableView *)tableView sortDescriptorsDidChange:(NSArray<NSSortDescriptor *> *)oldDescriptors

Loading…
Cancel
Save