vlc | branch: master | David Fuhrmann <[email protected]> | Fri May 31 10:42:45 2019 +0200| [437032b2e936b47f2ad941dc489fc3fd6fce03f9] | committer: David Fuhrmann
macosx: Implement deletion of multiple playlist items Avoids crash when deleting more than one index at once. Uses playlist_RequestDelete to handle concurrent requests from multiple UIs. Fixes deletion also from context menu. closes #22367 > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=437032b2e936b47f2ad941dc489fc3fd6fce03f9 --- modules/gui/macosx/playlist/VLCPlaylistController.h | 6 +++--- modules/gui/macosx/playlist/VLCPlaylistController.m | 16 ++++++++++++++-- modules/gui/macosx/playlist/VLCPlaylistMenuController.m | 7 +++---- modules/gui/macosx/playlist/VLCPlaylistTableView.m | 10 ++-------- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/modules/gui/macosx/playlist/VLCPlaylistController.h b/modules/gui/macosx/playlist/VLCPlaylistController.h index 7276a69ec5..eba43dd114 100644 --- a/modules/gui/macosx/playlist/VLCPlaylistController.h +++ b/modules/gui/macosx/playlist/VLCPlaylistController.h @@ -132,10 +132,10 @@ extern NSString *VLCPlaylistItemsRemoved; startPlayback:(BOOL)startPlayback; /** - * Remove the item at the given index (if any) - * @param index the index to remove + * Remove all items at the given index set + * @param indexes Set of indexes to remove */ -- (void)removeItemAtIndex:(size_t)index; +- (void)removeItemsAtIndexes:(NSIndexSet *)indexes; /** * Clear the entire playlist diff --git a/modules/gui/macosx/playlist/VLCPlaylistController.m b/modules/gui/macosx/playlist/VLCPlaylistController.m index 1597b8ec00..1366004983 100644 --- a/modules/gui/macosx/playlist/VLCPlaylistController.m +++ b/modules/gui/macosx/playlist/VLCPlaylistController.m @@ -395,14 +395,26 @@ static const struct vlc_playlist_callbacks playlist_callbacks = { return ret; } -- (void)removeItemAtIndex:(size_t)index +- (void)removeItemsAtIndexes:(NSIndexSet *)indexes { + if (indexes.count == 0) + return; + + __block vlc_playlist_item_t **items = calloc(indexes.count, sizeof(vlc_playlist_item_t *)); + __block NSUInteger pos = 0; + [indexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) { + VLCPlaylistItem *item = [_playlistModel playlistItemAtIndex:idx]; + items[pos++] = item.playlistItem; + }]; + /* note: we don't remove the cached data from the model here * because this will be done asynchronously through the callback */ vlc_playlist_Lock(_p_playlist); - vlc_playlist_Remove(_p_playlist, index, 1); + vlc_playlist_RequestRemove(_p_playlist, items, pos, indexes.firstIndex); vlc_playlist_Unlock(_p_playlist); + + free(items); } - (void)clearPlaylist diff --git a/modules/gui/macosx/playlist/VLCPlaylistMenuController.m b/modules/gui/macosx/playlist/VLCPlaylistMenuController.m index 4cebe5308b..b145780d47 100644 --- a/modules/gui/macosx/playlist/VLCPlaylistMenuController.m +++ b/modules/gui/macosx/playlist/VLCPlaylistMenuController.m @@ -72,11 +72,10 @@ - (IBAction)remove:(id)sender { - NSInteger selectedRow = self.playlistTableView.selectedRow; + if (self.playlistTableView.selectedRow == -1) + return; - if (selectedRow != -1) { - [_playlistController removeItemAtIndex:selectedRow]; - } + [_playlistController removeItemsAtIndexes:self.playlistTableView.selectedRowIndexes]; } - (IBAction)revealInFinder:(id)sender diff --git a/modules/gui/macosx/playlist/VLCPlaylistTableView.m b/modules/gui/macosx/playlist/VLCPlaylistTableView.m index b3bb79a019..3a814cc2fb 100644 --- a/modules/gui/macosx/playlist/VLCPlaylistTableView.m +++ b/modules/gui/macosx/playlist/VLCPlaylistTableView.m @@ -70,14 +70,8 @@ case NSDeleteCharFunctionKey: case NSBackspaceCharacter: { - if (selectedIndexes.count == 1) { - [[[VLCMain sharedInstance] playlistController] removeItemAtIndex:indexOfSelectedItem]; - } else { - VLCPlaylistController *playlistController = [[VLCMain sharedInstance] playlistController]; - [selectedIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) { - [playlistController removeItemAtIndex:idx]; - }]; - } + VLCPlaylistController *playlistController = [[VLCMain sharedInstance] playlistController]; + [playlistController removeItemsAtIndexes:selectedIndexes]; break; } _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
