[vlc-commits] [Git][videolan/vlc][master] macosx: Add the library context menu to all library tables

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Sat Aug 13 07:11:44 UTC 2022



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
adb9f7c3 by Claudio Cambra at 2022-08-12T22:32:38+00:00
macosx: Add the library context menu to all library tables

Signed-off-by: Claudio Cambra <claudio.cambra at gmail.com>

- - - - -


13 changed files:

- modules/gui/macosx/Makefile.am
- modules/gui/macosx/UI/VLCLibraryCollectionViewAlbumSupplementaryDetailView.xib
- modules/gui/macosx/UI/VLCLibraryWindow.xib
- modules/gui/macosx/library/VLCLibraryAlbumTableCellView.m
- modules/gui/macosx/library/VLCLibraryAlbumTracksDataSource.h
- modules/gui/macosx/library/VLCLibraryAlbumTracksDataSource.m
- modules/gui/macosx/library/VLCLibraryAudioDataSource.h
- modules/gui/macosx/library/VLCLibraryAudioDataSource.m
- modules/gui/macosx/library/VLCLibraryMenuController.h
- modules/gui/macosx/library/VLCLibraryMenuController.m
- modules/gui/macosx/library/VLCLibrarySongTableCellView.h
- + modules/gui/macosx/library/VLCLibraryTableView.h
- + modules/gui/macosx/library/VLCLibraryTableView.m


Changes:

=====================================
modules/gui/macosx/Makefile.am
=====================================
@@ -88,6 +88,8 @@ libmacosx_plugin_la_SOURCES = \
 	gui/macosx/library/VLCLibrarySongTableCellView.m \
 	gui/macosx/library/VLCLibrarySortingMenuController.h \
 	gui/macosx/library/VLCLibrarySortingMenuController.m \
+	gui/macosx/library/VLCLibraryTableView.h \
+	gui/macosx/library/VLCLibraryTableView.m \
 	gui/macosx/library/VLCLibraryTableCellView.h \
 	gui/macosx/library/VLCLibraryTableCellView.m \
 	gui/macosx/library/VLCLibraryVideoDataSource.h \


=====================================
modules/gui/macosx/UI/VLCLibraryCollectionViewAlbumSupplementaryDetailView.xib
=====================================
@@ -112,8 +112,8 @@
                                         <rect key="frame" x="0.0" y="0.0" width="701" height="198"/>
                                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                         <subviews>
-                                            <tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" tableStyle="fullWidth" columnReordering="NO" multipleSelection="NO" autosaveColumns="NO" rowHeight="50" viewBased="YES" id="eEJ-WA-0aM">
-                                                <rect key="frame" x="0.0" y="0.0" width="701" height="188"/>
+                                            <tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" tableStyle="fullWidth" columnReordering="NO" multipleSelection="NO" autosaveColumns="NO" rowHeight="50" viewBased="YES" id="eEJ-WA-0aM" customClass="VLCLibraryTableView">
+                                                <rect key="frame" x="0.0" y="0.0" width="701" height="198"/>
                                                 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                                 <size key="intercellSpacing" width="3" height="2"/>
                                                 <color key="backgroundColor" red="1" green="1" blue="1" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>


=====================================
modules/gui/macosx/UI/VLCLibraryWindow.xib
=====================================
@@ -912,7 +912,7 @@
                                 <rect key="frame" x="0.0" y="0.0" width="312" height="390"/>
                                 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                 <subviews>
-                                    <tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" columnReordering="NO" columnSelection="YES" multipleSelection="NO" autosaveColumns="NO" viewBased="YES" id="LNt-ot-2wU">
+                                    <tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" columnReordering="NO" columnSelection="YES" multipleSelection="NO" autosaveColumns="NO" viewBased="YES" id="LNt-ot-2wU" customClass="VLCLibraryTableView">
                                         <rect key="frame" x="0.0" y="0.0" width="312" height="390"/>
                                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                         <size key="intercellSpacing" width="3" height="2"/>
@@ -971,7 +971,7 @@
                                 <rect key="frame" x="0.0" y="0.0" width="401" height="390"/>
                                 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                 <subviews>
-                                    <tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" tableStyle="fullWidth" columnReordering="NO" multipleSelection="NO" autosaveColumns="NO" rowSizeStyle="automatic" viewBased="YES" id="4ll-T2-J16">
+                                    <tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" tableStyle="fullWidth" columnReordering="NO" multipleSelection="NO" autosaveColumns="NO" rowSizeStyle="automatic" viewBased="YES" id="4ll-T2-J16" customClass="VLCLibraryTableView">
                                         <rect key="frame" x="0.0" y="0.0" width="401" height="390"/>
                                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                         <color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>


