Implement user default to select behavior with multiple copies of app

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@22133 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2005-12-04 08:44:54 +00:00
parent 0cfe83b02f
commit bd69452e95
2 changed files with 52 additions and 3 deletions

View file

@ -1,3 +1,7 @@
2005-12-04 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSServicesManager.m: Implement use of NSUseRunningCopy
2005-11-29 Fabien VALLON <fabien@sonappart.net>
* Source/NSCachedImageRep.m : Improved documentation

View file

@ -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)