[vlc-commits] macosx/playlist: implement playback and deletion through interaction with the table view

Felix Paul Kühne git at videolan.org
Thu Jan 31 16:10:32 CET 2019


vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Thu Jan 31 14:31:14 2019 +0100| [e619a9f9f081b560edaa4784d66dc25c8e9af96b] | committer: Felix Paul Kühne

macosx/playlist: implement playback and deletion through interaction with the table view

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

 .../package/macosx/VLC.xcodeproj/project.pbxproj   | 20 ++++-
 modules/gui/macosx/Makefile.am                     |  1 +
 modules/gui/macosx/UI/VLCLibraryWindow.xib         |  2 +-
 modules/gui/macosx/VLCPlaylistController.h         |  4 +
 modules/gui/macosx/VLCPlaylistController.m         | 26 ++++++-
 modules/gui/macosx/VLCPlaylistTableView.h          | 34 +++++++++
 modules/gui/macosx/VLCPlaylistTableView.m          | 85 ++++++++++++++++++++++
 7 files changed, 166 insertions(+), 6 deletions(-)

diff --git a/extras/package/macosx/VLC.xcodeproj/project.pbxproj b/extras/package/macosx/VLC.xcodeproj/project.pbxproj
index 27381cfe78..b7e71374dc 100644
--- a/extras/package/macosx/VLC.xcodeproj/project.pbxproj
+++ b/extras/package/macosx/VLC.xcodeproj/project.pbxproj
@@ -126,6 +126,7 @@
 		7D445D812202524000263D34 /* VLCPlaylistController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D445D802202524000263D34 /* VLCPlaylistController.m */; };
 		7D445D842202524D00263D34 /* VLCPlaylistItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D445D832202524D00263D34 /* VLCPlaylistItem.m */; };
 		7D445D872202574B00263D34 /* VLCPlaylistModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D445D862202574B00263D34 /* VLCPlaylistModel.m */; };
+		7D445D8B22032B9200263D34 /* VLCPlaylistTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D445D8A22032B9200263D34 /* VLCPlaylistTableView.m */; };
 		7D66D4362200BC340040D04A /* VLCClickerManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D66D4352200BC340040D04A /* VLCClickerManager.m */; };
 		7D66D4392200C5B80040D04A /* VLCVideoFilterHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D66D4382200C5B80040D04A /* VLCVideoFilterHelper.m */; };
 		7D66D43C2200D6090040D04A /* VLCDetachedVideoWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D66D43B2200D6090040D04A /* VLCDetachedVideoWindow.m */; };
