[vlc-commits] [Git][videolan/vlc][master] 10 commits: macosx: Deduplicate context menu setup and presentation in VLCLibraryCollectionViewItem
Felix Paul Kühne (@fkuehne)
gitlab at videolan.org
Sun Jun 2 12:11:31 UTC 2024
Felix Paul Kühne pushed to branch master at VideoLAN / VLC
Commits:
8fa287ca by Claudio Cambra at 2024-06-02T11:57:18+00:00
macosx: Deduplicate context menu setup and presentation in VLCLibraryCollectionViewItem
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
8880dcce by Claudio Cambra at 2024-06-02T11:57:18+00:00
macosx: Replace deprecated NSControlKeyMask with NSEventModifierFlagControl in VLCLibraryCollectionViewItem
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
0f9d3db0 by Claudio Cambra at 2024-06-02T11:57:18+00:00
macosx: Add representedItemsAtIndexPaths method to VLCLibraryCollectionViewDataSource protocol
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
9b711f11 by Claudio Cambra at 2024-06-02T11:57:18+00:00
macosx: If possible, set a collection view's selected items as the represented items for a right-clicked colllection view item's menu
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
a755063b by Claudio Cambra at 2024-06-02T11:57:18+00:00
macosx: Set multiple selection to YES in collection views in library window XIB
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
4a7aa6cf by Claudio Cambra at 2024-06-02T11:57:18+00:00
macosx: Set multiple selection as allowed in library collection view's parent view controllers
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
656d3dc6 by Claudio Cambra at 2024-06-02T11:57:18+00:00
macosx: Fix collapse of supplementary detail view when multiple collection view items deselected
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
86453a3c by Claudio Cambra at 2024-06-02T11:57:18+00:00
macosx: Use XIBs as single source of truth on collection view selection settings
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
611c25ef by Claudio Cambra at 2024-06-02T11:57:18+00:00
macosx: Fix selectability of library collection view items in library window XIB
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
5b983caa by Claudio Cambra at 2024-06-02T11:57:18+00:00
macosx: Fix indentation in VLCLibraryCollectionViewItem rightMouseDown
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
11 changed files:
- modules/gui/macosx/UI/VLCLibraryWindow.xib
- modules/gui/macosx/library/VLCLibraryCollectionViewDataSource.h
- modules/gui/macosx/library/VLCLibraryCollectionViewDelegate.m
- modules/gui/macosx/library/VLCLibraryCollectionViewItem.m
- modules/gui/macosx/library/audio-library/VLCLibraryAudioDataSource.m
- modules/gui/macosx/library/audio-library/VLCLibraryAudioGroupDataSource.m
- modules/gui/macosx/library/audio-library/VLCLibraryAudioViewController.m
- modules/gui/macosx/library/home-library/VLCLibraryHomeViewVideoContainerViewDataSource.m
- modules/gui/macosx/library/home-library/VLCLibraryHomeViewVideoGridContainerView.m
- modules/gui/macosx/library/video-library/VLCLibraryVideoDataSource.m
- modules/gui/macosx/library/video-library/VLCLibraryVideoViewController.m
Changes:
=====================================
modules/gui/macosx/UI/VLCLibraryWindow.xib
=====================================
@@ -626,8 +626,8 @@
<rect key="frame" x="1" y="1" width="867" height="806"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
- <collectionView id="neh-e5-MUa">
- <rect key="frame" x="0.0" y="0.0" width="867" height="158"/>
+ <collectionView selectable="YES" allowsMultipleSelection="YES" id="neh-e5-MUa">
+ <rect key="frame" x="0.0" y="0.0" width="871" height="158"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES"/>
<collectionViewFlowLayout key="collectionViewLayout" minimumInteritemSpacing="10" minimumLineSpacing="10" id="0sw-3B-cXl">
<size key="itemSize" width="50" height="50"/>
@@ -852,7 +852,7 @@
<rect key="frame" x="0.0" y="0.0" width="528" height="411"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
- <collectionView selectable="YES" id="r7v-GI-W1U">
+ <collectionView selectable="YES" allowsMultipleSelection="YES" id="r7v-GI-W1U">
<rect key="frame" x="0.0" y="0.0" width="528" height="411"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES"/>
<collectionViewFlowLayout key="collectionViewLayout" minimumInteritemSpacing="10" minimumLineSpacing="10" id="v0C-1b-7Ss">
@@ -993,7 +993,7 @@
<rect key="frame" x="0.0" y="0.0" width="415" height="390"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
- <collectionView id="ZGR-PZ-7h5">
+ <collectionView selectable="YES" allowsMultipleSelection="YES" id="ZGR-PZ-7h5">
<rect key="frame" x="0.0" y="0.0" width="415" height="390"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES"/>
<collectionViewFlowLayout key="collectionViewLayout" minimumInteritemSpacing="10" minimumLineSpacing="10" id="od3-Iu-ch8">
@@ -1150,7 +1150,7 @@
<rect key="frame" x="0.0" y="0.0" width="714" height="390"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
- <collectionView id="QAt-jP-zE7">
+ <collectionView selectable="YES" allowsMultipleSelection="YES" id="QAt-jP-zE7">
<rect key="frame" x="0.0" y="0.0" width="714" height="390"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES"/>
<collectionViewFlowLayout key="collectionViewLayout" minimumInteritemSpacing="10" minimumLineSpacing="10" id="oKT-Ic-UdV">
=====================================
modules/gui/macosx/library/VLCLibraryCollectionViewDataSource.h
=====================================
@@ -24,6 +24,7 @@
NS_ASSUME_NONNULL_BEGIN
+ at class VLCLibraryRepresentedItem;
@protocol VLCMediaLibraryItemProtocol;
@protocol VLCLibraryCollectionViewDataSource <NSCollectionViewDataSource>
@@ -31,6 +32,9 @@ NS_ASSUME_NONNULL_BEGIN
- (id<VLCMediaLibraryItemProtocol>)libraryItemAtIndexPath:(NSIndexPath *)indexPath
forCollectionView:(NSCollectionView *)collectionView;
- (NSIndexPath *)indexPathForLibraryItem:(id<VLCMediaLibraryItemProtocol>)libraryItem;
+- (NSArray<VLCLibraryRepresentedItem *> *)representedItemsAtIndexPaths:(NSSet<NSIndexPath *> *const)indexPaths
+ forCollectionView:(NSCollectionView *)collectionView;
+
- (void)reloadData;
@optional
=====================================
modules/gui/macosx/library/VLCLibraryCollectionViewDelegate.m
=====================================
@@ -55,14 +55,13 @@
- (void)collectionView:(NSCollectionView *)collectionView didDeselectItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths
{
- NSIndexPath *indexPath = indexPaths.anyObject;
- if (!indexPath) {
- return;
- }
+ VLCLibraryCollectionViewFlowLayout * const collectionViewFlowLayout =
+ (VLCLibraryCollectionViewFlowLayout*)collectionView.collectionViewLayout;
- VLCLibraryCollectionViewFlowLayout *collectionViewFlowLayout = (VLCLibraryCollectionViewFlowLayout*)collectionView.collectionViewLayout;
if (collectionViewFlowLayout) {
- [collectionViewFlowLayout collapseDetailSectionAtIndex:indexPath];
+ for (NSIndexPath * const indexPath in indexPaths) {
+ [collectionViewFlowLayout collapseDetailSectionAtIndex:indexPath];
+ }
}
}
=====================================
modules/gui/macosx/library/VLCLibraryCollectionViewItem.m
=====================================
@@ -283,15 +283,33 @@ const CGFloat VLCLibraryCollectionViewItemMaximumDisplayedProgress = 0.95;
[self.representedItem queue];
}
--(void)mouseDown:(NSEvent *)theEvent
+- (void)openContextMenu:(NSEvent *)event
{
- if (theEvent.modifierFlags & NSControlKeyMask) {
- if (!_menuController) {
- _menuController = [[VLCLibraryMenuController alloc] init];
- }
+ if (!_menuController) {
+ _menuController = [[VLCLibraryMenuController alloc] init];
+ }
+
+ NSCollectionView * const collectionView = self.collectionView;
+ Protocol * const vlcDataSourceProtocol = @protocol(VLCLibraryCollectionViewDataSource);
+
+ if([collectionView.dataSource conformsToProtocol:vlcDataSourceProtocol]) {
+ NSObject<VLCLibraryCollectionViewDataSource> * const dataSource =
+ (NSObject<VLCLibraryCollectionViewDataSource> *)collectionView.dataSource;
+ NSSet<NSIndexPath *> * const indexPaths = collectionView.selectionIndexPaths;
+ NSArray<VLCLibraryRepresentedItem *> * const items =
+ [dataSource representedItemsAtIndexPaths:indexPaths forCollectionView:collectionView];
+ _menuController.representedItems = items;
+ } else {
+ _menuController.representedItems = @[self.representedItem];
+ }
+
+ [_menuController popupMenuWithEvent:event forView:self.view];
+}
- [_menuController setRepresentedItems:@[self.representedItem]];
- [_menuController popupMenuWithEvent:theEvent forView:self.view];
+-(void)mouseDown:(NSEvent *)event
+{
+ if (event.modifierFlags & NSEventModifierFlagControl) {
+ [self openContextMenu:event];
} else if (self.deselectWhenClickedIfSelected &&
self.selected &&
[self.collectionView.dataSource conformsToProtocol:@protocol(VLCLibraryCollectionViewDataSource)]) {
@@ -311,19 +329,13 @@ const CGFloat VLCLibraryCollectionViewItemMaximumDisplayedProgress = 0.95;
}
}
- [super mouseDown:theEvent];
+ [super mouseDown:event];
}
-- (void)rightMouseDown:(NSEvent *)theEvent
+- (void)rightMouseDown:(NSEvent *)event
{
- if (!_menuController) {
- _menuController = [[VLCLibraryMenuController alloc] init];
- }
-
- [_menuController setRepresentedItems:@[self.representedItem]];
- [_menuController popupMenuWithEvent:theEvent forView:self.view];
-
- [super rightMouseDown:theEvent];
+ [self openContextMenu:event];
+ [super rightMouseDown:event];
}
@end
=====================================
modules/gui/macosx/library/audio-library/VLCLibraryAudioDataSource.m
=====================================
@@ -905,4 +905,22 @@ viewForSupplementaryElementOfKind:(NSCollectionViewSupplementaryElementKind)kind
return carouselItemView;
}
+- (NSArray<VLCLibraryRepresentedItem *> *)representedItemsAtIndexPaths:(NSSet<NSIndexPath *> *const)indexPaths
+ forCollectionView:(NSCollectionView *)collectionView
+{
+ NSMutableArray<VLCLibraryRepresentedItem *> * const representedItems =
+ [NSMutableArray arrayWithCapacity:indexPaths.count];
+
+ for (NSIndexPath * const indexPath in indexPaths) {
+ const id<VLCMediaLibraryItemProtocol> libraryItem =
+ [self libraryItemAtIndexPath:indexPath forCollectionView:collectionView];
+ VLCLibraryRepresentedItem * const representedItem =
+ [[VLCLibraryRepresentedItem alloc] initWithItem:libraryItem
+ parentType:self.currentParentType];
+ [representedItems addObject:representedItem];
+ }
+
+ return representedItems;
+}
+
@end
=====================================
modules/gui/macosx/library/audio-library/VLCLibraryAudioGroupDataSource.m
=====================================
@@ -309,4 +309,22 @@ viewForSupplementaryElementOfKind:(NSCollectionViewSupplementaryElementKind)kind
return [NSIndexPath indexPathForItem:arrayIdx inSection:0];
}
+- (NSArray<VLCLibraryRepresentedItem *> *)representedItemsAtIndexPaths:(NSSet<NSIndexPath *> *const)indexPaths
+ forCollectionView:(NSCollectionView *)collectionView
+{
+ NSMutableArray<VLCLibraryRepresentedItem *> * const representedItems =
+ [NSMutableArray arrayWithCapacity:indexPaths.count];
+
+ for (NSIndexPath * const indexPath in indexPaths) {
+ const id<VLCMediaLibraryItemProtocol> libraryItem =
+ [self libraryItemAtIndexPath:indexPath forCollectionView:collectionView];
+ VLCLibraryRepresentedItem * const representedItem =
+ [[VLCLibraryRepresentedItem alloc] initWithItem:libraryItem
+ parentType:self.currentParentType];
+ [representedItems addObject:representedItem];
+ }
+
+ return representedItems;
+}
+
@end
=====================================
modules/gui/macosx/library/audio-library/VLCLibraryAudioViewController.m
=====================================
@@ -181,10 +181,6 @@ NSString *VLCLibraryPlaceholderAudioViewIdentifier = @"VLCLibraryPlaceholderAudi
_audioLibraryCollectionView.dataSource = _audioDataSource;
_audioLibraryCollectionView.delegate = _audioLibraryCollectionViewDelegate;
- _audioLibraryCollectionView.selectable = YES;
- _audioLibraryCollectionView.allowsMultipleSelection = NO;
- _audioLibraryCollectionView.allowsEmptySelection = YES;
-
const CGFloat collectionItemSpacing = VLCLibraryUIUnits.collectionViewItemSpacing;
const NSEdgeInsets collectionViewSectionInset = [VLCLibraryUIUnits collectionViewSectionInsets];
@@ -223,10 +219,6 @@ NSString *VLCLibraryPlaceholderAudioViewIdentifier = @"VLCLibraryPlaceholderAudi
_audioLibraryGridModeSplitViewListSelectionCollectionView.dataSource = _audioGroupDataSource;
_audioLibraryGridModeSplitViewListSelectionCollectionView.delegate = _audioLibraryCollectionViewDelegate;
- _audioLibraryGridModeSplitViewListSelectionCollectionView.selectable = YES;
- _audioLibraryGridModeSplitViewListSelectionCollectionView.allowsMultipleSelection = NO;
- _audioLibraryGridModeSplitViewListSelectionCollectionView.allowsEmptySelection = YES;
-
const CGFloat collectionItemSpacing = VLCLibraryUIUnits.collectionViewItemSpacing;
const NSEdgeInsets collectionViewSectionInset = [VLCLibraryUIUnits collectionViewSectionInsets];
=====================================
modules/gui/macosx/library/home-library/VLCLibraryHomeViewVideoContainerViewDataSource.m
=====================================
@@ -364,6 +364,28 @@ viewForSupplementaryElementOfKind:(NSCollectionViewSupplementaryElementKind)kind
return [NSIndexPath indexPathForItem:libraryItemIndex inSection:0];
}
+- (NSArray<VLCLibraryRepresentedItem *> *)representedItemsAtIndexPaths:(NSSet<NSIndexPath *> *const)indexPaths
+ forCollectionView:(NSCollectionView *)collectionView
+{
+ NSMutableArray<VLCLibraryRepresentedItem *> * const representedItems =
+ [NSMutableArray arrayWithCapacity:indexPaths.count];
+
+ for (NSIndexPath * const indexPath in indexPaths) {
+ const id<VLCMediaLibraryItemProtocol> libraryItem =
+ [self libraryItemAtIndexPath:indexPath forCollectionView:collectionView];
+ // TODO: Find a more elegant way to do this
+ VLCLibraryHomeViewVideoGridContainerView * const containerView =
+ (VLCLibraryHomeViewVideoGridContainerView *)collectionView.superview.superview.superview;
+ NSAssert(containerView != nil, @"The collection view's container view should not be nil!");
+ VLCLibraryRepresentedItem * const representedItem =
+ [[VLCLibraryRepresentedItem alloc] initWithItem:libraryItem
+ parentType:containerView.videoGroup];
+ [representedItems addObject:representedItem];
+ }
+
+ return representedItems;
+}
+
// pragma mark: iCarouselDataSource methods
- (NSInteger)numberOfItemsInCarousel:(iCarousel *)carousel
=====================================
modules/gui/macosx/library/home-library/VLCLibraryHomeViewVideoGridContainerView.m
=====================================
@@ -124,7 +124,7 @@
_collectionView.collectionViewLayout = _collectionViewLayout;
_collectionView.selectable = YES;
_collectionView.allowsEmptySelection = YES;
- _collectionView.allowsMultipleSelection = NO;
+ _collectionView.allowsMultipleSelection = YES;
_collectionViewDelegate = [[VLCLibraryCollectionViewDelegate alloc] init];
_collectionViewDelegate.itemsAspectRatio = VLCLibraryCollectionViewItemAspectRatioVideoItem;
=====================================
modules/gui/macosx/library/video-library/VLCLibraryVideoDataSource.m
=====================================
@@ -419,6 +419,24 @@ NSString * const VLCLibraryVideoDataSourceDisplayedCollectionChangedNotification
return [NSIndexPath indexPathForItem:row inSection:section];
}
+- (NSArray<VLCLibraryRepresentedItem *> *)representedItemsAtIndexPaths:(NSSet<NSIndexPath *> *const)indexPaths
+ forCollectionView:(NSCollectionView *)collectionView
+{
+ NSMutableArray<VLCLibraryRepresentedItem *> * const representedItems =
+ [NSMutableArray arrayWithCapacity:indexPaths.count];
+
+ for (NSIndexPath * const indexPath in indexPaths) {
+ const id<VLCMediaLibraryItemProtocol> libraryItem =
+ [self libraryItemAtIndexPath:indexPath forCollectionView:collectionView];
+ VLCLibraryRepresentedItem * const representedItem =
+ [[VLCLibraryRepresentedItem alloc] initWithItem:libraryItem
+ parentType:self.currentParentType];
+ [representedItems addObject:representedItem];
+ }
+
+ return representedItems;
+}
+
- (NSString *)titleForVideoGroup:(NSInteger)videoGroup
{
switch (videoGroup) {
=====================================
modules/gui/macosx/library/video-library/VLCLibraryVideoViewController.m
=====================================
@@ -163,9 +163,6 @@
_collectionViewLayout.sectionInset = collectionViewSectionInset;
self.videoLibraryCollectionView.collectionViewLayout = _collectionViewLayout;
- self.videoLibraryCollectionView.selectable = YES;
- self.videoLibraryCollectionView.allowsEmptySelection = YES;
- self.videoLibraryCollectionView.allowsMultipleSelection = NO;
_collectionViewDelegate = [[VLCLibraryCollectionViewDelegate alloc] init];
_collectionViewDelegate.itemsAspectRatio = VLCLibraryCollectionViewItemAspectRatioVideoItem;
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/009960d468e356fdb1e67b24ae9e2a4484311f59...5b983caa8ea4904aac44b65b215149665642a7a3
--
This project does not include diff previews in email notifications.
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/009960d468e356fdb1e67b24ae9e2a4484311f59...5b983caa8ea4904aac44b65b215149665642a7a3
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list