[vlc-commits] macosx: modernize the remaining sheet dialogs

Felix Paul Kühne git at videolan.org
Sun Jun 10 18:31:33 CEST 2018


vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Sun Jun 10 18:04:32 2018 +0200| [fbb8a437f2e94ea0de38f64648f65a318dbe40f0] | committer: Felix Paul Kühne

macosx: modernize the remaining sheet dialogs

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

 modules/gui/macosx/VLCBookmarksWindowController.m  |  2 +-
 .../gui/macosx/VLCConvertAndSaveWindowController.m | 33 ++++++----
 modules/gui/macosx/VLCOpenWindowController.m       | 18 ++----
 modules/gui/macosx/VLCPopupPanelController.m       |  2 +-
 modules/gui/macosx/VLCSimplePrefsController.h      |  3 -
 modules/gui/macosx/VLCSimplePrefsController.m      | 71 +++++++++++-----------
 modules/gui/macosx/VLCTextfieldPanelController.m   |  3 +-
 .../gui/macosx/VLCTimeSelectionPanelController.m   |  6 +-
 8 files changed, 65 insertions(+), 73 deletions(-)

diff --git a/modules/gui/macosx/VLCBookmarksWindowController.m b/modules/gui/macosx/VLCBookmarksWindowController.m
index 7f74aae84c..5606361c63 100644
--- a/modules/gui/macosx/VLCBookmarksWindowController.m
+++ b/modules/gui/macosx/VLCBookmarksWindowController.m
@@ -184,7 +184,7 @@
     p_old_input = p_input;
     vlc_object_release(p_input);
 
-    [NSApp beginSheet: _editBookmarksWindow modalForWindow: self.window modalDelegate: _editBookmarksWindow didEndSelector: nil contextInfo: nil];
+    [self.window beginSheet:_editBookmarksWindow completionHandler:nil];
 
     // Clear the bookmark list
     for (int i = 0; i < i_bookmarks; i++)
diff --git a/modules/gui/macosx/VLCConvertAndSaveWindowController.m b/modules/gui/macosx/VLCConvertAndSaveWindowController.m
index 1389ac8b99..2781a2d44f 100644
--- a/modules/gui/macosx/VLCConvertAndSaveWindowController.m
+++ b/modules/gui/macosx/VLCConvertAndSaveWindowController.m
@@ -435,7 +435,7 @@
 
 - (IBAction)customizeProfile:(id)sender
 {
-    [NSApp beginSheet:_customizePanel modalForWindow:self.window modalDelegate:self didEndSelector:NULL contextInfo:nil];
+    [self.window beginSheet:_customizePanel completionHandler:nil];
 }
 
 - (IBAction)closeCustomizationSheet:(id)sender
@@ -447,8 +447,6 @@
         [self updateCurrentProfile];
 }
 
-
-
 - (IBAction)videoSettingsChanged:(id)sender
 {
     bool enableSettings = [_customizeVidCheckbox state] == NSOnState && [_customizeVidKeepCheckbox state] == NSOffState;
@@ -510,7 +508,7 @@
 
 - (IBAction)showStreamPanel:(id)sender
 {
-    [NSApp beginSheet:_streamPanel modalForWindow:self.window modalDelegate:self didEndSelector:NULL contextInfo:nil];
+    [self.window beginSheet:_streamPanel completionHandler:nil];
 }
 
 - (IBAction)closeStreamPanel:(id)sender
@@ -531,23 +529,32 @@
 
     /* catch obvious errors */
     if ([[_streamAddressField stringValue] length] == 0) {
-        NSBeginInformationalAlertSheet(_NS("No Address given"),
-                                       _NS("OK"), @"", @"", _streamPanel, nil, nil, nil, nil,
-                                       @"%@", _NS("In order to stream, a valid destination address is required."));
+        NSAlert *alert = [[NSAlert alloc] init];
+        [alert setAlertStyle:NSInformationalAlertStyle];
+        [alert setMessageText:_NS("No Address given")];
+        [alert setInformativeText:_NS("In order to stream, a valid destination address is required.")];
+        [alert beginSheetModalForWindow:_streamPanel
+                      completionHandler:nil];
         return;
     }
 
     if ([_streamSAPCheckbox state] && [[_streamChannelField stringValue] length] == 0) {
-        NSBeginInformationalAlertSheet(_NS("No Channel Name given"),
-                                       _NS("OK"), @"", @"", _streamPanel, nil, nil, nil, nil,
-                                       @"%@", _NS("SAP stream announcement is enabled. However, no channel name is provided."));
+        NSAlert *alert = [[NSAlert alloc] init];
+        [alert setAlertStyle:NSInformationalAlertStyle];
+        [alert setMessageText:_NS("No Channel Name given")];
+        [alert setInformativeText:_NS("SAP stream announcement is enabled. However, no channel name is provided.")];
+        [alert beginSheetModalForWindow:_streamPanel
+                      completionHandler:nil];
         return;
     }
 
     if ([_streamSDPMatrix isEnabled] && [_streamSDPMatrix selectedCell] != [_streamSDPMatrix cellWithTag:0] && [[_streamSDPField stringValue] length] == 0) {
-        NSBeginInformationalAlertSheet(_NS("No SDP URL given"),
-                                       _NS("OK"), @"", @"", _streamPanel, nil, nil, nil, nil,
-                                       @"%@", _NS("A SDP export is requested, but no URL is provided."));
+        NSAlert *alert = [[NSAlert alloc] init];
+        [alert setAlertStyle:NSInformationalAlertStyle];
+        [alert setMessageText:_NS("No SDP URL given")];
+        [alert setInformativeText:_NS("A SDP export is requested, but no URL is provided.")];
+        [alert beginSheetModalForWindow:_streamPanel
+                      completionHandler:nil];
         return;
     }
 
diff --git a/modules/gui/macosx/VLCOpenWindowController.m b/modules/gui/macosx/VLCOpenWindowController.m
index 5a09c0ac85..adf7a38004 100644
--- a/modules/gui/macosx/VLCOpenWindowController.m
+++ b/modules/gui/macosx/VLCOpenWindowController.m
@@ -610,8 +610,9 @@ static NSString *kCaptureTabViewId  = @"capture";
         return;
     }
 
