mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 16:10:48 +00:00
Pass args to newly launched app to tell it what to do.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4347 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
f67aa2a775
commit
192d75fa42
2 changed files with 106 additions and 67 deletions
|
@ -154,6 +154,7 @@
|
|||
forExtension: (NSString*)ext;
|
||||
- (NSString*) getBestIconForExtension: (NSString*)ext;
|
||||
- (NSDictionary*) infoForExtension: (NSString*)ext;
|
||||
- (NSString*) locateApplicationBinary: (NSString*)appName;
|
||||
- (void) setBestApp: (NSString*)appName
|
||||
inRole: (NSString*)role
|
||||
forExtension: (NSString*)ext;
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#include <Foundation/NSProcessInfo.h>
|
||||
#include <Foundation/NSFileManager.h>
|
||||
#include <Foundation/NSNotificationQueue.h>
|
||||
#include <Foundation/NSConnection.h>
|
||||
|
||||
#define stringify_it(X) #X
|
||||
#define mkpath(X) stringify_it(X) "/Tools"
|
||||
|
@ -512,39 +513,67 @@ extIconForApp(NSWorkspace *ws, NSString *appName, NSDictionary *typeInfo)
|
|||
andDeactivate: (BOOL)flag
|
||||
{
|
||||
NSString *port = [appName stringByDeletingPathExtension];
|
||||
NSDate *finish = [NSDate dateWithTimeIntervalSinceNow: 30.0];
|
||||
id app;
|
||||
|
||||
/*
|
||||
* Try to connect to the application - launches if necessary.
|
||||
* Try to contact a running application.
|
||||
*/
|
||||
app = GSContactApplication(appName, port, finish);
|
||||
if (app == nil)
|
||||
{
|
||||
NSRunAlertPanel(nil,
|
||||
[NSString stringWithFormat:
|
||||
@"Failed to contact '%@' to open file", port],
|
||||
@"Continue", nil, nil);
|
||||
return NO;
|
||||
}
|
||||
|
||||
NS_DURING
|
||||
{
|
||||
if (flag == NO)
|
||||
[app application: nil openFileWithoutUI: fullPath];
|
||||
else
|
||||
[app application: nil openFile: fullPath];
|
||||
app = [NSConnection rootProxyForConnectionWithRegisteredName: port
|
||||
host: @""];
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
NSRunAlertPanel(nil,
|
||||
[NSString stringWithFormat:
|
||||
@"Failed to contact '%@' to open file", port],
|
||||
@"Continue", nil, nil);
|
||||
return NO;
|
||||
app = nil; /* Fatal error in DO */
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
|
||||
if (app == nil)
|
||||
{
|
||||
NSString *path;
|
||||
NSArray *args;
|
||||
|
||||
path = [self locateApplicationBinary: appName];
|
||||
if (path == nil)
|
||||
{
|
||||
NSRunAlertPanel(nil,
|
||||
[NSString stringWithFormat:
|
||||
@"Failed to locate '%@' to open file", port],
|
||||
@"Continue", nil, nil);
|
||||
return NO;
|
||||
}
|
||||
args = [NSArray arrayWithObjects: @"-GSFilePath", fullPath, nil];
|
||||
if ([NSTask launchedTaskWithLaunchPath: path arguments: args] == nil)
|
||||
{
|
||||
NSRunAlertPanel(nil,
|
||||
[NSString stringWithFormat:
|
||||
@"Failed to launch '%@' to open file", port],
|
||||
@"Continue", nil, nil);
|
||||
return NO;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
NS_DURING
|
||||
{
|
||||
if (flag == NO)
|
||||
[app application: nil openFileWithoutUI: fullPath];
|
||||
else
|
||||
[app application: nil openFile: fullPath];
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
NSRunAlertPanel(nil,
|
||||
[NSString stringWithFormat:
|
||||
@"Failed to contact '%@' to open file", port],
|
||||
@"Continue", nil, nil);
|
||||
return NO;
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
}
|
||||
|
||||
if (flag)
|
||||
[[NSApplication sharedApplication] deactivate];
|
||||
|
||||
|
@ -797,55 +826,10 @@ inFileViewerRootedAtPath: (NSString *)rootFullpath
|
|||
autolaunch: (BOOL)autolaunch
|
||||
{
|
||||
NSString *path;
|
||||
NSString *file;
|
||||
NSBundle *bundle;
|
||||
|
||||
if (appName == nil)
|
||||
return NO;
|
||||
|
||||
path = appName;
|
||||
appName = [path lastPathComponent];
|
||||
if ([appName isEqual: path])
|
||||
{
|
||||
path = [self fullPathForApplication: appName];
|
||||
appName = [[path lastPathComponent] stringByDeletingPathExtension];
|
||||
}
|
||||
else if ([appName pathExtension] == nil)
|
||||
{
|
||||
path = [path stringByAppendingPathExtension: @"app"];
|
||||
}
|
||||
else
|
||||
{
|
||||
appName = [[path lastPathComponent] stringByDeletingPathExtension];
|
||||
}
|
||||
|
||||
path = [self locateApplicationBinary: appName];
|
||||
if (path == nil)
|
||||
return NO;
|
||||
|
||||
/*
|
||||
* See if the 'Info-gnustep.plist' specifies the location of the
|
||||
* executable - if it does, replace our app name with the specified
|
||||
* value. If the executable name is an absolute path name, we also
|
||||
* replace the path with that specified.
|
||||
*/
|
||||
bundle = [NSBundle bundleWithPath: path];
|
||||
file = [[bundle infoDictionary] objectForKey: @"NSExecutable"];
|
||||
if (file != nil)
|
||||
{
|
||||
NSString *exepath;
|
||||
|
||||
appName = [file lastPathComponent];
|
||||
exepath = [file stringByDeletingLastPathComponent];
|
||||
if ([exepath isEqualToString: @""] == NO)
|
||||
{
|
||||
if ([file isAbsolutePath] == YES)
|
||||
path = exepath;
|
||||
else
|
||||
path = [path stringByAppendingPathComponent: exepath];
|
||||
}
|
||||
}
|
||||
|
||||
path = [path stringByAppendingPathComponent: appName];
|
||||
if ([NSTask launchedTaskWithLaunchPath: path arguments: nil] == nil)
|
||||
return NO;
|
||||
return YES;
|
||||
|
@ -980,6 +964,60 @@ inFileViewerRootedAtPath: (NSString *)rootFullpath
|
|||
return [map objectForKey: ext];
|
||||
}
|
||||
|
||||
- (NSString*) locateApplicationBinary: (NSString*)appName
|
||||
{
|
||||
NSString *path;
|
||||
NSString *file;
|
||||
NSBundle *bundle;
|
||||
|
||||
if (appName == nil)
|
||||
return nil;
|
||||
|
||||
path = appName;
|
||||
appName = [path lastPathComponent];
|
||||
if ([appName isEqual: path])
|
||||
{
|
||||
path = [self fullPathForApplication: appName];
|
||||
appName = [[path lastPathComponent] stringByDeletingPathExtension];
|
||||
}
|
||||
else if ([appName pathExtension] == nil)
|
||||
{
|
||||
path = [path stringByAppendingPathExtension: @"app"];
|
||||
}
|
||||
else
|
||||
{
|
||||
appName = [[path lastPathComponent] stringByDeletingPathExtension];
|
||||
}
|
||||
|
||||
if (path == nil)
|
||||
return nil;
|
||||
|
||||
/*
|
||||
* See if the 'Info-gnustep.plist' specifies the location of the
|
||||
* executable - if it does, replace our app name with the specified
|
||||
* value. If the executable name is an absolute path name, we also
|
||||
* replace the path with that specified.
|
||||
*/
|
||||
bundle = [NSBundle bundleWithPath: path];
|
||||
file = [[bundle infoDictionary] objectForKey: @"NSExecutable"];
|
||||
if (file != nil)
|
||||
{
|
||||
NSString *exepath;
|
||||
|
||||
appName = [file lastPathComponent];
|
||||
exepath = [file stringByDeletingLastPathComponent];
|
||||
if ([exepath isEqualToString: @""] == NO)
|
||||
{
|
||||
if ([file isAbsolutePath] == YES)
|
||||
path = exepath;
|
||||
else
|
||||
path = [path stringByAppendingPathComponent: exepath];
|
||||
}
|
||||
}
|
||||
|
||||
return [path stringByAppendingPathComponent: appName];
|
||||
}
|
||||
|
||||
- (void) setBestApp: (NSString*)appName
|
||||
inRole: (NSString*)role
|
||||
forExtension: (NSString*)ext
|
||||
|
|
Loading…
Reference in a new issue