Revision: 15493 http://sourceforge.net/p/skim-app/code/15493 Author: hofman Date: 2025-06-18 14:59:49 +0000 (Wed, 18 Jun 2025) Log Message: ----------- convenience method to show an alert to let the user confirm not to continue
Modified Paths: -------------- trunk/SKMainDocument.m Modified: trunk/SKMainDocument.m =================================================================== --- trunk/SKMainDocument.m 2025-06-18 14:40:46 UTC (rev 15492) +++ trunk/SKMainDocument.m 2025-06-18 14:59:49 UTC (rev 15493) @@ -299,6 +299,15 @@ return option; } +- (BOOL)confirmNotToContinueUsingMessageText:(NSString *)messageText informativeText:(NSString *)informativeText { + NSAlert *alert = [[NSAlert alloc] init]; + [alert setMessageText:messageText]; + [alert setInformativeText:informativeText]; + [alert addButtonWithTitle:NSLocalizedString(@"No", @"Button title")]; + [alert addButtonWithTitle:NSLocalizedString(@"Yes", @"Button title")]; + return [alert runModal] == NSAlertFirstButtonReturn; +} + - (SKInteractionMode)interactionMode { return [[self mainWindowController] interactionMode]; } @@ -901,19 +910,12 @@ if ((data = [[NSData alloc] initWithContentsOfURL:pdfURL options:NSDataReadingUncached error:&error]) && (pdfDoc = [[SKPDFDocument alloc] initWithURL:pdfURL])) { NSArray *array = [[NSFileManager defaultManager] readSkimNotesFromPDFBundleAtURL:absoluteURL error:&error]; - if (array == nil) { - NSAlert *alert = [[NSAlert alloc] init]; - [alert setMessageText:NSLocalizedString(@"Unable to Read Notes", @"Message in alert dialog")]; - [alert setInformativeText:[NSString stringWithFormat:NSLocalizedString(@"Skim was not able to read the notes at %@. %@ Do you want to continue to open the PDF document anyway?", @"Informative text in alert dialog"), [[pdfURL path] stringByAbbreviatingWithTildeInPath], [error localizedDescription]]]; - [alert addButtonWithTitle:NSLocalizedString(@"No", @"Button title")]; - [alert addButtonWithTitle:NSLocalizedString(@"Yes", @"Button title")]; - if ([alert runModal] == NSAlertFirstButtonReturn) { - data = nil; - pdfDoc = nil; - error = [NSError userCancelledErrorWithUnderlyingError:error]; - } - } else if ([array count]) { + if ([array count]) { [tmpData setNoteDicts:array]; + } else if (array == nil && [self confirmNotToContinueUsingMessageText:NSLocalizedString(@"Unable to Read Notes", @"Message in alert dialog") informativeText:[NSString stringWithFormat:NSLocalizedString(@"Skim was not able to read the notes at %@. %@ Do you want to continue to open the PDF document anyway?", @"Informative text in alert dialog"), [[pdfURL path] stringByAbbreviatingWithTildeInPath], [error localizedDescription]]]) { + data = nil; + pdfDoc = nil; + error = [NSError userCancelledErrorWithUnderlyingError:error]; } } } @@ -928,23 +930,14 @@ if (pdfDoc) { NSArray *array = [[NSFileManager defaultManager] readSkimNotesFromExtendedAttributesAtURL:absoluteURL error:&error]; BOOL foundEANotes = [array count] > 0; + // if we found no notes, see if we had an error finding notes. If EAs were not supported we ignore the error, as we may assume there won't be any notes if (foundEANotes) { [tmpData setNoteDicts:array]; - } else { - // we found no notes, see if we had an error finding notes. if EAs were not supported we ignore the error, as we may assume there won't be any notes - if (array == nil && isIgnorablePOSIXError(error) == NO) { - NSAlert *alert = [[NSAlert alloc] init]; - [alert setMessageText:NSLocalizedString(@"Unable to Read Notes", @"Message in alert dialog")]; - [alert setInformativeText:[NSString stringWithFormat:NSLocalizedString(@"Skim was not able to read the notes at %@. %@ Do you want to continue to open the PDF document anyway?", @"Informative text in alert dialog"), [[absoluteURL path] stringByAbbreviatingWithTildeInPath], [error localizedDescription]]]; - [alert addButtonWithTitle:NSLocalizedString(@"No", @"Button title")]; - [alert addButtonWithTitle:NSLocalizedString(@"Yes", @"Button title")]; - if ([alert runModal] == NSAlertFirstButtonReturn) { - fileData = nil; - data = nil; - pdfDoc = nil; - error = [NSError userCancelledErrorWithUnderlyingError:error]; - } - } + } else if (array == nil && isIgnorablePOSIXError(error) == NO && [self confirmNotToContinueUsingMessageText:NSLocalizedString(@"Unable to Read Notes", @"Message in alert dialog") informativeText:[NSString stringWithFormat:NSLocalizedString(@"Skim was not able to read the notes at %@. %@ Do you want to continue to open the PDF document anyway?", @"Informative text in alert dialog"), [[absoluteURL path] stringByAbbreviatingWithTildeInPath], [error localizedDescription]]]) { + fileData = nil; + data = nil; + pdfDoc = nil; + error = [NSError userCancelledErrorWithUnderlyingError:error]; } NSInteger readOption = [[NSUserDefaults standardUserDefaults] integerForKey:foundEANotes ? SKReadNonMissingNotesFromSkimFileOptionKey : SKReadMissingNotesFromSkimFileOptionKey]; if (pdfDoc && readOption != SKOptionNever) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Skim-app-commit mailing list Skim-app-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/skim-app-commit