=====================================
modules/gui/macosx/library/VLCLibraryAlbumTableCellView.m
=====================================
@@ -30,6 +30,7 @@
 #import "library/VLCLibraryController.h"
 #import "library/VLCLibraryDataTypes.h"
 #import "library/VLCLibraryTableCellView.h"
+#import "library/VLCLibraryTableView.h"
 #import "library/VLCLibraryAlbumTracksDataSource.h"
 
 NSString *VLCAudioLibraryCellIdentifier = @"VLCAudioLibraryCellIdentifier";
@@ -46,7 +47,7 @@ const CGFloat VLCLibraryAlbumTableCellViewSmallSpacing = 5;
 {
     VLCLibraryController *_libraryController;
     VLCLibraryAlbumTracksDataSource *_tracksDataSource;
-    NSTableView *_tracksTableView;
+    VLCLibraryTableView *_tracksTableView;
     NSTableColumn *_column;
 }
 @end
@@ -117,7 +118,7 @@ const CGFloat VLCLibraryAlbumTableCellViewSmallSpacing = 5;
 
 - (void)setupTracksTableView
 {
-    _tracksTableView = [[NSTableView alloc] initWithFrame:NSZeroRect];
+    _tracksTableView = [[VLCLibraryTableView alloc] initWithFrame:NSZeroRect];
     _column = [[NSTableColumn alloc] initWithIdentifier:VLCLibraryAlbumTableCellTableViewColumnIdentifier];
     _column.width = [self expectedTableViewWidth];
     _column.maxWidth = MAXFLOAT;


=====================================
modules/gui/macosx/library/VLCLibraryAlbumTracksDataSource.h
=====================================
@@ -22,11 +22,13 @@
 
 #import <Cocoa/Cocoa.h>
 
+#import "VLCLibraryTableView.h"
+
 NS_ASSUME_NONNULL_BEGIN
 
 @class VLCMediaLibraryAlbum;
 
- at interface VLCLibraryAlbumTracksDataSource : NSObject <NSTableViewDataSource, NSTableViewDelegate>
+ at interface VLCLibraryAlbumTracksDataSource : NSObject <VLCLibraryTableViewDataSource, NSTableViewDelegate>
 
 extern const CGFloat VLCLibraryTracksRowHeight;
 


=====================================
modules/gui/macosx/library/VLCLibraryAlbumTracksDataSource.m
=====================================
@@ -30,6 +30,7 @@
 #import "library/VLCLibraryController.h"
 #import "library/VLCLibraryDataTypes.h"
 #import "library/VLCLibraryTableCellView.h"
+#import "library/VLCLibraryTableView.h"
 #import "library/VLCLibraryAlbumTracksDataSource.h"
 
 const CGFloat VLCLibraryTracksRowHeight = 40.;
@@ -79,8 +80,13 @@ const CGFloat VLCLibraryTracksRowHeight = 40.;
         cellView.identifier = VLCAudioLibrarySongCellIdentifier;
     }
 
-    cellView.representedMediaItem = _tracks[row];
+    cellView.representedMediaItem = (VLCMediaLibraryMediaItem *)[self libraryItemAtRow:row];
     return cellView;
 }
 
+- (id<VLCMediaLibraryItemProtocol>)libraryItemAtRow:(NSInteger)row
+{
+    return _tracks[row];
+}
+
 @end
\ No newline at end of file


=====================================
modules/gui/macosx/library/VLCLibraryAudioDataSource.h
=====================================
@@ -22,13 +22,15 @@
 
 #import <Cocoa/Cocoa.h>
 
+#import "VLCLibraryTableView.h"
+
 NS_ASSUME_NONNULL_BEGIN
 
 @class VLCLibraryModel;
 @class VLCLibraryGroupDataSource;
 @class VLCMediaLibraryAlbum;
 
- at interface VLCLibraryAudioDataSource : NSObject <NSTableViewDataSource, NSTableViewDelegate>
+ at interface VLCLibraryAudioDataSource : NSObject <VLCLibraryTableViewDataSource, NSTableViewDelegate>
 
 @property (readwrite, assign) VLCLibraryModel *libraryModel;
 @property (readwrite, assign) VLCLibraryGroupDataSource *groupDataSource;
@@ -48,7 +50,7 @@ NS_ASSUME_NONNULL_BEGIN
 
 @end
 
- at interface VLCLibraryGroupDataSource : NSObject <NSTableViewDataSource, NSTableViewDelegate>
+ at interface VLCLibraryGroupDataSource : NSObject <VLCLibraryTableViewDataSource, NSTableViewDelegate>
 
 @property (readwrite, retain, nullable) NSArray <VLCMediaLibraryAlbum *> *representedListOfAlbums;
 


