Felix Paul Kühne pushed to branch master at VideoLAN / VLC


Commits:
9d63a7ea by Claudio Cambra at 2024-05-26T09:33:21+00:00
macosx: Remove check for selectedRow in playlist menu controller remove

Signed-off-by: Claudio Cambra <[email protected]>

- - - - -
091de38e by Claudio Cambra at 2024-05-26T09:33:21+00:00
macosx: Replace menu controller internal variable in playlist table view with 
private property

Signed-off-by: Claudio Cambra <[email protected]>

- - - - -
9de1c919 by Claudio Cambra at 2024-05-26T09:33:21+00:00
macosx: Present different context menu items for playlist table view depending 
on single/multiple selection

Signed-off-by: Claudio Cambra <[email protected]>

- - - - -
6bfade93 by Claudio Cambra at 2024-05-26T09:33:21+00:00
macosx: Fix crash from double removal of items in playlist menu

Signed-off-by: Claudio Cambra <[email protected]>

- - - - -
677e4d44 by Claudio Cambra at 2024-05-26T09:33:21+00:00
macosx: Do not set menu controller as playlist table view delegate, use 
notifications to track selection changes

Fixes table view cells being borked immediately as the data source is meant to 
be the delegate

Signed-off-by: Claudio Cambra <[email protected]>

- - - - -


4 changed files:

- modules/gui/macosx/UI/VLCLibraryWindowPlaylistView.xib
- modules/gui/macosx/playlist/VLCPlaylistMenuController.h
- modules/gui/macosx/playlist/VLCPlaylistMenuController.m
- modules/gui/macosx/playlist/VLCPlaylistTableView.m


Changes:

=====================================
modules/gui/macosx/UI/VLCLibraryWindowPlaylistView.xib
=====================================
@@ -53,7 +53,7 @@
                         <rect key="frame" x="0.0" y="0.0" width="510" 
height="194"/>
                         <autoresizingMask key="autoresizingMask" 
widthSizable="YES" heightSizable="YES"/>
                         <subviews>
-                            <tableView verticalHuggingPriority="750" 
allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" 
multipleSelection="NO" autosaveColumns="NO" rowHeight="16" 
rowSizeStyle="automatic" viewBased="YES" id="Ubg-RS-LWE" 
customClass="VLCPlaylistTableView">
+                            <tableView verticalHuggingPriority="750" 
allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" 
autosaveColumns="NO" rowHeight="16" rowSizeStyle="automatic" viewBased="YES" 
id="Ubg-RS-LWE" customClass="VLCPlaylistTableView">
                                 <rect key="frame" x="0.0" y="0.0" width="510" 
height="194"/>
                                 <autoresizingMask key="autoresizingMask" 
widthSizable="YES" heightSizable="YES"/>
                                 <size key="intercellSpacing" width="3" 
height="2"/>


=====================================
modules/gui/macosx/playlist/VLCPlaylistMenuController.h
=====================================
@@ -28,7 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
 
 @interface VLCPlaylistMenuController : NSObject
 
-@property (readwrite, weak) NSTableView *playlistTableView;
+@property (readwrite, weak, nonatomic) NSTableView *playlistTableView;
 @property (readonly) NSMenu *playlistMenu;
 
 @end


=====================================
modules/gui/macosx/playlist/VLCPlaylistMenuController.m
=====================================
@@ -48,6 +48,10 @@
     NSMenuItem *_clearPlaylistMenuItem;
     NSMenuItem *_sortMenuItem;
 }
+
+@property (readwrite, atomic) NSArray<NSMenuItem *> *items;
+@property (readwrite, atomic) NSArray<NSMenuItem *> *multipleSelectionItems;
+
 @end
 
 @implementation VLCPlaylistMenuController
@@ -86,8 +90,44 @@
     _sortMenuItem = [[NSMenuItem alloc] initWithTitle:_NS("Sort") action:nil 
keyEquivalent:@""];
     [_sortMenuItem 
setSubmenu:_playlistSortingMenuController.playlistSortingMenu];
 
