removed unnecessary weak references in blocks

This commit is contained in:
michael starke
2017-09-02 09:42:28 +02:00
parent e8bdd3b2b8
commit f8b86a386a
2 changed files with 16 additions and 24 deletions

View File

@@ -275,9 +275,8 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
}
if(self.encrypted) {
__weak MPDocument *welf = self;
dispatch_async(dispatch_get_main_queue(), ^{
[welf _handleFileChangeWithStrategy:MPFileChangeStrategyUseOther setAsDefault:NO];
[self _handleFileChangeWithStrategy:MPFileChangeStrategyUseOther setAsDefault:NO];
});
return; // Done!
}
@@ -290,11 +289,10 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
self.lockedForFileChange = YES;
/* Dispatch the alert to the main queue */
__weak MPDocument *welf = self;
dispatch_async(dispatch_get_main_queue(), ^{
MPFileChangeStrategy strategy = (MPFileChangeStrategy)[NSUserDefaults.standardUserDefaults integerForKey:kMPSettingsKeyFileChangeStrategy];
if(strategy != MPFileChangeStrategyAsk) {
[welf _handleFileChangeWithStrategy:strategy setAsDefault:NO];
[self _handleFileChangeWithStrategy:strategy setAsDefault:NO];
self.lockedForFileChange = NO;
return;
}
@@ -307,22 +305,22 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
[alert addButtonWithTitle:NSLocalizedString(@"FILE_CHANGE_STRATEGY_MERGE", @"Merge changes into file!")];
[alert addButtonWithTitle:NSLocalizedString(@"KEEP_OTHER_DISCARD_MINE", @"Reopen the file!")];
[alert addButtonWithTitle:NSLocalizedString(@"KEEP_MINE_DISCARD_OTHER", @"Ignore the changes to an open file!")];
[alert beginSheetModalForWindow:welf.windowForSheet completionHandler:^(NSModalResponse returnCode) {
[alert beginSheetModalForWindow:self.windowForSheet completionHandler:^(NSModalResponse returnCode) {
BOOL useAsDefault = (alert.suppressionButton.state == NSOnState);
switch(returnCode) {
case NSAlertFirstButtonReturn: {
[welf _handleFileChangeWithStrategy:MPFileChangeStrategyMerge setAsDefault:useAsDefault];
[self _handleFileChangeWithStrategy:MPFileChangeStrategyMerge setAsDefault:useAsDefault];
break;
}
case NSAlertSecondButtonReturn:
[welf _handleFileChangeWithStrategy:MPFileChangeStrategyUseOther setAsDefault:useAsDefault];
[self _handleFileChangeWithStrategy:MPFileChangeStrategyUseOther setAsDefault:useAsDefault];
break;
case NSAlertThirdButtonReturn:
[welf _handleFileChangeWithStrategy:MPFileChangeStrategyKeepMine setAsDefault:useAsDefault];
[self _handleFileChangeWithStrategy:MPFileChangeStrategyKeepMine setAsDefault:useAsDefault];
default:
break;
}
welf.lockedForFileChange = NO;
self.lockedForFileChange = NO;
}];
});
}];
@@ -383,14 +381,13 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
backing:NSBackingStoreBuffered
defer:NO];
MPPasswordInputController *passwordInputController = [[MPPasswordInputController alloc] init];
__weak MPDocument *welf = self;
[passwordInputController requestPasswordWithMessage:NSLocalizedString(@"EXTERN_CHANGE_OF_MASTERKEY", @"The master key was changed by an extrenal programm!")
cancelLabel:NSLocalizedString(@"ABORT_MERGE_KEEP_MINE", @"Button label to abort a merge on a file with changed master key!")
completionHandler:^BOOL(NSString *password, NSURL *keyURL, BOOL didCancel, NSError *__autoreleasing *error) {
[welf.windowForSheet endSheet:sheet returnCode:(didCancel ? NSModalResponseCancel : NSModalResponseOK)];
[self.windowForSheet endSheet:sheet returnCode:(didCancel ? NSModalResponseCancel : NSModalResponseOK)];
if(!didCancel) {
KPKCompositeKey *compositeKey = [[KPKCompositeKey alloc] initWithPassword:password key:keyURL];
[welf mergeWithContentsFromURL:url key:compositeKey];
[self mergeWithContentsFromURL:url key:compositeKey];
}
// just return yes regardless since we will display the sheet again if needed!
return YES;

View File

@@ -208,17 +208,16 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
[alert addButtonWithTitle:NSLocalizedString(@"SAVE_LOSSY", "Save lossy")];
[alert addButtonWithTitle:NSLocalizedString(@"CHANGE_FORMAT", "")];
[alert addButtonWithTitle:NSLocalizedString(@"CANCEL", "Cancel")];
__weak MPDocumentWindowController *welf = self;
[alert beginSheetModalForWindow:[welf.document windowForSheet] completionHandler:^(NSModalResponse returnCode) {
[alert beginSheetModalForWindow:((NSDocument *)self.document).windowForSheet completionHandler:^(NSModalResponse returnCode) {
switch(returnCode) {
case NSAlertFirstButtonReturn:
/* Save lossy */
[welf.document saveDocument:nil];
[self.document saveDocument:nil];
return;
case NSAlertSecondButtonReturn:
[alert.window orderOut:nil];
[welf.document saveDocumentAs:nil];
[self.document saveDocumentAs:nil];
return;
case NSAlertThirdButtonReturn:
@@ -323,12 +322,11 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
self.passwordInputController = [[MPPasswordInputController alloc] init];
}
[self _setContentViewController:self.passwordInputController];
__weak MPDocumentWindowController *welf = self;
[self.passwordInputController requestPasswordWithCompletionHandler:^BOOL(NSString *password, NSURL *keyURL, BOOL cancel, NSError *__autoreleasing *error) {
if(cancel) {
return NO;
}
return [((MPDocument *)welf.document) unlockWithPassword:password keyFileURL:keyURL error:error];
return [((MPDocument *)self.document) unlockWithPassword:password keyFileURL:keyURL error:error];
}];
}
@@ -403,7 +401,6 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
}
- (void)duplicateEntryWithOptions:(id)sender {
MPDuplicateEntryOptionsWindowController *wc = [[MPDuplicateEntryOptionsWindowController alloc] init];
__weak MPDocumentWindowController *welf = self;
[self.window beginSheet:wc.window completionHandler:^(NSModalResponse returnCode) {
if(returnCode == NSModalResponseOK) {
@@ -418,7 +415,7 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
if(wc.duplicateHistory) {
options |= kKPKCopyOptionCopyHistory;
}
[((MPDocument *)welf.document) duplicateEntryWithOptions:options];
[((MPDocument *)self.document) duplicateEntryWithOptions:options];
}
}];
}
@@ -555,9 +552,8 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
if(NSAlertSecondButtonReturn == returnCode) {
return;
}
id __weak welf = self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[welf editPassword:nil];
[self editPassword:nil];
});
}];
}
@@ -577,9 +573,8 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
if(returnCode == NSAlertSecondButtonReturn) {
return;
}
id __weak welf = self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[welf editPassword:nil];
[self editPassword:nil];
});
}];
}