Revision: 29272 http://sourceforge.net/p/bibdesk/svn/29272 Author: hofman Date: 2025-06-25 22:28:57 +0000 (Wed, 25 Jun 2025) Log Message: ----------- separate methods to open last open files and default file, open last open files after relaunch separately in applicationDidFinishLaunching
Modified Paths: -------------- trunk/bibdesk/BDSKAppController.h trunk/bibdesk/BDSKAppController.m Modified: trunk/bibdesk/BDSKAppController.h =================================================================== --- trunk/bibdesk/BDSKAppController.h 2025-06-25 14:48:22 UTC (rev 29271) +++ trunk/bibdesk/BDSKAppController.h 2025-06-25 22:28:57 UTC (rev 29272) @@ -49,7 +49,6 @@ IBOutlet NSMenu *bookmarksMenu; IBOutlet NSMenu *historyMenu; IBOutlet NSMenu *shareMenu; - BOOL didReopen; } - (IBAction)visitWebSite:(nullable id)sender; Modified: trunk/bibdesk/BDSKAppController.m =================================================================== --- trunk/bibdesk/BDSKAppController.m 2025-06-25 14:48:22 UTC (rev 29271) +++ trunk/bibdesk/BDSKAppController.m 2025-06-25 22:28:57 UTC (rev 29272) @@ -284,12 +284,24 @@ #pragma clang diagnostic pop } +- (void)openDefaultFile { + NSUserDefaults *sud = [NSUserDefaults standardUserDefaults]; + NSURL *fileURL = [NSURL fileURLWithAliasData:[sud objectForKey:BDSKDefaultBibFileAliasKey] bookmarkData:[sud objectForKey:BDSKDefaultBibFileBookmarkKey]]; + if (fileURL && NO == fileIsInTrash(fileURL)) + [[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:fileURL display:YES completionHandler:^(NSDocument *document, BOOL documentWasAlreadyOpen, NSError *error){}]; +} + +- (void)openLastOpenFiles { + NSArray *files = [[NSUserDefaults standardUserDefaults] objectForKey:BDSKLastOpenFileNamesKey]; + for (NSDictionary *dict in [files reverseObjectEnumerator]){ + NSURL *fileURL = [NSURL fileURLWithAliasData:[dict objectForKey:@"_BDAlias"] bookmarkData:[dict objectForKey:@"bookmark"]] ?: [NSURL fileURLWithPath:[dict objectForKey:@"fileName"] isDirectory:NO]; + if (fileURL && NO == fileIsInTrash(fileURL)) + [[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:fileURL display:YES completionHandler:^(NSDocument *document, BOOL documentWasAlreadyOpen, NSError *error){}]; + } +} + - (void)openFilesAtStartup { - didReopen = YES; - NSUserDefaults *sud = [NSUserDefaults standardUserDefaults]; - NSInteger option = [sud boolForKey:BDSKIsRelaunchKey] ? BDSKStartupOpenLastOpenFiles : [sud integerForKey:BDSKStartupBehaviorKey]; - [sud removeObjectForKey:BDSKIsRelaunchKey]; - switch (option) { + switch ([[NSUserDefaults standardUserDefaults] integerForKey:BDSKStartupBehaviorKey]) { case BDSKStartupOpenUntitledFile: [[NSDocumentController sharedDocumentController] openUntitledDocumentAndDisplay:YES error:NULL]; break; @@ -299,22 +311,10 @@ [[NSDocumentController sharedDocumentController] openDocument:nil]; break; case BDSKStartupOpenDefaultFile: - { - NSURL *fileURL = [NSURL fileURLWithAliasData:[sud objectForKey:BDSKDefaultBibFileAliasKey] bookmarkData:[sud objectForKey:BDSKDefaultBibFileBookmarkKey]]; - if (fileURL && NO == fileIsInTrash(fileURL)) - [[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:fileURL display:YES completionHandler:^(NSDocument *document, BOOL documentWasAlreadyOpen, NSError *error){}]; - } + [self openDefaultFile]; break; case BDSKStartupOpenLastOpenFiles: - { - NSArray *files = [sud objectForKey:BDSKLastOpenFileNamesKey]; - NSURL *fileURL; - for (NSDictionary *dict in [files reverseObjectEnumerator]){ - fileURL = [NSURL fileURLWithAliasData:[dict objectForKey:@"_BDAlias"] bookmarkData:[dict objectForKey:@"bookmark"]] ?: [NSURL fileURLWithPath:[dict objectForKey:@"fileName"] isDirectory:NO]; - if (fileURL && NO == fileIsInTrash(fileURL)) - [[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:fileURL display:YES completionHandler:^(NSDocument *document, BOOL documentWasAlreadyOpen, NSError *error){}]; - } - } + [self openLastOpenFiles]; break; default: break; @@ -362,14 +362,17 @@ // this registered the value transformers for radio buttons [BDSKRadioTransformer class]; - - if ([sud boolForKey:BDSKIsRelaunchKey]) - [self openFilesAtStartup]; } - (void)applicationDidFinishLaunching:(NSNotification *)aNotification{ - if (didReopen == NO && [[[aNotification userInfo] objectForKey:NSApplicationLaunchIsDefaultLaunchKey] boolValue]) + NSUserDefaults *sud = [NSUserDefaults standardUserDefaults]; + + if ([sud boolForKey:BDSKIsRelaunchKey]) { + [sud removeObjectForKey:BDSKIsRelaunchKey]; + [self openLastOpenFiles]; + } else if ([[[aNotification userInfo] objectForKey:NSApplicationLaunchIsDefaultLaunchKey] boolValue]) { [self openFilesAtStartup]; + } // register our help book, so it's available for methods that don't register this, e.g. the web group [[NSHelpManager sharedHelpManager] registerBooksInBundle:[NSBundle mainBundle]]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Bibdesk-commit mailing list Bibdesk-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bibdesk-commit