Recovery attempt for save without password now also adheres to cancel

This commit is contained in:
michael starke
2016-08-31 18:26:46 +02:00
parent a79f815f99
commit 9e09565365

View File

@@ -21,18 +21,28 @@
*/
- (void)attemptRecoveryFromError:(NSError *)error optionIndex:(NSUInteger)recoveryOptionIndex delegate:(nullable id)delegate didRecoverSelector:(nullable SEL)didRecoverSelector contextInfo:(nullable void *)contextInfo {
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[delegate methodSignatureForSelector:didRecoverSelector]];
__block void *contextInfoCopy = contextInfo;
if(error.code == MPErrorNoPasswordOrKeyFile) {
if([delegate isKindOfClass:[MPDocument class]]) {
MPDocument *document = delegate;
[document.windowControllers.firstObject editPasswordWithCompetionHandler:^(NSInteger result) {
BOOL didRecover = result == NSModalResponseOK;
BOOL didRecover = NO;
if(recoveryOptionIndex == 0) {
[document.windowControllers.firstObject editPasswordWithCompetionHandler:^(NSInteger result) {
BOOL didRecover = result == NSModalResponseOK;
invocation.target = delegate;
invocation.selector = didRecoverSelector;
[invocation setArgument:&didRecover atIndex:2];
[invocation setArgument:&contextInfoCopy atIndex:3];
[invocation invoke];
}];
}
else {
invocation.target = delegate;
invocation.selector = didRecoverSelector;
[invocation setArgument:&didRecover atIndex:2];
[invocation setArgument:&contextInfo atIndex:3];
[invocation invoke];
}];
}
}
}