Try to improve interface with workspace application.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@22374 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2006-01-27 17:09:27 +00:00
parent 5cec8a846e
commit 26661e35d7
2 changed files with 173 additions and 38 deletions

View file

@ -2,9 +2,11 @@
* Source/NSApplication.m: pass more informative user info in * Source/NSApplication.m: pass more informative user info in
notifications. notifications.
* Source/NSWorkspace.m: implement filesystem based fallback mechanisms * Source/NSWorkspace.m: Implement filesystem based fallback mechanisms
for tracking launched and active appplications when there is no for tracking launched and active appplications when there is no
workspace manager process to do it. workspace manager process to do it.
Try to be consistent about asking workspace manager application to
perform tasks for us if it exists.
2006-01-22 Fred Kiefer <FredKiefer@gmx.de> 2006-01-22 Fred Kiefer <FredKiefer@gmx.de>

View file

@ -55,6 +55,7 @@
#include <Foundation/NSDistributedNotificationCenter.h> #include <Foundation/NSDistributedNotificationCenter.h>
#include <Foundation/NSConnection.h> #include <Foundation/NSConnection.h>
#include <Foundation/NSDebug.h> #include <Foundation/NSDebug.h>
#include <Foundation/NSThread.h>
#include <Foundation/NSURL.h> #include <Foundation/NSURL.h>
#include <Foundation/NSValue.h> #include <Foundation/NSValue.h>
#include "AppKit/NSWorkspace.h" #include "AppKit/NSWorkspace.h"
@ -106,6 +107,11 @@ static id GSLaunched(NSNotification *notification, BOOL active)
} }
if ([lock tryLock] == NO) if ([lock tryLock] == NO)
{ {
unsigned sleeps = 0;
/*
* If the lock is really old ... assume the app has died and break it.
*/
if ([[lock lockDate] timeIntervalSinceNow] < -20.0) if ([[lock lockDate] timeIntervalSinceNow] < -20.0)
{ {
NS_DURING NS_DURING
@ -118,7 +124,19 @@ static id GSLaunched(NSNotification *notification, BOOL active)
} }
NS_ENDHANDLER NS_ENDHANDLER
} }
if ([lock tryLock] == NO) /*
* Retry locking several times if necessary before giving up.
*/
for (sleeps = 0; sleeps < 10; sleeps++)
{
if ([lock tryLock] == YES)
{
break;
}
sleeps++;
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.1]];
}
if (sleeps >= 10)
{ {
NSLog(@"Unable to obtain lock %@", lock); NSLog(@"Unable to obtain lock %@", lock);
return nil; return nil;
@ -681,6 +699,22 @@ static NSString *_rootPath = @"/";
{ {
id app; id app;
NS_DURING
{
if ((app = [self _workspaceApplication]) != nil)
{
BOOL result;
result = [app openFile: fullPath
withApplication: appName
andDeactivate: flag];
NS_VALRETURN(result);
}
}
NS_HANDLER
// workspace manager problem ... fall through to default code
NS_ENDHANDLER
if (appName == nil) if (appName == nil)
{ {
NSString *ext = [fullPath pathExtension]; NSString *ext = [fullPath pathExtension];
@ -731,8 +765,23 @@ static NSString *_rootPath = @"/";
{ {
id app; id app;
NSString *appName; NSString *appName;
NSString *ext = [fullPath pathExtension]; NSString *ext;
NS_DURING
{
if ((app = [self _workspaceApplication]) != nil)
{
BOOL result;
result = [app openTempFile: fullPath];
NS_VALRETURN(result);
}
}
NS_HANDLER
// workspace manager problem ... fall through to default code
NS_ENDHANDLER
ext = [fullPath pathExtension];
if ([self _extension: ext role: nil app: &appName] == NO) if ([self _extension: ext role: nil app: &appName] == NO)
{ {
NSWarnLog(@"No known applications for file extension '%@'", ext); NSWarnLog(@"No known applications for file extension '%@'", ext);
@ -787,38 +836,50 @@ static NSString *_rootPath = @"/";
files: (NSArray*)files files: (NSArray*)files
tag: (int*)tag tag: (int*)tag
{ {
id app = [self _workspaceApplication]; id app;
if (app == nil) NS_DURING
{ {
return NO; if ((app = [self _workspaceApplication]) != nil)
} {
else BOOL result;
{
// Send the request on to the Workspace application result = [app performFileOperation: operation
return [app performFileOperation: operation source: source
source: source destination: destination
destination: destination files: files
files: files tag: tag];
tag: tag]; NS_VALRETURN(result);
}
} }
NS_HANDLER
// workspace manager problem ... fall through to default code
NS_ENDHANDLER
return NO;
} }
- (BOOL) selectFile: (NSString*)fullPath - (BOOL) selectFile: (NSString*)fullPath
inFileViewerRootedAtPath: (NSString*)rootFullpath inFileViewerRootedAtPath: (NSString*)rootFullpath
{ {
id app = [self _workspaceApplication]; id app;
if (app == nil) NS_DURING
{ {
return NO; if ((app = [self _workspaceApplication]) != nil)
} {
else BOOL result;
{
// Send the request on to the Workspace application result = [app selectFile: fullPath
return [app selectFile: fullPath inFileViewerRootedAtPath: rootFullpath];
inFileViewerRootedAtPath: rootFullpath]; NS_VALRETURN(result);
}
} }
NS_HANDLER
// workspace manager problem ... fall through to default code
NS_ENDHANDLER
return NO;
} }
/** /**
@ -1305,7 +1366,23 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath
showIcon: (BOOL)showIcon showIcon: (BOOL)showIcon
autolaunch: (BOOL)autolaunch autolaunch: (BOOL)autolaunch
{ {
id app; id app;
NS_DURING
{
if ((app = [self _workspaceApplication]) != nil)
{
BOOL result;
result = [app launchApplication: appName
showIcon: showIcon
autolaunch: autolaunch];
NS_VALRETURN(result);
}
}
NS_HANDLER
// workspace manager problem ... fall through to default code
NS_ENDHANDLER
app = [self _connectApplication: appName]; app = [self _connectApplication: appName];
if (app == nil) if (app == nil)
@ -1334,6 +1411,22 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath
*/ */
- (NSDictionary*) activeApplication - (NSDictionary*) activeApplication
{ {
id app;
NS_DURING
{
if ((app = [self _workspaceApplication]) != nil)
{
NSDictionary *result;
result = [app activeApplication];
NS_VALRETURN(result);
}
}
NS_HANDLER
// workspace manager problem ... fall through to default code
NS_ENDHANDLER
return GSLaunched(nil, YES); return GSLaunched(nil, YES);
} }
@ -1345,6 +1438,22 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath
*/ */
- (NSArray*) launchedApplications - (NSArray*) launchedApplications
{ {
id app;
NS_DURING
{
if ((app = [self _workspaceApplication]) != nil)
{
NSArray *result;
result = [app launchedApplications];
NS_VALRETURN(result);
}
}
NS_HANDLER
// workspace manager problem ... fall through to default code
NS_ENDHANDLER
return GSLaunched(nil, NO); return GSLaunched(nil, NO);
} }
@ -1566,18 +1675,23 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath
*/ */
- (int) extendPowerOffBy: (int)requested - (int) extendPowerOffBy: (int)requested
{ {
int result = 0; id app;
id app = [self _workspaceApplication];
if (app != nil) NS_DURING
{ {
NS_DURING if ((app = [self _workspaceApplication]) != nil)
result = [app extendPowerOffBy: requested]; {
NS_HANDLER int result;
result = 0;
NS_ENDHANDLER result = [app extendPowerOffBy: requested];
NS_VALRETURN(result);
}
} }
return result; NS_HANDLER
// workspace manager problem ... fall through to default code
NS_ENDHANDLER
return 0;
} }
@end @end
@ -2417,16 +2531,35 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath
- (id) _workspaceApplication - (id) _workspaceApplication
{ {
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults]; static NSUserDefaults *defs = nil;
NSString *appName; static GSServicesManager *smgr = nil;
id app; NSString *appName;
NSString *myName;
id app;
if (defs == nil)
{
defs = RETAIN([NSUserDefaults standardUserDefaults]);
}
if (smgr == nil)
{
smgr = RETAIN([GSServicesManager manager]);
}
/* What Workspace application? */ /* What Workspace application? */
appName = [defs stringForKey: @"GSWorkspaceApplication"]; appName = [defs stringForKey: @"GSWorkspaceApplication"];
if (appName == nil) if (appName == nil)
{ {
appName = @"GWorkspace"; appName = @"GWorkspace";
} }
/*
* If this app is the workspace app, there is no sense contacting
* it as it would cause recursion ... so we return nil.
*/
myName = [smgr port];
if ([appName isEqual: myName] == YES)
{
return nil;
}
app = [self _connectApplication: appName]; app = [self _connectApplication: appName];
if (app == nil) if (app == nil)