[vlc-commits] [Git][videolan/vlc][master] 5 commits: macosx: Extract anyRecents procedure to method
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Wed Aug 2 21:03:48 UTC 2023
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
a3df09e1 by Claudio Cambra at 2023-08-02T20:27:20+00:00
macosx: Extract anyRecents procedure to method
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
a5475d47 by Claudio Cambra at 2023-08-02T20:27:20+00:00
macosx: Extract row adjustment procedure to separate method
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
a2826d5d by Claudio Cambra at 2023-08-02T20:27:20+00:00
macosx: Add convenience method to convert selected row to video group it represents
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
002f76fa by Claudio Cambra at 2023-08-02T20:27:20+00:00
macosx: Store previously-provided number of video library table view sections
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
cbc967ae by Claudio Cambra at 2023-08-02T20:27:20+00:00
macosx: Check recents entry visibility in video library table view when recents are added/deleted
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
1 changed file:
- modules/gui/macosx/library/video-library/VLCLibraryVideoTableViewDataSource.m
Changes:
=====================================
modules/gui/macosx/library/video-library/VLCLibraryVideoTableViewDataSource.m
=====================================
@@ -43,6 +43,7 @@
NSArray *_recentsArray;
NSArray *_libraryArray;
VLCLibraryCollectionViewFlowLayout *_collectionViewFlowLayout;
+ NSUInteger _priorNumVideoSections;
}
@end
@@ -136,6 +137,8 @@
- (void)libraryModelRecentsListReset:(NSNotification * const)aNotification
{
+ [self checkRecentsSection];
+
if (_groupsTableView.selectedRow == -1 ||
_groupsTableView.selectedRow != VLCLibraryVideoRecentsGroup - 1) { // Row 0 == second value in enum, so compensate
@@ -163,6 +166,8 @@
- (void)libraryModelRecentsItemDeleted:(NSNotification * const)aNotification
{
+ [self checkRecentsSection];
+
if (_groupsTableView.selectedRow == -1 ||
_groupsTableView.selectedRow != VLCLibraryVideoRecentsGroup - 1) { // Row 0 == second value in enum, so compensate
@@ -268,20 +273,52 @@
#pragma mark - table view data source and delegation
+- (BOOL)recentItemsPresent
+{
+ return self.libraryModel.numberOfRecentMedia > 0;
+}
+
+- (BOOL)recentsSectionPresent
+{
+ // We display Recents and/or Library. This will need to change if we add more sections.
+ return _priorNumVideoSections == 2;
+}
+
+- (NSUInteger)rowToVideoGroupAdjustment
+{
+ // Group 0 is invalid so we need to adjust the selected row value to match the backing enum.
+ // Additionally, we hide recents when there are no recent media items. Since the recent group
+ // enum value is 1, we need to adjust by more if we are hiding it. Remember the groups are
+ // defined in the desired order.
+ const BOOL anyRecents = [self recentItemsPresent];
+ return anyRecents ? 1 : 2;
+}
+
+- (NSInteger)rowToVideoGroup:(NSInteger)row
+{
+ return row + [self rowToVideoGroupAdjustment];
+}
+
+- (void)checkRecentsSection
+{
+ const BOOL recentsPresent = [self recentItemsPresent];
+ const BOOL recentsVisible = [self recentsSectionPresent];
+
+ if (recentsPresent == recentsVisible) {
+ return;
+ }
+
+ [_groupsTableView reloadData];
+ [self reloadData];
+}
+
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
if (tableView == _groupsTableView) {
- const BOOL anyRecents = self.libraryModel.numberOfRecentMedia > 0;
- return anyRecents ? 2 : 1;
+ _priorNumVideoSections = [self recentItemsPresent] ? 2 : 1;
+ return _priorNumVideoSections;
} else if (tableView == _groupSelectionTableView && _groupsTableView.selectedRow > -1) {
- // Group 0 is invalid so we need to adjust the selected row value to match the backing enum.
- // Additionally, we hide recents when there are no recent media items. Since the recent group
- // enum value is 1, we need to adjust by more if we are hiding it. Remember the groups are
- // defined in the desired order.
- const BOOL anyRecents = self.libraryModel.numberOfRecentMedia > 0;
- const NSUInteger selectedRowAdjustment = anyRecents ? 1 : 2;
-
- switch(_groupsTableView.selectedRow + selectedRowAdjustment) {
+ switch([self rowToVideoGroup:_groupsTableView.selectedRow]) {
case VLCLibraryVideoRecentsGroup:
return _recentsArray.count;
case VLCLibraryVideoLibraryGroup:
@@ -298,7 +335,6 @@
- (id<NSPasteboardWriting>)tableView:(NSTableView *)tableView pasteboardWriterForRow:(NSInteger)row
{
const id<VLCMediaLibraryItemProtocol> libraryItem = [self libraryItemAtRow:row forTableView:tableView];
-
return [NSPasteboardItem pasteboardItemWithLibraryItem:libraryItem];
}
@@ -306,14 +342,7 @@
forTableView:(NSTableView *)tableView
{
if (tableView == _groupSelectionTableView && _groupsTableView.selectedRow > -1) {
- // Group 0 is invalid so we need to adjust the selected row value to match the backing enum.
- // Additionally, we hide recents when there are no recent media items. Since the recent group
- // enum value is 1, we need to adjust by more if we are hiding it. Remember the groups are
- // defined in the desired order.
- const BOOL anyRecents = self.libraryModel.numberOfRecentMedia > 0;
- const NSUInteger rowAdjustment = anyRecents ? 1 : 2;
-
- switch(_groupsTableView.selectedRow + rowAdjustment) {
+ switch([self rowToVideoGroup:_groupsTableView.selectedRow]) {
case VLCLibraryVideoRecentsGroup:
return _recentsArray[row];
case VLCLibraryVideoLibraryGroup:
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/0a5e19e2f9852f5bfa71b695d89e85e5b82d9976...cbc967ae6f8b831e4edd188aebdbe3b46c63d5e5
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/0a5e19e2f9852f5bfa71b695d89e85e5b82d9976...cbc967ae6f8b831e4edd188aebdbe3b46c63d5e5
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