[vlc-commits] macosx: implement playlist sorting button with a popup menu

Felix Paul Kühne git at videolan.org
Fri May 31 19:58:22 CEST 2019


vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Fri May 31 19:39:55 2019 +0200| [ef6cb8f4aec7f8fc0883aa6e8ecde0b0f6f77414] | committer: Felix Paul Kühne

macosx: implement playlist sorting button with a popup menu

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

 .../package/macosx/VLC.xcodeproj/project.pbxproj   |   6 +
 modules/gui/macosx/Makefile.am                     |   2 +
 modules/gui/macosx/UI/VLCLibraryWindow.xib         |   4 +-
 modules/gui/macosx/library/VLCLibraryWindow.h      |   1 +
 modules/gui/macosx/library/VLCLibraryWindow.m      |  10 ++
 .../playlist/VLCPlaylistSortingMenuController.h    |  33 ++++++
 .../playlist/VLCPlaylistSortingMenuController.m    | 131 +++++++++++++++++++++
 po/POTFILES.in                                     |   2 +
 8 files changed, 187 insertions(+), 2 deletions(-)

diff --git a/extras/package/macosx/VLC.xcodeproj/project.pbxproj b/extras/package/macosx/VLC.xcodeproj/project.pbxproj
index a5d6ad34d0..7afc0f126c 100644
--- a/extras/package/macosx/VLC.xcodeproj/project.pbxproj
+++ b/extras/package/macosx/VLC.xcodeproj/project.pbxproj
@@ -104,6 +104,7 @@
 		7D0F64062202047900FDB91F /* VLCLibraryCollectionViewItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D0F64042202047900FDB91F /* VLCLibraryCollectionViewItem.m */; };
 		7D0F640C2202163E00FDB91F /* VLCPlaylistDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D0F640B2202163E00FDB91F /* VLCPlaylistDataSource.m */; };
 		7D1BF28A22A153E20027C50F /* VLCRoundedCornerTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D1BF28922A153E20027C50F /* VLCRoundedCornerTextField.m */; };
+		7D1BF28D22A192000027C50F /* VLCPlaylistSortingMenuController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D1BF28C22A192000027C50F /* VLCPlaylistSortingMenuController.m */; };
 		7D20081A2289835C002679DF /* VLCTrackingView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D2008192289835C002679DF /* VLCTrackingView.m */; };
 		7D28E6362275B4820098D30E /* NSColor+VLCAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D28E6352275B4820098D30E /* NSColor+VLCAdditions.m */; };
 		7D28E6392275B7340098D30E /* NSFont+VLCAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D28E6382275B7340098D30E /* NSFont+VLCAdditions.m */; };
@@ -452,6 +453,8 @@
 		7D0F640B2202163E00FDB91F /* VLCPlaylistDataSource.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCPlaylistDataSource.m; sourceTree = "<group>"; };
 		7D1BF28822A153E20027C50F /* VLCRoundedCornerTextField.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCRoundedCornerTextField.h; sourceTree = "<group>"; };
 		7D1BF28922A153E20027C50F /* VLCRoundedCornerTextField.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCRoundedCornerTextField.m; sourceTree = "<group>"; };
+		7D1BF28B22A192000027C50F /* VLCPlaylistSortingMenuController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCPlaylistSortingMenuController.h; sourceTree = "<group>"; };
+		7D1BF28C22A192000027C50F /* VLCPlaylistSortingMenuController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCPlaylistSortingMenuController.m; sourceTree = "<group>"; };
 		7D2008182289835C002679DF /* VLCTrackingView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCTrackingView.h; sourceTree = "<group>"; };
 		7D2008192289835C002679DF /* VLCTrackingView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCTrackingView.m; sourceTree = "<group>"; };
 		7D28E6342275B4820098D30E /* NSColor+VLCAdditions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSColor+VLCAdditions.h"; sourceTree = "<group>"; };
@@ -1048,6 +1051,8 @@
 				7D445D832202524D00263D34 /* VLCPlaylistItem.m */,
 				7D445D8C2203375100263D34 /* VLCPlaylistMenuController.h */,
 				7D445D8D2203375100263D34 /* VLCPlaylistMenuController.m */,
