[vlc-commits] [Git][videolan/vlc][master] macosx: library: extract playlist dialog helpers, deduplicate alerts, validate name input
Felix Paul Kühne (@fkuehne)
gitlab at videolan.org
Fri May 29 13:37:23 UTC 2026
Felix Paul Kühne pushed to branch master at VideoLAN / VLC
Commits:
ec5216bd by Serhii Bykov at 2026-05-29T14:55:38+02:00
macosx: library: extract playlist dialog helpers, deduplicate alerts, validate name input
- - - - -
1 changed file:
- modules/gui/macosx/library/VLCLibraryController.m
Changes:
=====================================
modules/gui/macosx/library/VLCLibraryController.m
=====================================
@@ -248,6 +248,8 @@ typedef int (*folder_action_f)(vlc_medialibrary_t*, const char*);
return vlc_ml_clear_history(_p_libraryInstance, VLC_ML_HISTORY_TYPE_GLOBAL);
}
+#pragma mark - Playlist creation
+
- (void)showCreatePlaylistDialogForPlayQueue
{
VLCPlayQueueController * const playQueueController = VLCMain.sharedInstance.playQueueController;
@@ -261,42 +263,67 @@ typedef int (*folder_action_f)(vlc_medialibrary_t*, const char*);
return;
}
+ NSString * const playlistName = [self runCreatePlaylistDialog];
+ if (!playlistName) {
+ return;
+ }
+
+ if (![self createPlaylistWithName:playlistName fromPlayQueueItems:items]) {
+ msg_Err(getIntf(), "Failed to create playlist '%s' from play queue items", playlistName.UTF8String);
+ }
+}
+
+- (void)showCreatePlaylistDialogForMediaItems:(NSArray<VLCMediaLibraryMediaItem *> *)mediaItems
+{
+ if (!mediaItems || mediaItems.count == 0) {
+ return;
+ }
+
+ NSString * const playlistName = [self runCreatePlaylistDialog];
+ if (!playlistName) {
+ return;
+ }
+
+ if (![self createPlaylistWithName:playlistName fromMediaItems:mediaItems]) {
+ msg_Err(getIntf(), "Failed to create playlist '%s' from media items", playlistName.UTF8String);
+ }
+}
+
+- (nullable NSString *)runCreatePlaylistDialog
+{
NSAlert * const alert = [[NSAlert alloc] init];
alert.messageText = _NS("Create New Playlist");
alert.informativeText = _NS("Enter a name for the new playlist:");
- [alert addButtonWithTitle:_NS("Create")];
+ NSButton * const createButton = [alert addButtonWithTitle:_NS("Create")];
+ createButton.enabled = NO;
[alert addButtonWithTitle:_NS("Cancel")];
NSTextField * const input = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 300, 24)];
input.placeholderString = _NS("Playlist Name");
alert.accessoryView = input;
-
alert.window.initialFirstResponder = input;
- const NSModalResponse response = [alert runModal];
- if (response != NSAlertFirstButtonReturn) {
- return;
- }
+ NSCharacterSet * const whitespace = NSCharacterSet.whitespaceAndNewlineCharacterSet;
+ id observer = [NSNotificationCenter.defaultCenter
+ addObserverForName:NSControlTextDidChangeNotification
+ object:input
+ queue:NSOperationQueue.mainQueue
+ usingBlock:^(NSNotification *note) {
+ createButton.enabled = [input.stringValue stringByTrimmingCharactersInSet:whitespace].length > 0;
+ }];
- NSString * const playlistName = input.stringValue;
- if (playlistName.length == 0) {
- return;
- }
+ const NSModalResponse response = [alert runModal];
+ [NSNotificationCenter.defaultCenter removeObserver:observer];
- const BOOL success = [self createPlaylistWithName:playlistName fromItems:items];
- if (success) {
- return;
+ if (response != NSAlertFirstButtonReturn) {
+ return nil;
}
- NSAlert * const errorAlert = [[NSAlert alloc] init];
- errorAlert.messageText = _NS("Failed to Create Playlist");
- errorAlert.informativeText = _NS("The playlist could not be created. Please try again.");
- errorAlert.alertStyle = NSAlertStyleWarning;
- [errorAlert addButtonWithTitle:_NS("OK")];
- [errorAlert runModal];
+ NSString * const name = [input.stringValue stringByTrimmingCharactersInSet:whitespace];
+ return name.length > 0 ? name : nil;
}
-- (BOOL)createPlaylistWithName:(NSString *)playlistName fromItems:(NSArray<VLCPlayQueueItem *> *)items
+- (BOOL)createPlaylistWithName:(NSString *)playlistName fromPlayQueueItems:(NSArray<VLCPlayQueueItem *> *)items
{
if (!_p_libraryInstance || !playlistName || playlistName.length == 0) {
return NO;
@@ -355,47 +382,6 @@ typedef int (*folder_action_f)(vlc_medialibrary_t*, const char*);
return YES;
}
-- (void)showCreatePlaylistDialogForMediaItems:(NSArray<VLCMediaLibraryMediaItem *> *)mediaItems
-{
- if (!mediaItems || mediaItems.count == 0) {
- return;
- }
-
- NSAlert * const alert = [[NSAlert alloc] init];
- alert.messageText = _NS("Create New Playlist");
- alert.informativeText = _NS("Enter a name for the new playlist:");
- [alert addButtonWithTitle:_NS("Create")];
- [alert addButtonWithTitle:_NS("Cancel")];
-
- NSTextField * const input = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 300, 24)];
- input.placeholderString = _NS("Playlist Name");
- alert.accessoryView = input;
-
- alert.window.initialFirstResponder = input;
-
- const NSModalResponse response = [alert runModal];
- if (response != NSAlertFirstButtonReturn) {
- return;
- }
-
- NSString * const playlistName = input.stringValue;
- if (playlistName.length == 0) {
- return;
- }
-
- const BOOL success = [self createPlaylistWithName:playlistName fromMediaItems:mediaItems];
- if (success) {
- return;
- }
-
- NSAlert * const errorAlert = [[NSAlert alloc] init];
- errorAlert.messageText = _NS("Failed to Create Playlist");
- errorAlert.informativeText = _NS("The playlist could not be created. Please try again.");
- errorAlert.alertStyle = NSAlertStyleWarning;
- [errorAlert addButtonWithTitle:_NS("OK")];
- [errorAlert runModal];
-}
-
- (void)sortByCriteria:(enum vlc_ml_sorting_criteria_t)sortCriteria andDescending:(bool)descending
{
_unsorted = NO;
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/ec5216bd84e5bb6a0c0ee7bfc56778fb3f6803a9
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/ec5216bd84e5bb6a0c0ee7bfc56778fb3f6803a9
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help
More information about the vlc-commits
mailing list