Fix for opening files with relative paths.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@17964 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2003-10-24 09:29:43 +00:00
parent e109b8d959
commit 12ea75e949
3 changed files with 39 additions and 13 deletions

View file

@ -1,3 +1,11 @@
2003-10-24 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSWorkspace.m: Change a few uses of '/' in stgrings to
use stringByAppendingPatchComponent:
* Tools/gopen.m: Fix to pass the full path of the file to the
app being used to open it, so relative paths in the arguments
work properly.
2003-10-21 Bjorn Giesler <bjoern@giesler.de>
* Source/GSServicesManager.m: Fix NSPerformService() to work for

View file

@ -1105,7 +1105,7 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath
}
/**
* <p>Launches the specified application (unless it is alreeady running).<br />
* <p>Launches the specified application (unless it is already running).<br />
* If the autolaunch flag is yes, sets the autolaunch user default for the
* newly launched application, so that applications which understand the
* concept of being autolaunched at system startup time can modify their
@ -1528,7 +1528,7 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath
}
else
{
path = [path stringByAppendingFormat: @"/%@", file];
path = [path stringByAppendingPathComponent: file];
}
}
@ -1644,7 +1644,8 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath
*/
if (iconPath == nil)
{
iconPath = [[bundle bundlePath] stringByAppendingPathComponent: file];
iconPath = [[bundle bundlePath]
stringByAppendingPathComponent: file];
}
file = iconPath;
}
@ -1712,7 +1713,7 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath
absolute = [[NSURL fileURLWithPath: [file stringByStandardizingPath]]
absoluteString];
// This compensates for a bug we have in NSURL, that is there to have
// This compensates for a feature we have in NSURL, that is there to have
// MacOSX compatibility.
if ([absolute hasPrefix: @"file://localhost/"])
{

View file

@ -35,6 +35,17 @@
#include <AppKit/NSApplication.h>
#include <AppKit/NSWorkspace.h>
static NSString*
absolutePath(NSFileManager *fm, NSString *path)
{
path = [path stringByStandardizingPath];
if ([path isAbsolutePath] == NO)
{
path = [[fm currentDirectoryPath] stringByAppendingPathComponent: path];
}
return path;
}
int
main(int argc, char** argv, char **env_c)
{
@ -79,12 +90,14 @@ main(int argc, char** argv, char **env_c)
if (filetoopen)
{
filetoopen = absolutePath(fm, filetoopen);
[workspace openFile: filetoopen
withApplication: application];
withApplication: application];
}
if (filetoprint)
{
filetoprint = absolutePath(fm, filetoprint);
puts("Not implemented");
}
@ -95,11 +108,11 @@ main(int argc, char** argv, char **env_c)
if (argc == 1)
{
NSFileHandle *fh = [NSFileHandle fileHandleWithStandardInput];
NSData *data = [fh readDataToEndOfFile];
NSString *tempFile = [NSTemporaryDirectory()
NSFileHandle *fh = [NSFileHandle fileHandleWithStandardInput];
NSData *data = [fh readDataToEndOfFile];
NSString *tempFile = [NSTemporaryDirectory()
stringByAppendingPathComponent: @"openfiletmp"];
NSNumber *processId = [NSNumber numberWithInt:
NSNumber *processId = [NSNumber numberWithInt:
[[NSProcessInfo processInfo] processIdentifier]];
tempFile = [tempFile stringByAppendingString: [processId stringValue]];
@ -140,6 +153,10 @@ main(int argc, char** argv, char **env_c)
BOOL isDir = NO, exists = NO;
exists = [fm fileExistsAtPath: arg isDirectory: &isDir];
if (exists == YES)
{
arg = absolutePath(fm, arg);
}
if (exists && !isDir && [fm isExecutableFileAtPath: arg])
{
[workspace openFile: arg withApplication: terminal];
@ -147,9 +164,9 @@ main(int argc, char** argv, char **env_c)
else // no argument specified
{
// First check to see if it's an application
if ([ext isEqualToString: @"app"] ||
[ext isEqualToString: @"debug"] ||
[ext isEqualToString: @"profile"])
if ([ext isEqualToString: @"app"]
|| [ext isEqualToString: @"debug"]
|| [ext isEqualToString: @"profile"])
{
NSString *appName =
[[arg lastPathComponent] stringByDeletingPathExtension];
@ -172,7 +189,7 @@ main(int argc, char** argv, char **env_c)
else
{
if (![workspace openFile: arg
withApplication: application])
withApplication: application])
{
// no recognized extension,
// run application indicated by environment var.