From 4a4233feae0655d8a9a0e9810d74fadc722b4237 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Wed, 26 Dec 2018 10:15:33 -0500 Subject: [PATCH] Update some selector-based alerts to block-based --- macosx/Controller.m | 49 ++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/macosx/Controller.m b/macosx/Controller.m index f0e96c9b3..6773745db 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -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