=====================================
modules/gui/macosx/library/VLCLibraryAudioDataSource.m
=====================================
@@ -30,6 +30,7 @@
 #import "library/VLCLibraryController.h"
 #import "library/VLCLibraryDataTypes.h"
 #import "library/VLCLibraryTableCellView.h"
+#import "library/VLCLibraryTableView.h"
 #import "library/VLCLibraryAlbumTableCellView.h"
 #import "library/VLCLibraryCollectionViewItem.h"
 #import "library/VLCLibraryCollectionViewFlowLayout.h"
@@ -258,10 +259,15 @@
         cellView.identifier = VLCAudioLibraryCellIdentifier;
     }
 
-    [cellView setRepresentedItem:_displayedCollection[row]];
+    [cellView setRepresentedItem:[self libraryItemAtRow:row]];
     return cellView;
 }
 
+- (id<VLCMediaLibraryItemProtocol>)libraryItemAtRow:(NSInteger)row
+{
+    return _displayedCollection[row];
+}
+
 - (void)tableViewSelectionDidChange:(NSNotification *)notification
 {
     id<VLCMediaLibraryItemProtocol> libraryItem = _displayedCollection[self.collectionSelectionTableView.selectedRow];
@@ -394,12 +400,15 @@ viewForSupplementaryElementOfKind:(NSCollectionViewSupplementaryElementKind)kind
         cellView.identifier = VLCAudioLibraryCellIdentifier;
     }
 
-    VLCMediaLibraryAlbum *album = _representedListOfAlbums[row];
-    cellView.representedAlbum = album;
-
+    cellView.representedAlbum = (VLCMediaLibraryAlbum *)[self libraryItemAtRow:row];
     return cellView;
 }
 
+- (id<VLCMediaLibraryItemProtocol>)libraryItemAtRow:(NSInteger)row
+{
+    return _representedListOfAlbums[row];
+}
+
 - (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row
 {
     VLCLibraryAlbumTableCellView *cellView = (VLCLibraryAlbumTableCellView *)[self tableView:tableView viewForTableColumn:[[NSTableColumn alloc] initWithIdentifier:VLCLibraryAlbumTableCellTableViewColumnIdentifier] row:row];


=====================================
modules/gui/macosx/library/VLCLibraryMenuController.h
=====================================
@@ -28,6 +28,10 @@ NS_ASSUME_NONNULL_BEGIN
 
 @interface VLCLibraryMenuController : NSObject
 
+ at property (readonly) NSMenu *libraryMenu;
+ at property (readonly) NSMenu *minimalMenu;
+ at property (readonly) NSMenu *menuToPresent;
+
 - (void)popupMenuWithEvent:(NSEvent *)theEvent forView:(NSView *)theView;
 - (void)setRepresentedItem:(id<VLCMediaLibraryItemProtocol>)item;
 


=====================================
modules/gui/macosx/library/VLCLibraryMenuController.m
=====================================
@@ -32,7 +32,6 @@
 
 @interface VLCLibraryMenuController ()
 {
-    NSMenu *_libraryMenu;
     VLCLibraryInformationPanel *_informationPanel;
     id<VLCMediaLibraryItemProtocol> _representedItem;
 }
@@ -66,19 +65,20 @@
 
     _libraryMenu = [[NSMenu alloc] initWithTitle:@""];
     [_libraryMenu addMenuItemsFromArray:@[playItem, appendItem, revealItem, deleteItem, informationItem, [NSMenuItem separatorItem], addItem]];
+
+    _minimalMenu = [[NSMenu alloc] initWithTitle:@""];
+    NSMenuItem *addItem2 = [[NSMenuItem alloc] initWithTitle:_NS("Add Media Folder...") action:@selector(addMedia:) keyEquivalent:@""];
+    [_minimalMenu addItem:addItem2];
+}
+
+- (NSMenu *)menuToPresent
+{
+    return _representedItem == nil ? _minimalMenu : _libraryMenu;
 }
 
 - (void)popupMenuWithEvent:(NSEvent *)theEvent forView:(NSView *)theView
 {
-    if (_representedItem != nil) {
-        [NSMenu popUpContextMenu:_libraryMenu withEvent:theEvent forView:theView];
-    } else {
-        NSMenu *minimalMenu = [[NSMenu alloc] initWithTitle:@""];
-        NSMenuItem *addItem = [[NSMenuItem alloc] initWithTitle:_NS("Add Media Folder...") action:@selector(addMedia:) keyEquivalent:@""];
-        addItem.target = self;
-        [minimalMenu addItem:addItem];
-        [NSMenu popUpContextMenu:minimalMenu withEvent:theEvent forView:theView];
-    }
+    [NSMenu popUpContextMenu:[self menuToPresent] withEvent:theEvent forView:theView];
 }
 
 #pragma mark - actions
@@ -88,8 +88,16 @@
         return;
     }
 
