]> granicus.if.org Git - transmission/commitdiff
Update some selector-based alerts to block-based
authorMitchell Livingston <livings124@mac.com>
Wed, 26 Dec 2018 15:15:33 +0000 (10:15 -0500)
committerMitchell Livingston <livings124@mac.com>
Wed, 26 Dec 2018 15:15:33 +0000 (10:15 -0500)
macosx/Controller.m

index f0e96c9b3fd8c38485f69dbce77797f878efd8ee..6773745db1ce232fe5a2219ad5a714198dc107c1 100644 (file)
@@ -735,16 +735,21 @@ static void removeKeRangerRansomware()
 
         if ([fDefaults boolForKey: @"CheckQuitDownloading"] ? downloading > 0 : active > 0)
         {
-            NSString * message = active == 1
+            NSAlert *alert = [[NSAlert alloc] init];
+            alert.alertStyle = NSAlertStyleInformational;
+            alert.messageText = NSLocalizedString(@"Are you sure you want to quit?", "Confirm Quit panel -> title");
+            alert.informativeText = active == 1
                 ? NSLocalizedString(@"There is an active transfer that will be paused on quit."
                     " The transfer will automatically resume on the next launch.", "Confirm Quit panel -> message")
                 : [NSString stringWithFormat: NSLocalizedString(@"There are %d active transfers that will be paused on quit."
                     " The transfers will automatically resume on the next launch.", "Confirm Quit panel -> message"), active];
-
-            NSBeginAlertSheet(NSLocalizedString(@"Are you sure you want to quit?", "Confirm Quit panel -> title"),
-                                NSLocalizedString(@"Quit", "Confirm Quit panel -> button"),
-                                NSLocalizedString(@"Cancel", "Confirm Quit panel -> button"), nil, fWindow, self,
-                                @selector(quitSheetDidEnd:returnCode:contextInfo:), nil, nil, @"%@", message);
+            [alert addButtonWithTitle:NSLocalizedString(@"Quit", "Confirm Quit panel -> button")];
+            [alert addButtonWithTitle:NSLocalizedString(@"Cancel", "Confirm Quit panel -> button")];
+            
+            [alert beginSheetModalForWindow:fWindow
+                          completionHandler:^(NSModalResponse returnCode) {
+                              [NSApp replyToApplicationShouldTerminate: returnCode == NSAlertFirstButtonReturn];
+                          }];
             return NSTerminateLater;
         }
     }
@@ -752,11 +757,6 @@ static void removeKeRangerRansomware()
     return NSTerminateNow;
 }
 
-- (void) quitSheetDidEnd: (NSWindow *) sheet returnCode: (NSInteger) returnCode contextInfo: (void *) contextInfo
-{
-    [NSApp replyToApplicationShouldTerminate: returnCode == NSAlertDefaultReturn];
-}
-
 - (void) applicationWillTerminate: (NSNotification *) notification
 {
     fQuitting = YES;
@@ -1401,9 +1401,6 @@ static void removeKeRangerRansomware()
 
         if ([fDefaults boolForKey: @"CheckRemoveDownloading"] ? downloading > 0 : active > 0)
         {
-            NSDictionary * dict = @{ @"Torrents" : torrents,
-                                    @"DeleteData" : @(deleteData) };
-
             NSString * title, * message;
 
             const NSUInteger selected = [torrents count];
@@ -1446,9 +1443,19 @@ static void removeKeRangerRansomware()
                             "Removal confirm panel -> message part 2")];
             }
 
-            NSBeginAlertSheet(title, NSLocalizedString(@"Remove", "Removal confirm panel -> button"),
-                NSLocalizedString(@"Cancel", "Removal confirm panel -> button"), nil, fWindow, self,
-                nil, @selector(removeSheetDidEnd:returnCode:contextInfo:), (__bridge_retained void *)(dict), @"%@", message);
+            NSAlert *alert = [[NSAlert alloc] init];
+            alert.alertStyle = NSAlertStyleInformational;
+            alert.messageText = title;
+            alert.informativeText = message;
+            [alert addButtonWithTitle:NSLocalizedString(@"Remove", "Removal confirm panel -> button")];
+            [alert addButtonWithTitle:NSLocalizedString(@"Cancel", "Removal confirm panel -> button")];
+            
+            [alert beginSheetModalForWindow:fWindow
+                          completionHandler:^(NSModalResponse returnCode) {
+                              if (returnCode == NSAlertFirstButtonReturn) {
+                                  [self confirmRemoveTorrents: torrents deleteData: deleteData];
+                              }
+                          }];
             return;
         }
     }
@@ -1456,14 +1463,6 @@ static void removeKeRangerRansomware()
     [self confirmRemoveTorrents: torrents deleteData: deleteData];
 }
 
-- (void) removeSheetDidEnd: (NSWindow *) sheet returnCode: (NSInteger) returnCode contextInfo: (void *) contextInfo
-{
-    NSDictionary * dict = (__bridge_transfer NSDictionary *)contextInfo;
-    NSArray * torrents = dict[@"Torrents"];
-    if (returnCode == NSAlertDefaultReturn)
-        [self confirmRemoveTorrents: torrents deleteData: [dict[@"DeleteData"] boolValue]];
-}
-
 - (void) confirmRemoveTorrents: (NSArray *) torrents deleteData: (BOOL) deleteData
 {
     //miscellaneous