Revision: 29274 http://sourceforge.net/p/bibdesk/svn/29274 Author: hofman Date: 2025-06-26 15:52:05 +0000 (Thu, 26 Jun 2025) Log Message: ----------- Open default file or last open files at any startup early (e.g. before opening a file)
Modified Paths: -------------- trunk/bibdesk/BDSKAppController.m Modified: trunk/bibdesk/BDSKAppController.m =================================================================== --- trunk/bibdesk/BDSKAppController.m 2025-06-26 09:15:32 UTC (rev 29273) +++ trunk/bibdesk/BDSKAppController.m 2025-06-26 15:52:05 UTC (rev 29274) @@ -95,13 +95,19 @@ #define BDSKDidMigrateLocalUrlFormatDefaultsKey @"BDSKDidMigrateLocalUrlFormatDefaultsKey" enum { - BDSKStartupOpenUntitledFile, - BDSKStartupDoNothing, - BDSKStartupOpenDialog, - BDSKStartupOpenDefaultFile, - BDSKStartupOpenLastOpenFiles + BDSKActivateAnyStartup, + BDSKActivateDefaultLaunch, + BDSKActivateReopen }; +enum { + BDSKOpenUntitledFile, + BDSKOpenNothing, + BDSKOpenDialog, + BDSKOpenDefaultFile, + BDSKOpenLastOpenFiles +}; + @implementation BDSKAppController // remove legacy comparisons of added/created/modified strings in table column code from prefs @@ -300,22 +306,24 @@ } } -- (void)openFilesAtStartup:(BOOL)atStartup { +- (void)openFilesOnActivation:(NSInteger)activation { switch ([[NSUserDefaults standardUserDefaults] integerForKey:BDSKStartupBehaviorKey]) { - case BDSKStartupOpenUntitledFile: - [[NSDocumentController sharedDocumentController] openUntitledDocumentAndDisplay:YES error:NULL]; + case BDSKOpenUntitledFile: + if (activation != BDSKActivateAnyStartup) + [[NSDocumentController sharedDocumentController] openUntitledDocumentAndDisplay:YES error:NULL]; break; - case BDSKStartupDoNothing: + case BDSKOpenNothing: break; - case BDSKStartupOpenDialog: - if (atStartup) + case BDSKOpenDialog: + if (activation == BDSKActivateDefaultLaunch) [[NSDocumentController sharedDocumentController] openDocument:nil]; break; - case BDSKStartupOpenDefaultFile: - [self openDefaultFile]; + case BDSKOpenDefaultFile: + if (activation != BDSKActivateDefaultLaunch) + [self openDefaultFile]; break; - case BDSKStartupOpenLastOpenFiles: - if (atStartup) + case BDSKOpenLastOpenFiles: + if (activation == BDSKActivateAnyStartup) [self openLastOpenFiles]; break; default: @@ -364,17 +372,20 @@ // this registered the value transformers for radio buttons [BDSKRadioTransformer class]; + + if ([sud boolForKey:BDSKIsRelaunchKey]) + [self openLastOpenFiles]; + else + [self openFilesOnActivation:BDSKActivateAnyStartup]; } - (void)applicationDidFinishLaunching:(NSNotification *)aNotification{ NSUserDefaults *sud = [NSUserDefaults standardUserDefaults]; - if ([sud boolForKey:BDSKIsRelaunchKey]) { + if ([sud boolForKey:BDSKIsRelaunchKey] == NO && [[[aNotification userInfo] objectForKey:NSApplicationLaunchIsDefaultLaunchKey] boolValue]) + [self openFilesOnActivation:BDSKActivateDefaultLaunch]; + else [sud removeObjectForKey:BDSKIsRelaunchKey]; - [self openLastOpenFiles]; - } else if ([[[aNotification userInfo] objectForKey:NSApplicationLaunchIsDefaultLaunchKey] boolValue]) { - [self openFilesAtStartup:YES]; - } // 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]]; @@ -424,6 +435,14 @@ [NSApp setAutomaticCustomizeTouchBarMenuItemEnabled:YES]; } +// we don't want to reopen last open files or show an Open dialog when re-activating the app +- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag { + if (flag) + return YES; + [self openFilesOnActivation:BDSKActivateReopen]; + return NO; +} + - (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender { return NO; } @@ -477,14 +496,6 @@ } } -// we don't want to reopen last open files or show an Open dialog when re-activating the app -- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag { - if (flag) - return YES; - [self openFilesAtStartup:NO]; - return NO; -} - - (void)applicationDidBecomeActive:(NSNotification *)aNotification{ [[NSNotificationCenter defaultCenter] postNotificationName:BDSKFlagsChangedNotification object:NSApp]; } 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