+    // We want to add all the tracks to the playlist but only play the first one immediately,
+    // otherwise we will skip straight to the last track of the last album from the artist
+    __block BOOL beginPlayImmediately = playImmediately;
+
     [_representedItem iterateMediaItemsWithBlock:^(VLCMediaLibraryMediaItem* mediaItem) {
-        [[[VLCMain sharedInstance] libraryController] appendItemToPlaylist:mediaItem playImmediately:playImmediately];
+        [[[VLCMain sharedInstance] libraryController] appendItemToPlaylist:mediaItem playImmediately:beginPlayImmediately];
+
+        if(beginPlayImmediately) {
+            beginPlayImmediately = NO;
+        }
     }];
 }
 


=====================================
modules/gui/macosx/library/VLCLibrarySongTableCellView.h
=====================================
@@ -25,7 +25,7 @@
 NS_ASSUME_NONNULL_BEGIN
 
 @class VLCTrackingView;
- at class VLCMediaLibraryItem;
+ at class VLCMediaLibraryMediaItem;
 
 @interface VLCLibrarySongTableCellView : NSTableCellView
 
@@ -37,7 +37,7 @@ extern NSString *VLCAudioLibrarySongCellIdentifier;
 @property (readwrite, assign) IBOutlet NSTextField *trackNumberTextField;
 @property (readwrite, assign) IBOutlet NSButton *playInstantlyButton;
 
- at property (readwrite, assign, nonatomic) VLCMediaLibraryItem *representedMediaItem;
+ at property (readwrite, assign, nonatomic) VLCMediaLibraryMediaItem *representedMediaItem;
 
 - (IBAction)playInstantly:(id)sender;
 


=====================================
modules/gui/macosx/library/VLCLibraryTableView.h
=====================================
@@ -0,0 +1,39 @@
+/*****************************************************************************
+ * VLCLibraryTableView.m: MacOS X interface module
+ *****************************************************************************
+ * Copyright (C) 2022 VLC authors and VideoLAN
+ *
+ * Authors: Claudio Cambra <claudio.cambra at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import <Cocoa/Cocoa.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+ at protocol VLCMediaLibraryItemProtocol;
+
+ at protocol VLCLibraryTableViewDataSource <NSTableViewDataSource>
+
+- (id<VLCMediaLibraryItemProtocol>)libraryItemAtRow:(NSInteger)row;
+
+ at end
+
+ at interface VLCLibraryTableView : NSTableView<NSMenuDelegate>
+
+ at end
+
+NS_ASSUME_NONNULL_END
\ No newline at end of file


=====================================
modules/gui/macosx/library/VLCLibraryTableView.m
=====================================
@@ -0,0 +1,71 @@
+/*****************************************************************************
+ * VLCLibraryTableView.m: MacOS X interface module
+ *****************************************************************************
+ * Copyright (C) 2022 VLC authors and VideoLAN
+ *
+ * Authors: Claudio Cambra <claudio.cambra at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import "VLCLibraryTableView.h"
+#import <library/VLCLibraryDataTypes.h>
+#import "library/VLCLibraryMenuController.h"
+
+ at interface VLCLibraryTableView ()
+{
+    VLCLibraryMenuController *_menuController;
+    BOOL _vlcDataSourceConforming;
+}
+ at end
+
+ at implementation VLCLibraryTableView
+
+- (void)setupMenu
+{
+    if(_menuController == nil) {
+        _menuController = [[VLCLibraryMenuController alloc] init];
+        _menuController.libraryMenu.delegate = self;
+    }
+
+    self.menu = _menuController.libraryMenu;
+}
+
+- (void)setDataSource:(id<NSTableViewDataSource>)dataSource
+{
+    [super setDataSource:dataSource];
+
+    if([self.dataSource conformsToProtocol:@protocol(VLCLibraryTableViewDataSource)]) {
+        _vlcDataSourceConforming = YES;
+        [self setupMenu];
+    } else {
+        _vlcDataSourceConforming = NO;
+        self.menu = nil;
+        _menuController = nil;
+    }
+}
+
+#pragma mark tableview menu delegates
+
+- (void)menuNeedsUpdate:(NSMenu *)menu
+{
+    if(self.clickedRow < 0 || self.dataSource == nil || !_vlcDataSourceConforming) {
+        return;
+    }
+
+    [_menuController setRepresentedItem:[(id<VLCLibraryTableViewDataSource>)self.dataSource libraryItemAtRow:self.clickedRow]];
+}
+
+ at end
\ No newline at end of file



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/adb9f7c3939e513e6ad18850051e92b7ca2fbd38

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/adb9f7c3939e513e6ad18850051e92b7ca2fbd38
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