[vlc-commits] macosx: add double-click-to-play to the audio library

Felix Paul Kühne git at videolan.org
Sun Aug 18 20:50:09 CEST 2019


vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Sun Aug 18 20:49:46 2019 +0200| [22f11eeb11ed2291fe975f0119ecadc83d6cad80] | committer: Felix Paul Kühne

macosx: add double-click-to-play to the audio library

This is for the list representation only so far

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=22f11eeb11ed2291fe975f0119ecadc83d6cad80
---

 .../macosx/library/VLCLibraryAlbumTableCellView.m  | 16 ++++++++++
 .../gui/macosx/library/VLCLibraryAudioDataSource.m | 34 ++++++++++++++++++++++
 2 files changed, 50 insertions(+)

diff --git a/modules/gui/macosx/library/VLCLibraryAlbumTableCellView.m b/modules/gui/macosx/library/VLCLibraryAlbumTableCellView.m
index 0c5a93c166..0ec4e14228 100644
--- a/modules/gui/macosx/library/VLCLibraryAlbumTableCellView.m
+++ b/modules/gui/macosx/library/VLCLibraryAlbumTableCellView.m
@@ -78,6 +78,8 @@ const CGFloat LayoutSpacer;
     _tracksDataSource = [[VLCLibraryTracksDataSource alloc] init];
     _tracksTableView.dataSource = _tracksDataSource;
     _tracksTableView.delegate = _tracksDataSource;
+    _tracksTableView.doubleAction = @selector(tracksTableViewDoubleClickAction:);
+    _tracksTableView.target = self;
     [self addSubview:_tracksTableView];
     NSDictionary *dict = NSDictionaryOfVariableBindings(_tracksTableView, _representedImageView);
     [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-20-[_tracksTableView]-20-|" options:0 metrics:0 views:dict]];
@@ -139,6 +141,20 @@ const CGFloat LayoutSpacer;
     [_tracksTableView reloadData];
 }
 
+- (void)tracksTableViewDoubleClickAction:(id)sender
+{
+    if (!_libraryController) {
+        _libraryController = [[VLCMain sharedInstance] libraryController];
+    }
+
+    NSArray *tracks = [_representedAlbum tracksAsMediaItems];
+    NSUInteger trackCount = tracks.count;
+    NSInteger clickedRow = _tracksTableView.clickedRow;
+    if (clickedRow < trackCount) {
+        [_libraryController appendItemToPlaylist:tracks[_tracksTableView.clickedRow] playImmediately:YES];
+    }
+}
+
 @end
 
 @interface VLCLibraryTracksDataSource ()
diff --git a/modules/gui/macosx/library/VLCLibraryAudioDataSource.m b/modules/gui/macosx/library/VLCLibraryAudioDataSource.m
index e9ed995ca7..1626610a94 100644
--- a/modules/gui/macosx/library/VLCLibraryAudioDataSource.m
+++ b/modules/gui/macosx/library/VLCLibraryAudioDataSource.m
@@ -22,7 +22,10 @@
 
 #import "VLCLibraryAudioDataSource.h"
 
+#import "main/VLCMain.h"
+
 #import "library/VLCLibraryModel.h"
+#import "library/VLCLibraryController.h"
 #import "library/VLCLibraryDataTypes.h"
 #import "library/VLCLibraryTableCellView.h"
 #import "library/VLCLibraryAlbumTableCellView.h"
@@ -66,6 +69,9 @@ static NSString *VLCAudioLibraryCellIdentifier = @"VLCAudioLibraryCellIdentifier
     flowLayout.minimumLineSpacing = 20.;
     flowLayout.minimumInteritemSpacing = 20.;
 
+    _groupSelectionTableView.target = self;
+    _groupSelectionTableView.doubleAction = @selector(groubSelectionDoubleClickAction:);
+
     [self reloadAppearance];
 }
 
@@ -273,6 +279,34 @@ static NSString *VLCAudioLibraryCellIdentifier = @"VLCAudioLibraryCellIdentifier
     [self.groupSelectionTableView reloadData];
 }
 
+#pragma mark - table view double click actions
+
+- (void)groubSelectionDoubleClickAction:(id)sender
+{
+    NSArray *listOfAlbums = _groupDataSource.representedListOfAlbums;
+    NSUInteger albumCount = listOfAlbums.count;
+    if (!listOfAlbums || albumCount == 0) {
+        return;
+    }
+
+    NSInteger clickedRow = _groupSelectionTableView.clickedRow;
+    if (clickedRow > albumCount) {
+        return;
+    }
+
+    VLCLibraryController *libraryController = [[VLCMain sharedInstance] libraryController];
+
+    NSArray *tracks = [listOfAlbums[clickedRow] tracksAsMediaItems];
+    NSUInteger trackCount = tracks.count;
+    BOOL playImmediately = YES;
+    for (NSUInteger x = 0; x < trackCount; x++) {
+        [libraryController appendItemToPlaylist:tracks[x] playImmediately:playImmediately];
+        if (playImmediately) {
+            playImmediately = NO;
+        }
+    }
+}
+
 #pragma mark - collection view data source and delegation
 
 - (NSInteger)collectionView:(NSCollectionView *)collectionView



More information about the vlc-commits mailing list