Revision: 15524 http://sourceforge.net/p/skim-app/code/15524 Author: hofman Date: 2025-06-22 16:26:38 +0000 (Sun, 22 Jun 2025) Log Message: ----------- warn about large number of files to reopen from document controller
Modified Paths: -------------- trunk/SKApplicationController.m trunk/SKDocumentController.m Modified: trunk/SKApplicationController.m =================================================================== --- trunk/SKApplicationController.m 2025-06-22 15:40:15 UTC (rev 15523) +++ trunk/SKApplicationController.m 2025-06-22 16:26:38 UTC (rev 15524) @@ -185,19 +185,6 @@ didReopen = YES; SKBookmark *previousSession = [[SKBookmarkController sharedBookmarkController] previousSession]; - NSUInteger numberOfDocs = [[previousSession children] count]; - - if (numberOfDocs > REOPEN_WARNING_LIMIT) { - NSAlert *alert = [[NSAlert alloc] init]; - [alert setMessageText:[NSString stringWithFormat:NSLocalizedString(@"Are you sure you want to open %lu documents?", @"Message in alert dialog"), (unsigned long)numberOfDocs]]; - [alert setInformativeText:NSLocalizedString(@"Each document opens in a separate window.", @"Informative text in alert dialog")]; - [alert addButtonWithTitle:NSLocalizedString(@"Cancel", @"Button title")]; - [alert addButtonWithTitle:NSLocalizedString(@"Open", @"Button title")]; - - if (NSAlertFirstButtonReturn == [alert runModal]) - previousSession = nil; - } - if (previousSession) [[NSDocumentController sharedDocumentController] openDocumentWithBookmark:previousSession completionHandler:^(NSDocument *document, BOOL documentWasAlreadyOpen, NSError *error){ if (document == nil && error && [error isUserCancelledError] == NO) Modified: trunk/SKDocumentController.m =================================================================== --- trunk/SKDocumentController.m 2025-06-22 15:40:15 UTC (rev 15523) +++ trunk/SKDocumentController.m 2025-06-22 16:26:38 UTC (rev 15524) @@ -81,6 +81,7 @@ #define SKPasteboardTypePostScript @"com.adobe.encapsulated-postscript" #define WARNING_LIMIT 10 +#define SESSION_WARNING_LIMIT 50 @interface NSDocumentController (SKPrivateDeclaration) - (void)_setTabPlusButtonWasClicked:(BOOL)wasClicked; @@ -357,49 +358,53 @@ NSArray *children = [bookmark children]; NSInteger i = [children count]; - __block NSInteger countDown = i; - __block NSMutableArray *errors = nil; - __block NSMutableArray *windows = nil; - __block NSMutableArray *tabInfos = nil; - - windows = [[NSMutableArray alloc] init]; - while ([windows count] < (NSUInteger)i) - [windows addObject:[NSNull null]]; - - while (i-- > 0) { - SKBookmark *child = [children objectAtIndex:i]; + if ([self shouldOpenNumberOfDocuments:i warningLimit:SESSION_WARNING_LIMIT]) { + __block NSInteger countDown = i; + __block NSMutableArray *errors = nil; + __block NSMutableArray *windows = nil; + __block NSMutableArray *tabInfos = nil; - if (windows) { - NSString *tabs = [child tabs]; - if (tabs) { - if (tabInfos == nil) - tabInfos = [[NSMutableArray alloc] init]; - [tabInfos addObject:@[tabs, [NSNumber numberWithUnsignedInteger:i]]]; - } - } + windows = [[NSMutableArray alloc] init]; + while ([windows count] < (NSUInteger)i) + [windows addObject:[NSNull null]]; - [self openDocumentWithBookmark:child completionHandler:^(NSDocument *document, BOOL documentWasAlreadyOpen, NSError *error){ - if (windows && [document mainWindow]) - [windows replaceObjectAtIndex:i withObject:[document mainWindow]]; - if (document == nil && error) { - if (errors == nil) - errors = [[NSMutableArray alloc] init]; - [errors addObject:error]; + while (i-- > 0) { + SKBookmark *child = [children objectAtIndex:i]; + + if (windows) { + NSString *tabs = [child tabs]; + if (tabs) { + if (tabInfos == nil) + tabInfos = [[NSMutableArray alloc] init]; + [tabInfos addObject:@[tabs, [NSNumber numberWithUnsignedInteger:i]]]; + } } - if (--countDown == 0) { - if (tabInfos && [windows count] > 1) - [NSWindow addTabs:tabInfos forWindows:windows]; - windows = nil; - tabInfos = nil; - if (completionHandler) { - if (errors) - completionHandler(nil, NO, [NSError combineErrors:errors maximum:WARNING_LIMIT]); - else - completionHandler(document, documentWasAlreadyOpen, error); + + [self openDocumentWithBookmark:child completionHandler:^(NSDocument *document, BOOL documentWasAlreadyOpen, NSError *error){ + if (windows && [document mainWindow]) + [windows replaceObjectAtIndex:i withObject:[document mainWindow]]; + if (document == nil && error) { + if (errors == nil) + errors = [[NSMutableArray alloc] init]; + [errors addObject:error]; } - errors = nil; - } - }]; + if (--countDown == 0) { + if (tabInfos && [windows count] > 1) + [NSWindow addTabs:tabInfos forWindows:windows]; + windows = nil; + tabInfos = nil; + if (completionHandler) { + if (errors) + completionHandler(nil, NO, [NSError combineErrors:errors maximum:WARNING_LIMIT]); + else + completionHandler(document, documentWasAlreadyOpen, error); + } + errors = nil; + } + }]; + } + } else if (completionHandler) { + completionHandler(nil, NO, [NSError userCancelledErrorWithUnderlyingError:nil]); } } else if (type == SKBookmarkTypeFolder) { @@ -436,8 +441,8 @@ } } -- (BOOL)shouldOpenNumberOfDocuments:(NSUInteger)count { - if (count > WARNING_LIMIT) { +- (BOOL)shouldOpenNumberOfDocuments:(NSUInteger)count warningLimit:(NSUInteger)warningLimit { + if (count > warningLimit) { NSAlert *alert = [[NSAlert alloc] init]; [alert setMessageText:[NSString stringWithFormat:NSLocalizedString(@"Are you sure you want to open %lu documents?", @"Message in alert dialog"), (unsigned long)count]]; [alert setInformativeText:NSLocalizedString(@"Each document opens in a separate window.", @"Informative text in alert dialog")]; @@ -450,7 +455,7 @@ } - (void)openDocumentWithBookmarks:(NSArray *)bookmarks completionHandler:(void (^)(NSDocument *document, BOOL documentWasAlreadyOpen, NSError *error))completionHandler { - if ([self shouldOpenNumberOfDocuments:[bookmarks count]]) { + if ([self shouldOpenNumberOfDocuments:[bookmarks count] warningLimit:WARNING_LIMIT]) { // bookmarks should not be empty __block NSInteger i = [bookmarks count]; __block NSMutableArray *errors = nil; @@ -491,7 +496,7 @@ [urls addObject:url]; } - if ([self shouldOpenNumberOfDocuments:[urls count]] == NO) { + if ([self shouldOpenNumberOfDocuments:[urls count] warningLimit:WARNING_LIMIT] == NO) { urls = nil; if (outError) *outError = [NSError userCancelledErrorWithUnderlyingError:nil]; 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