-    if (!b_outputNibLoaded)
-        b_outputNibLoaded = [NSBundle loadNibNamed:@"StreamOutput" owner:_output];
+    if (!b_outputNibLoaded) {
+        b_outputNibLoaded = [[NSBundle mainBundle] loadNibNamed:@"StreamOutput" owner:_output topLevelObjects:nil];
+    }
 
     [self.window beginSheet:_output.outputSheet completionHandler:nil];
 }
@@ -1043,11 +1044,8 @@ static NSString *kCaptureTabViewId  = @"capture";
 - (IBAction)openNetUDPButtonAction:(id)sender
 {
     if (sender == _netOpenUDPButton) {
-        [NSApp beginSheet: self.netUDPPanel
-           modalForWindow: self.window
-            modalDelegate: self
-           didEndSelector: NULL
-              contextInfo: nil];
+        [self.window beginSheet:self.netUDPPanel
+              completionHandler:nil];
         [self openNetInfoChanged:nil];
     }
     else if (sender == _netUDPCancelButton) {
@@ -1240,11 +1238,7 @@ static NSString *kCaptureTabViewId  = @"capture";
 
 - (IBAction)subSettings:(id)sender
 {
-    [NSApp beginSheet: self.fileSubSheet
-       modalForWindow: [sender window]
-        modalDelegate: self
-       didEndSelector: NULL
-          contextInfo: nil];
+    [[self window] beginSheet:self.fileSubSheet completionHandler:nil];
 }
 
 - (IBAction)subCloseSheet:(id)sender
diff --git a/modules/gui/macosx/VLCPopupPanelController.m b/modules/gui/macosx/VLCPopupPanelController.m
index 0f051c0db5..ed32427c6a 100644
--- a/modules/gui/macosx/VLCPopupPanelController.m
+++ b/modules/gui/macosx/VLCPopupPanelController.m
@@ -61,7 +61,7 @@
 
     _completionBlock = [handler copy];
 
-    [NSApp beginSheet:self.window modalForWindow:window modalDelegate:self didEndSelector:NULL contextInfo:nil];
+    [window beginSheet:self.window completionHandler:nil];
 }
 
 @end
diff --git a/modules/gui/macosx/VLCSimplePrefsController.h b/modules/gui/macosx/VLCSimplePrefsController.h
index ba4c5db670..760d80c478 100644
--- a/modules/gui/macosx/VLCSimplePrefsController.h
+++ b/modules/gui/macosx/VLCSimplePrefsController.h
@@ -222,9 +222,6 @@
 
 - (IBAction)buttonAction:(id)sender;
 - (IBAction)resetPreferences:(id)sender;
-- (void)sheetDidEnd:(NSWindow *)o_sheet
-         returnCode:(int)i_return
-        contextInfo:(void *)o_context;
 
 /* interface */
 - (IBAction)interfaceSettingChanged:(id)sender;
diff --git a/modules/gui/macosx/VLCSimplePrefsController.m b/modules/gui/macosx/VLCSimplePrefsController.m
index 0315a88f08..305196cc09 100644
--- a/modules/gui/macosx/VLCSimplePrefsController.m
+++ b/modules/gui/macosx/VLCSimplePrefsController.m
@@ -805,42 +805,40 @@ static inline const char * __config_GetLabel(vlc_object_t *p_this, const char *p
 
 - (IBAction)resetPreferences:(NSControl *)sender
 {
-    NSBeginInformationalAlertSheet(_NS("Reset Preferences"), _NS("Cancel"),
-                                   _NS("Continue"), nil, [sender window], self,
-                                   @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil, @"%@",
-                                   _NS("This will reset VLC media player's preferences.\n\n"
-                                       "Note that VLC will restart during the process, so your current "
-                                       "playlist will be emptied and eventual playback, streaming or "
-                                       "transcoding activities will stop immediately.\n\n"
-                                       "The Media Library will not be affected.\n\n"
-                                       "Are you sure you want to continue?"));
-}
-
-- (void)sheetDidEnd:(NSWindow *)o_sheet
-         returnCode:(int)i_return
-        contextInfo:(void *)o_context
-{
-    if (i_return == NSAlertAlternateReturn) {
-        /* reset VLC's config */
-        config_ResetAll();
-        [self resetControls];
-
-        /* force config file creation, since libvlc won't exit normally */
-        config_SaveConfigFile(p_intf);
-
-        /* reset OS X defaults */
-        [[VLCMain sharedInstance] resetAndReinitializeUserDefaults];
-
-        /* Relaunch now */
-        const char * path = [[[NSBundle mainBundle] executablePath] UTF8String];
-
-        /* For some reason we need to fork(), not just execl(), which reports a ENOTSUP then. */
-        if (fork() != 0) {
-            exit(0);
-            return;
+    NSAlert *alert = [[NSAlert alloc] init];
+    [alert setAlertStyle:NSInformationalAlertStyle];
+    [alert setMessageText:_NS("Reset Preferences")];
+    [alert setInformativeText:_NS("This will reset VLC media player's preferences.\n\n"
+                                  "Note that VLC will restart during the process, so your current "
+                                  "playlist will be emptied and eventual playback, streaming or "
+                                  "transcoding activities will stop immediately.\n\n"
+                                  "The Media Library will not be affected.\n\n"
+                                  "Are you sure you want to continue?")];
+    [alert addButtonWithTitle:_NS("Cancel")];
+    [alert addButtonWithTitle:_NS("Continue")];
+    [alert beginSheetModalForWindow:[sender window] completionHandler:^(NSModalResponse returnCode) {
+        if (returnCode == NSAlertSecondButtonReturn) {
+            /* reset VLC's config */
+            config_ResetAll();
+            [self resetControls];
+
+            /* force config file creation, since libvlc won't exit normally */
+            config_SaveConfigFile(p_intf);
+
+            /* reset OS X defaults */
+            [[VLCMain sharedInstance] resetAndReinitializeUserDefaults];
+
+            /* Relaunch now */
+            const char * path = [[[NSBundle mainBundle] executablePath] UTF8String];
+
+            /* For some reason we need to fork(), not just execl(), which reports a ENOTSUP then. */
+            if (fork() != 0) {
+                exit(0);
+                return;
+            }
+            execl(path, path, NULL);
         }
-        execl(path, path, NULL);
-    }
+    }];
 }
 
 static inline void save_int_list(intf_thread_t * p_intf, id object, const char * name)
@@ -1327,8 +1325,7 @@ static inline void save_string_list(intf_thread_t * p_intf, id object, const cha
         fillUrlHandlerPopup(@"smb", _urlhandler_smbPopup);
         fillUrlHandlerPopup(@"udp", _urlhandler_udpPopup);
 
-
-        [NSApp beginSheet:_urlhandler_win modalForWindow:self.window modalDelegate:self didEndSelector:NULL contextInfo:nil];
+        [self.window beginSheet:_urlhandler_win completionHandler:nil];
     } else {
         [_urlhandler_win orderOut:sender];
         [NSApp endSheet:_urlhandler_win];
diff --git a/modules/gui/macosx/VLCTextfieldPanelController.m b/modules/gui/macosx/VLCTextfieldPanelController.m
index 42a6ccb9aa..02644d5ea9 100644
--- a/modules/gui/macosx/VLCTextfieldPanelController.m
+++ b/modules/gui/macosx/VLCTextfieldPanelController.m
@@ -32,7 +32,6 @@
 
 @implementation VLCTextfieldPanelController
 
-
 - (id)init
 {
     self = [super initWithWindowNibName:@"TextfieldPanel"];
@@ -61,7 +60,7 @@
 
     _completionBlock = [handler copy];
 
-    [NSApp beginSheet:self.window modalForWindow:window modalDelegate:self didEndSelector:NULL contextInfo:nil];
+    [window beginSheet:self.window completionHandler:nil];
 }
 
 @end
diff --git a/modules/gui/macosx/VLCTimeSelectionPanelController.m b/modules/gui/macosx/VLCTimeSelectionPanelController.m
index ac8bdb0670..9fd6eb3de7 100644
--- a/modules/gui/macosx/VLCTimeSelectionPanelController.m
+++ b/modules/gui/macosx/VLCTimeSelectionPanelController.m
@@ -89,10 +89,8 @@
     [_stepper setMaxValue:self.maxValue];
 
     _completionHandler = [handler copy];
-    [NSApp beginSheet:self.window
-       modalForWindow:window modalDelegate:self
-       didEndSelector:nil
-          contextInfo:nil];
+
+    [window beginSheet:self.window completionHandler:nil];
 }
 
 @end



More information about the vlc-commits mailing list