Fixed #464 stop multiple file-changed boxes from appearing at once

This commit is contained in:
Nathan Landis 2016-05-21 18:49:30 -05:00
parent a897a5915a
commit f0fc823b06
3 changed files with 15 additions and 1 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View File

@ -75,6 +75,8 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
@property (strong) IBOutlet NSView *warningView;
@property (weak) IBOutlet NSImageView *warningViewImage;
@property (assign) BOOL fileChangeDialogOpen;;
@end
@implementation MPDocument
@ -115,6 +117,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
if(self) {
_didLockFile = NO;
_readOnly = NO;
_fileChangeDialogOpen = NO;
}
return self;
}
@ -244,15 +247,26 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
if(NSOrderedSame == [self.fileModificationDate compare:modificationDate]) {
return; // Just metadata has changed
}
if(_fileChangeDialogOpen) {
return; // This alert is already being shown
}
/* Dispatch the alert to the main queue */
dispatch_async(dispatch_get_main_queue(), ^{
_fileChangeDialogOpen = YES;
NSAlert *alert = [[NSAlert alloc] init];
alert.alertStyle = NSWarningAlertStyle;
alert.messageText = NSLocalizedString(@"FILE_CHANGED_BY_OTHERS_MESSAGE_TEXT", @"Message displayed when an open file was changed from another application");
alert.informativeText = NSLocalizedString(@"FILE_CHANGED_BY_OTHERS_INFO_TEXT", @"Informative text displayed when the file was change form another application");
alert.informativeText = NSLocalizedString(@"FILE_CHANGED_BY_OTHERS_INFO_TEXT", @"Informative text displayed when the file was change from another application");
[alert addButtonWithTitle:NSLocalizedString(@"KEEP_MINE", @"Ignore the changes to an open file!")];
[alert addButtonWithTitle:NSLocalizedString(@"LOAD_CHANGES", @"Reopen the file!")];
[alert beginSheetModalForWindow:self.windowForSheet completionHandler:^(NSModalResponse returnCode) {
_fileChangeDialogOpen = NO;
if(returnCode == NSAlertSecondButtonReturn) {
[self revertDocumentToSaved:nil];
}

BIN
MacPassTests/.DS_Store vendored Normal file

Binary file not shown.