+				7D1BF28B22A192000027C50F /* VLCPlaylistSortingMenuController.h */,
+				7D1BF28C22A192000027C50F /* VLCPlaylistSortingMenuController.m */,
 				7D445D852202574B00263D34 /* VLCPlaylistModel.h */,
 				7D445D862202574B00263D34 /* VLCPlaylistModel.m */,
 				7D0F63FD2201F63400FDB91F /* VLCPlaylistTableCellView.h */,
@@ -1682,6 +1687,7 @@
 				7D66D43C2200D6090040D04A /* VLCDetachedVideoWindow.m in Sources */,
 				1C31138E1E508C6900D4DD76 /* VLCAboutWindowController.m in Sources */,
 				1C3113901E508C6900D4DD76 /* VLCHelpWindowController.m in Sources */,
+				7D1BF28D22A192000027C50F /* VLCPlaylistSortingMenuController.m in Sources */,
 				1C3113921E508C6900D4DD76 /* VLCAddonListItem.m in Sources */,
 				7DFBDCB7226CDFD600B700A5 /* VLCImageView.m in Sources */,
 				7D404ABF2281892C00B28EF4 /* NSView+VLCAdditions.m in Sources */,
diff --git a/modules/gui/macosx/Makefile.am b/modules/gui/macosx/Makefile.am
index d8f313a29d..f47f77bdc8 100644
--- a/modules/gui/macosx/Makefile.am
+++ b/modules/gui/macosx/Makefile.am
@@ -149,6 +149,8 @@ libmacosx_plugin_la_SOURCES = \
 	gui/macosx/playlist/VLCPlaylistMenuController.m \
 	gui/macosx/playlist/VLCPlaylistModel.h \
 	gui/macosx/playlist/VLCPlaylistModel.m \
+	gui/macosx/playlist/VLCPlaylistSortingMenuController.h \
+	gui/macosx/playlist/VLCPlaylistSortingMenuController.m \
 	gui/macosx/playlist/VLCPlaylistTableCellView.h \
 	gui/macosx/playlist/VLCPlaylistTableCellView.m \
 	gui/macosx/playlist/VLCPlaylistTableView.h \
diff --git a/modules/gui/macosx/UI/VLCLibraryWindow.xib b/modules/gui/macosx/UI/VLCLibraryWindow.xib
index 86049f80a8..05a1187a45 100644
--- a/modules/gui/macosx/UI/VLCLibraryWindow.xib
+++ b/modules/gui/macosx/UI/VLCLibraryWindow.xib
@@ -23,7 +23,7 @@
                 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                 <subviews>
                     <segmentedControl verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="W1M-0o-qYG">
-                        <rect key="frame" x="212.5" y="333" width="56" height="23"/>
+                        <rect key="frame" x="212" y="333" width="56" height="23"/>
                         <segmentedCell key="cell" borderStyle="border" alignment="left" style="texturedRounded" trackingMode="selectOne" id="Twg-gp-8ng">
                             <font key="font" metaFont="system"/>
                             <segments>
@@ -196,7 +196,7 @@
                                             <font key="font" metaFont="system"/>
                                         </buttonCell>
                                         <connections>
-                                            <action selector="repeatAction:" target="QvC-M9-y7g" id="r9L-pE-b8A"/>
+                                            <action selector="sortPlaylist:" target="QvC-M9-y7g" id="sBc-0X-g5C"/>
                                         </connections>
                                     </button>
                                 </subviews>
diff --git a/modules/gui/macosx/library/VLCLibraryWindow.h b/modules/gui/macosx/library/VLCLibraryWindow.h
index 01ca4893ff..7d1ac8fed6 100644
--- a/modules/gui/macosx/library/VLCLibraryWindow.h
+++ b/modules/gui/macosx/library/VLCLibraryWindow.h
@@ -73,6 +73,7 @@ NS_ASSUME_NONNULL_BEGIN
 - (IBAction)shuffleAction:(id)sender;
 - (IBAction)repeatAction:(id)sender;
 - (IBAction)clearPlaylist:(id)sender;