+    self.items = @[
+        _playMenuItem,
+        _removeMenuItem,
+        _revealInFinderMenuItem,
+        _informationMenuItem,
+        NSMenuItem.separatorItem,
+        _addFilesToPlaylistMenuItem,
+        _clearPlaylistMenuItem,
+        _sortMenuItem
+    ];
+
+    self.multipleSelectionItems = @[
+        _removeMenuItem,
+        NSMenuItem.separatorItem,
+        _addFilesToPlaylistMenuItem,
+        _clearPlaylistMenuItem,
+        _sortMenuItem
+    ];
+
     _playlistMenu = [[NSMenu alloc] init];
-    [_playlistMenu addMenuItemsFromArray:@[_playMenuItem, _removeMenuItem, 
_revealInFinderMenuItem, _informationMenuItem, [NSMenuItem separatorItem], 
_addFilesToPlaylistMenuItem, _clearPlaylistMenuItem, _sortMenuItem]];
+    _playlistMenu.itemArray = self.items;
+}
+
+- (void)setPlaylistTableView:(NSTableView *)playlistTableView
+{
+    NSNotificationCenter * const notificationCenter = 
NSNotificationCenter.defaultCenter;
+    if (self.playlistTableView != nil) {
+        [notificationCenter removeObserver:self
+                                      
name:NSTableViewSelectionDidChangeNotification
+                                    object:self.playlistTableView];
+    }
+
+    _playlistTableView = playlistTableView;
+    [notificationCenter addObserver:self
+                           selector:@selector(tableViewSelectionDidChange:)
+                               name:NSTableViewSelectionDidChangeNotification
+                             object:self.playlistTableView];
+
 }
 
 - (void)play:(id)sender
@@ -103,9 +143,6 @@
 
 - (void)remove:(id)sender
 {
-    if (self.playlistTableView.selectedRow == -1)
-        return;
-
     [_playlistController 
removeItemsAtIndexes:self.playlistTableView.selectedRowIndexes];
 }
 
@@ -180,4 +217,19 @@
     return NO;
 }
 
+- (void)tableViewSelectionDidChange:(NSNotification *)notification
+{
+    NSTableView * const tableView = notification.object;
+    if (tableView != self.playlistTableView) {
+        return;
+    }
+
+    const BOOL multipleSelection = tableView.selectedRowIndexes.count > 1;
+    if (multipleSelection) {
+        self.playlistMenu.itemArray = self.multipleSelectionItems;
+    } else {
+        self.playlistMenu.itemArray = self.items;
+    }
+}
+
 @end


=====================================
modules/gui/macosx/playlist/VLCPlaylistTableView.m
=====================================
@@ -30,18 +30,18 @@
 #import "playlist/VLCPlaylistMenuController.h"
 
 @interface VLCPlaylistTableView ()
-{
-    VLCPlaylistMenuController *_menuController;
-}
+
+@property (readonly, atomic) VLCPlaylistMenuController *menuController;
+
 @end
 
 @implementation VLCPlaylistTableView
 
 - (NSMenu *)menuForEvent:(NSEvent *)event
 {
-    if (!_menuController) {
+    if (self.menuController == nil) {
         _menuController = [[VLCPlaylistMenuController alloc] init];
-        _menuController.playlistTableView = self;
+        self.menuController.playlistTableView = self;
     }
 
     NSPoint pt = [self convertPoint: [event locationInWindow] fromView: nil];
@@ -49,7 +49,7 @@
     if (row != -1 && ![[self selectedRowIndexes] containsIndex: row])
         [self selectRowIndexes:[NSIndexSet indexSetWithIndex:row] 
byExtendingSelection:NO];
 
-    return _menuController.playlistMenu;
+    return self.menuController.playlistMenu;
 }
 
 - (void)keyDown:(NSEvent *)event



View it on GitLab: 
https://code.videolan.org/videolan/vlc/-/compare/1d4b4e528dcf72df44b09df9bc41869d96e44017...677e4d447ec45b8b990e79e1993f5743e2cd604e

-- 
This project does not include diff previews in email notifications.
View it on GitLab: 
https://code.videolan.org/videolan/vlc/-/compare/1d4b4e528dcf72df44b09df9bc41869d96e44017...677e4d447ec45b8b990e79e1993f5743e2cd604e
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance
_______________________________________________
vlc-commits mailing list
[email protected]
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to