diff --git a/ChangeLog b/ChangeLog index 57104478f..82d2e28cb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2005-12-04 Richard Frith-Macdonald + + * Source/GSServicesManager.m: Implement use of NSUseRunningCopy + 2005-11-29 Fabien VALLON * Source/NSCachedImageRep.m : Improved documentation diff --git a/Source/GSServicesManager.m b/Source/GSServicesManager.m index 9b20adfe6..44b0a1ccf 100644 --- a/Source/GSServicesManager.m +++ b/Source/GSServicesManager.m @@ -324,6 +324,12 @@ NSRegisterServicesProvider(id provider, NSString *name) { id delegate = [[NSApplication sharedApplication] delegate]; + if ([selName isEqualToString: @"activateIgnoringOtherApps:"]) + { + [anInvocation invokeWithTarget: NSApp]; + return; + } + if ([selName hasPrefix: @"application:"] == YES) { if ([delegate respondsToSelector: aSel] == YES) @@ -1041,9 +1047,27 @@ static NSString *disabledName = @".GNUstepDisabled"; if (registered == NO) { - int result = NSRunAlertPanel(appName, - @"Application may already be running with this name", - @"Continue", @"Abort", @"Rename"); + NSUserDefaults *defs = [NSUserDefaults standardUserDefaults]; + NSString *def = [defs objectForKey: @"NSUseRunningCopy"]; + int result; + + if (def != nil) + { + if ([def boolValue] == YES) + { + result = NSAlertOtherReturn; + } + else + { + result = NSAlertAlternateReturn; + } + } + else + { + result = NSRunAlertPanel(appName, + @"Application may already be running with this name", + @"Continue", @"Abort", @"Rename"); + } if (result == NSAlertOtherReturn) { @@ -1102,6 +1126,27 @@ static NSString *disabledName = @".GNUstepDisabled"; NS_ENDHANDLER } + if (result == NSAlertAlternateReturn) + { + id app; + + /* + * Try to activate the other app and terminate self. + */ + app = [NSConnection rootProxyForConnectionWithRegisteredName: appName + host: @""]; + NS_DURING + { + [app activateIgnoringOtherApps: YES]; + } + NS_HANDLER + { + /* maybe it terminated. */ + } + NS_ENDHANDLER + registered = NO; + } + if (result == NSAlertDefaultReturn || result == NSAlertOtherReturn) { if (registered == NO)