+- (IBAction)sortPlaylist:(id)sender;
 - (IBAction)openMedia:(id)sender;
 - (IBAction)showAndHidePlaylist:(id)sender;
 
diff --git a/modules/gui/macosx/library/VLCLibraryWindow.m b/modules/gui/macosx/library/VLCLibraryWindow.m
index f9bf5fa646..24bff720a5 100644
--- a/modules/gui/macosx/library/VLCLibraryWindow.m
+++ b/modules/gui/macosx/library/VLCLibraryWindow.m
@@ -29,6 +29,7 @@
 
 #import "playlist/VLCPlaylistController.h"
 #import "playlist/VLCPlaylistDataSource.h"
+#import "playlist/VLCPlaylistSortingMenuController.h"
 
 #import "library/VLCLibraryController.h"
 #import "library/VLCLibraryAudioDataSource.h"
@@ -68,6 +69,7 @@ const CGFloat VLCLibraryWindowDefaultPlaylistWidth = 340.;
     VLCLibraryGroupDataSource *_libraryAudioGroupDataSource;
     VLCMediaSourceDataSource *_mediaSourceDataSource;
     VLCLibraryAlternativeAudioViewController *_alternativeAudioViewController;
+    VLCPlaylistSortingMenuController *_playlistSortingMenuController;
 
     VLCPlaylistController *_playlistController;
 
@@ -403,6 +405,14 @@ const CGFloat VLCLibraryWindowDefaultPlaylistWidth = 340.;
     [_playlistController clearPlaylist];
 }
 
