* Source/NSApplication.m: Attempt to open files from the command

line, if possible in -finishLaunching.  This matches the behavior
	seen on OpenStep and on Mac OS X/Cocoa.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@30407 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2010-05-17 08:29:55 +00:00
parent 06c9f9a37a
commit 3cdbf7591f
2 changed files with 47 additions and 1 deletions

View file

@ -1,3 +1,9 @@
2010-05-17 04:36-EDT Gregory John Casamento <greg.casamento@gmail.com>
* Source/NSApplication.m: Attempt to open files from the command
line, if possible in -finishLaunching. This matches the behavior
seen on OpenStep and on Mac OS X/Cocoa.
2010-05-16 Quentin Mathe <quentin.mathe@gmail.com>
* Source/Functions.m:

View file

@ -379,6 +379,7 @@ struct _NSModalSession {
- (void) _windowDidResignKey: (NSNotification*) notification;
- (void) _windowWillClose: (NSNotification*) notification;
- (void) _workspaceNotification: (NSNotification*) notification;
- (NSArray *) _openFiles;
@end
@interface NSWindow (ApplicationPrivate)
@ -958,6 +959,7 @@ static NSSize scaledIconSizeForSize(NSSize imageSize)
BOOL hadDuplicates = NO;
BOOL didAutoreopen = NO;
NSImage *image = nil;
NSArray *files = nil;
appIconFile = [infoDict objectForKey: @"NSIcon"];
if (appIconFile && ![appIconFile isEqual: @""])
@ -1107,7 +1109,17 @@ static NSSize scaledIconSizeForSize(NSSize imageSize)
* Now check to see if we were launched with arguments asking to
* open a file. We permit some variations on the default name.
*/
if ((filePath = [defs stringForKey: @"GSFilePath"]) != nil
if ((files = [self _openFiles]) != nil)
{
NSEnumerator *en = [files objectEnumerator];
filePath = nil;
while ((filePath = (NSString *)[en nextObject]) != nil)
{
[_listener application: self openFile: filePath];
}
}
else if ((filePath = [defs stringForKey: @"GSFilePath"]) != nil
|| (filePath = [defs stringForKey: @"NSOpen"]) != nil)
{
[_listener application: self openFile: filePath];
@ -4011,6 +4023,34 @@ struct _DelegateWrapper
}
}
- (NSArray *) _openFiles
{
NSMutableArray *files = nil;
NSArray *args = [[NSProcessInfo processInfo] arguments];
NSEnumerator *en = [args objectEnumerator];
NSString *file = nil;
[en nextObject]; // skip the first element, which is always empty...
while((file = [en nextObject]) != nil)
{
unichar c = [file characterAtIndex: 0];
if(c != '-')
{
if(files == nil)
{
files = [NSMutableArray array];
}
[files addObject: file];
}
else
{
break;
}
}
return files;
}
@end // NSApplication (Private)