@@ -458,6 +459,8 @@
 		7D445D832202524D00263D34 /* VLCPlaylistItem.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCPlaylistItem.m; sourceTree = "<group>"; };
 		7D445D852202574B00263D34 /* VLCPlaylistModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCPlaylistModel.h; sourceTree = "<group>"; };
 		7D445D862202574B00263D34 /* VLCPlaylistModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCPlaylistModel.m; sourceTree = "<group>"; };
+		7D445D8922032B9200263D34 /* VLCPlaylistTableView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCPlaylistTableView.h; sourceTree = "<group>"; };
+		7D445D8A22032B9200263D34 /* VLCPlaylistTableView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCPlaylistTableView.m; sourceTree = "<group>"; };
 		7D5678EB1D5BA1DC002698F3 /* VLCApplication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCApplication.h; sourceTree = "<group>"; };
 		7D5678EC1D5BA1DC002698F3 /* VLCApplication.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCApplication.m; sourceTree = "<group>"; };
 		7D5678EE1D5BA397002698F3 /* VLCMainWindowControlsBar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCMainWindowControlsBar.h; sourceTree = "<group>"; };
@@ -1315,11 +1318,9 @@
 			name = "Open media";
 			sourceTree = "<group>";
 		};
-		7D713D2F2201ADFD0042BEB7 /* Library Window */ = {
+		7D445D8822032B5D00263D34 /* Playlist */ = {
 			isa = PBXGroup;
 			children = (
-				7D713D302201AE350042BEB7 /* VLCLibraryWindow.h */,
-				7D713D312201AE350042BEB7 /* VLCLibraryWindow.m */,
 				7D0F640A2202163E00FDB91F /* VLCPlaylistDataSource.h */,
 				7D0F640B2202163E00FDB91F /* VLCPlaylistDataSource.m */,
 				7D445D7F2202524000263D34 /* VLCPlaylistController.h */,
@@ -1330,6 +1331,18 @@
 				7D445D832202524D00263D34 /* VLCPlaylistItem.m */,
 				7D0F63FD2201F63400FDB91F /* VLCPlaylistTableCellView.h */,
 				7D0F63FE2201F63400FDB91F /* VLCPlaylistTableCellView.m */,
+				7D445D8922032B9200263D34 /* VLCPlaylistTableView.h */,
+				7D445D8A22032B9200263D34 /* VLCPlaylistTableView.m */,
+			);
+			name = Playlist;
+			sourceTree = "<group>";
+		};
+		7D713D2F2201ADFD0042BEB7 /* Library Window */ = {
+			isa = PBXGroup;
+			children = (
+				7D713D302201AE350042BEB7 /* VLCLibraryWindow.h */,
+				7D713D312201AE350042BEB7 /* VLCLibraryWindow.m */,
+				7D445D8822032B5D00263D34 /* Playlist */,
 				7D0F64032202047900FDB91F /* VLCLibraryCollectionViewItem.h */,
 				7D0F64042202047900FDB91F /* VLCLibraryCollectionViewItem.m */,
 			);
@@ -1754,6 +1767,7 @@
 				1C5716AC1F5B142200678627 /* coreaudio_common.c in Sources */,
 				1C3113D51E508C6900D4DD76 /* VLCTextfieldPanelController.m in Sources */,
 				1C3113D71E508C6900D4DD76 /* VLCPopupPanelController.m in Sources */,
+				7D445D8B22032B9200263D34 /* VLCPlaylistTableView.m in Sources */,
 				6B8A6AFE21279D2600DC29F3 /* PXSourceListRuntimeAdditions.m in Sources */,
 				6B8A6B0321279D2600DC29F3 /* PXSourceListBadgeCell.m in Sources */,
 				1C3113D91E508C6900D4DD76 /* VLCSimplePrefsController.m in Sources */,
diff --git a/modules/gui/macosx/Makefile.am b/modules/gui/macosx/Makefile.am
index 140fc30039..47f0fc3f65 100644
--- a/modules/gui/macosx/Makefile.am
+++ b/modules/gui/macosx/Makefile.am
@@ -96,6 +96,7 @@ libmacosx_plugin_la_SOURCES = \
 	gui/macosx/VLCPlaylistItem.h gui/macosx/VLCPlaylistItem.m \
 	gui/macosx/VLCPlaylistModel.h gui/macosx/VLCPlaylistModel.m \
 	gui/macosx/VLCPlaylistTableCellView.h gui/macosx/VLCPlaylistTableCellView.m \
+	gui/macosx/VLCPlaylistTableView.h gui/macosx/VLCPlaylistTableView.m \
 	gui/macosx/VLCLibraryCollectionViewItem.h gui/macosx/VLCLibraryCollectionViewItem.m \
 	gui/macosx/VLCDetachedVideoWindow.h gui/macosx/VLCDetachedVideoWindow.m \
 	gui/macosx/VLCRendererDiscovery.h gui/macosx/VLCRendererDiscovery.m \
diff --git a/modules/gui/macosx/UI/VLCLibraryWindow.xib b/modules/gui/macosx/UI/VLCLibraryWindow.xib
index 7fa27acd4d..899a2a2491 100644
--- a/modules/gui/macosx/UI/VLCLibraryWindow.xib
+++ b/modules/gui/macosx/UI/VLCLibraryWindow.xib
@@ -91,7 +91,7 @@
                                             <rect key="frame" x="0.0" y="0.0" width="237" height="235"/>
                                             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                             <subviews>
-                                                <tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" alternatingRowBackgroundColors="YES" multipleSelection="NO" autosaveColumns="NO" rowSizeStyle="automatic" viewBased="YES" id="Fr1-af-8gb">
+                                                <tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" alternatingRowBackgroundColors="YES" multipleSelection="NO" autosaveColumns="NO" rowSizeStyle="automatic" viewBased="YES" id="Fr1-af-8gb" customClass="VLCPlaylistTableView">
                                                     <rect key="frame" x="0.0" y="0.0" width="237" height="235"/>
                                                     <autoresizingMask key="autoresizingMask"/>
                                                     <size key="intercellSpacing" width="3" height="2"/>
diff --git a/modules/gui/macosx/VLCPlaylistController.h b/modules/gui/macosx/VLCPlaylistController.h
index 63652603cb..18b895db4c 100644
--- a/modules/gui/macosx/VLCPlaylistController.h
+++ b/modules/gui/macosx/VLCPlaylistController.h
@@ -51,6 +51,10 @@ NS_ASSUME_NONNULL_BEGIN
               atPosition:(size_t)insertionIndex
            startPlayback:(BOOL)b_start;
 
+- (void)playItemAtIndex:(size_t)index;
+
+- (void)removeItemAtIndex:(size_t)index;
+
 @end
 
 NS_ASSUME_NONNULL_END
diff --git a/modules/gui/macosx/VLCPlaylistController.m b/modules/gui/macosx/VLCPlaylistController.m
index 878ccb0d6d..30ea4e40cc 100644
--- a/modules/gui/macosx/VLCPlaylistController.m
+++ b/modules/gui/macosx/VLCPlaylistController.m
@@ -168,7 +168,7 @@ static const struct vlc_playlist_callbacks playlist_callbacks = {
         insertionIndex++;
     }
 
-    [_playlistDataSource playlistUpdated];
+    [_playlistDataSource performSelectorOnMainThread:@selector(playlistUpdated) withObject:nil waitUntilDone:NO];
 }
 
 - (void)playlistRemovedItemsAtIndex:(size_t)index count:(size_t)numberOfItems
@@ -178,11 +178,13 @@ static const struct vlc_playlist_callbacks playlist_callbacks = {
     for (size_t i = index + numberOfItems; i > index; i--) {
         [_playlistModel removeItemAtIndex:i];
     }
+
+    [_playlistDataSource performSelectorOnMainThread:@selector(playlistUpdated) withObject:nil waitUntilDone:NO];
 }
 
 - (void)currentPlaylistItemChanged:(ssize_t)index
 {
-    [_playlistDataSource playlistUpdated];
+    [_playlistDataSource performSelectorOnMainThread:@selector(playlistUpdated) withObject:nil waitUntilDone:NO];
 }
 
 #pragma mark - controller functions for use within the UI
@@ -197,6 +199,9 @@ static const struct vlc_playlist_callbacks playlist_callbacks = {
               atPosition:(size_t)insertionIndex
            startPlayback:(BOOL)startPlayback;
 {
+    /* note: we don't add the item as cached data to the model here
+     * because this will be done asynchronously through the callback */
+
     intf_thread_t *p_intf = getIntf();
     NSUInteger numberOfItems = [itemArray count];
 
@@ -245,6 +250,23 @@ static const struct vlc_playlist_callbacks playlist_callbacks = {
     }
 }
 
+- (void)playItemAtIndex:(size_t)index
+{
+    vlc_playlist_Lock(_p_playlist);
+    vlc_playlist_PlayAt(_p_playlist, index);
+    vlc_playlist_Unlock(_p_playlist);
+}
+
+- (void)removeItemAtIndex:(size_t)index
+{
+    /* 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_Unlock(_p_playlist);
+}
+
 #pragma mark - helper methods
 
 - (input_item_t *)createInputItemBasedOnMetadata:(NSDictionary *)itemToCreateDict
diff --git a/modules/gui/macosx/VLCPlaylistTableView.h b/modules/gui/macosx/VLCPlaylistTableView.h
new file mode 100644
index 0000000000..e071e4ee2e
--- /dev/null
+++ b/modules/gui/macosx/VLCPlaylistTableView.h
@@ -0,0 +1,34 @@
+/*****************************************************************************
+ * VLCPlaylistTableView.h: table view subclass for the playlist
+ *****************************************************************************
+ * Copyright (C) 2003-2019 VLC authors and VideoLAN
+ *
+ * Authors: Derk-Jan Hartman <hartman at videola/n dot org>
+ *          Benjamin Pracht <bigben at videolab dot org>
+ *          Felix Paul Kühne <fkuehne at videolan dot org>
+ *          David Fuhrmann <dfuhrmann # videolan.org>
+ *
+ * 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 interface VLCPlaylistTableView : NSTableView
+
+ at end
+
+NS_ASSUME_NONNULL_END
diff --git a/modules/gui/macosx/VLCPlaylistTableView.m b/modules/gui/macosx/VLCPlaylistTableView.m
new file mode 100644
index 0000000000..3d67b1ca6d
--- /dev/null
+++ b/modules/gui/macosx/VLCPlaylistTableView.m
@@ -0,0 +1,85 @@
+/*****************************************************************************
+ * VLCPlaylistTableView.m: table view subclass for the playlist
+ *****************************************************************************
+ * Copyright (C) 2003-2019 VLC authors and VideoLAN
+ *
+ * Authors: Derk-Jan Hartman <hartman at videola/n dot org>
+ *          Benjamin Pracht <bigben at videolab dot org>
+ *          Felix Paul Kühne <fkuehne at videolan dot org>
+ *          David Fuhrmann <dfuhrmann # videolan.org>
+ *
+ * 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 "VLCPlaylistTableView.h"
+#import "VLCMain.h"
+#import "VLCPlaylistController.h"
+
+ at implementation VLCPlaylistTableView
+
+- (NSMenu *)menuForEvent:(NSEvent *)event
+{
+    return nil;
+    // FIXME:   return([(VLCPlaylist *)[self delegate] menuForEvent: event]);
+}
+
+- (void)keyDown:(NSEvent *)event
+{
+    unichar key = 0;
+
+    if ([[event characters] length]) {
+        /* we evaluate the first key only */
+        key = [[event characters] characterAtIndex: 0];
+    }
+
+    size_t indexOfSelectedItem = self.selectedRow;
+
+    switch(key) {
+        case NSDeleteCharacter:
+        case NSDeleteFunctionKey:
+        case NSDeleteCharFunctionKey:
+        case NSBackspaceCharacter:
+            [[[VLCMain sharedInstance] playlistController] removeItemAtIndex:indexOfSelectedItem];
+            break;
+
+        case NSEnterCharacter:
+        case NSCarriageReturnCharacter:
+            [[[VLCMain sharedInstance] playlistController] playItemAtIndex:indexOfSelectedItem];
+            break;
+
+        default:
+            [super keyDown: event];
+            break;
+    }
+}
+
+- (BOOL)acceptsFirstResponder
+{
+    return YES;
+}
+
+- (BOOL)becomeFirstResponder
+{
+    [self setNeedsDisplay:YES];
+    return YES;
+}
+
+- (BOOL)resignFirstResponder
+{
+    [self setNeedsDisplay:YES];
+    return YES;
+}
+
+ at end



More information about the vlc-commits mailing list