+- (IBAction)sortPlaylist:(id)sender
+{
+    if (!_playlistSortingMenuController) {
+        _playlistSortingMenuController = [[VLCPlaylistSortingMenuController alloc] init];
+    }
+    [NSMenu popUpContextMenu:_playlistSortingMenuController.playlistSortingMenu withEvent:[NSApp currentEvent] forView:sender];
+}
+
 - (IBAction)openMedia:(id)sender
 {
     [[[VLCMain sharedInstance] open] openFileGeneric];
diff --git a/modules/gui/macosx/playlist/VLCPlaylistSortingMenuController.h b/modules/gui/macosx/playlist/VLCPlaylistSortingMenuController.h
new file mode 100644
index 0000000000..0483ccadd6
--- /dev/null
+++ b/modules/gui/macosx/playlist/VLCPlaylistSortingMenuController.h
@@ -0,0 +1,33 @@
+/*****************************************************************************
+ * VLCPlaylistSortingMenuController.h: MacOS X interface module
+ *****************************************************************************
+ * Copyright (C) 2002-2019 VLC authors and VideoLAN
+ *
+ * Authors: Felix Paul Kühne <fkuehne # videolan dot 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 VLCPlaylistSortingMenuController : NSObject
+
+ at property (readonly) NSMenu *playlistSortingMenu;
+
+ at end
+
+NS_ASSUME_NONNULL_END
diff --git a/modules/gui/macosx/playlist/VLCPlaylistSortingMenuController.m b/modules/gui/macosx/playlist/VLCPlaylistSortingMenuController.m
new file mode 100644
index 0000000000..0ba9f6bd46
--- /dev/null
+++ b/modules/gui/macosx/playlist/VLCPlaylistSortingMenuController.m
@@ -0,0 +1,131 @@
+/*****************************************************************************
+ * VLCPlaylistSortingMenuController.m: MacOS X interface module
+ *****************************************************************************
+ * Copyright (C) 2002-2019 VLC authors and VideoLAN
+ *
+ * Authors: Felix Paul Kühne <fkuehne # videolan dot 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 "VLCPlaylistSortingMenuController.h"
+
+#import "extensions/NSString+Helpers.h"
+#import "main/VLCMain.h"
+#import "playlist/VLCPlaylistController.h"
+
+ at interface VLCPlaylistSortingMenuController () <NSMenuDelegate>
+{
+    VLCPlaylistController *_playlistController;
+}
+ at end
+
+ at implementation VLCPlaylistSortingMenuController
+
+- (instancetype)init
+{
+    self = [super init];
+    if (self) {
+        [self createMenu];
+        _playlistController = [[VLCMain sharedInstance] playlistController];
+    }
+    return self;
+}
+
+- (void)createMenu
+{
+    _playlistSortingMenu = [[NSMenu alloc] init];
+
+    NSArray *titles = @[_NS("Title"),
+                        _NS("Duration"),
+                        _NS("Artist"),
+                        _NS("Album"),
+                        _NS("Album Artist"),
+                        _NS("Genre"),
+                        _NS("Date"),
+                        _NS("Track Number"),
+                        _NS("Disc Number"),
+                        _NS("URL"),
+                        _NS("Rating")];
+    NSUInteger count = titles.count;
+    for (NSUInteger x = 0; x < count; x++) {
+        NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:titles[x] action:@selector(selectSortKey:) keyEquivalent:@""];
+        menuItem.target = self;
+        menuItem.tag = x;
+        [_playlistSortingMenu addItem:menuItem];
+    }
+
+    [_playlistSortingMenu addItem:[NSMenuItem separatorItem]];
+
+    titles = @[_NS("Ascending"),
+               _NS("Descending")];
+    count = titles.count;
+    for (NSUInteger x = 0; x < count; x++) {
+        NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:titles[x] action:@selector(selectSortOrder:) keyEquivalent:@""];
+        menuItem.target = self;
+        menuItem.tag = x + 100;
+        [_playlistSortingMenu addItem:menuItem];
+    }
+
+    _playlistSortingMenu.delegate = self;
+}
+
+- (void)menuNeedsUpdate:(NSMenu *)menu
+{
+    if (_playlistController.unsorted) {
+        return;
+    }
+    NSInteger count = _playlistSortingMenu.numberOfItems;
+    for (NSInteger x = 0; x < count; x++) {
+        NSMenuItem *menuItem = [_playlistSortingMenu itemAtIndex:x];
+        menuItem.state = NSOffState;
+    }
+
+    NSMenuItem *menuItem = [_playlistSortingMenu itemWithTag:_playlistController.lastSortKey];
+    menuItem.state = NSOnState;
+
+    menuItem = [_playlistSortingMenu itemWithTag:_playlistController.lastSortOrder + 100];
+    menuItem.state = NSOnState;
+}
+
+- (void)selectSortKey:(id)sender
+{
+    enum vlc_playlist_sort_key sortKey = (enum vlc_playlist_sort_key)[sender tag];
+    enum vlc_playlist_sort_order sortOrder;
+    if (_playlistController.unsorted) {
+        /* we don't have an order and the user can only do a single selection - pick the most popular */
+        sortOrder = VLC_PLAYLIST_SORT_ORDER_ASCENDING;
+    } else {
+        sortOrder = _playlistController.lastSortOrder;
+    }
+
+    [_playlistController sortByKey:sortKey andOrder:sortOrder];
+}
+
+- (void)selectSortOrder:(id)sender
+{
+    enum vlc_playlist_sort_key sortKey;
+    enum vlc_playlist_sort_order sortOrder = (enum vlc_playlist_sort_order)([sender tag] - 100);
+    if (_playlistController.unsorted) {
+        /* we don't have a key and the user can only do a single selection - pick the most popular */
+        sortKey = VLC_PLAYLIST_SORT_KEY_TITLE;
+    } else {
+        sortKey = _playlistController.lastSortKey;
+    }
+
+    [_playlistController sortByKey:sortKey andOrder:sortOrder];
+}
+
+ at end
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 49171fb386..f30a4eeeb2 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -553,6 +553,8 @@ modules/gui/macosx/playlist/VLCPlaylistMenuController.h
 modules/gui/macosx/playlist/VLCPlaylistMenuController.m
 modules/gui/macosx/playlist/VLCPlaylistModel.h
 modules/gui/macosx/playlist/VLCPlaylistModel.m
+modules/gui/macosx/playlist/VLCPlaylistSortingMenuController.h
+modules/gui/macosx/playlist/VLCPlaylistSortingMenuController.m
 modules/gui/macosx/playlist/VLCPlaylistTableCellView.h
 modules/gui/macosx/playlist/VLCPlaylistTableCellView.m
 modules/gui/macosx/playlist/VLCPlaylistTableView.h



More information about the vlc-commits mailing list