diff --git a/ChangeLog b/ChangeLog index 7617217aa..cbb47d92a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,10 @@ 2009-03-20 Richard Frith-Macdonald * Tools/gopen.m: Extend to open URLs as well as files. + * Source/GSServicesManager.m: + * Source/NSSworkspace.m: + Additions so that any app using a document controller can open a URL + (also any app where its delegate implements -application:openURL:). 2009-03-20 Fred Kiefer diff --git a/Source/GSServicesManager.m b/Source/GSServicesManager.m index c41304983..509d8290e 100644 --- a/Source/GSServicesManager.m +++ b/Source/GSServicesManager.m @@ -340,7 +340,7 @@ NSRegisterServicesProvider(id provider, NSString *name) /* * We assume that messages of the form 'application:...' are all - * safe and do mnot need to be listed in GSPermittedMessages. + * safe and do not need to be listed in GSPermittedMessages. * They can be handled either by the application delegate or by * the shared GSServicesManager instance. */ @@ -618,6 +618,31 @@ static NSString *disabledName = @".GNUstepDisabled"; return result; } +- (BOOL) application: (NSApplication*)theApp + openURL: (NSURL*)aURL +{ + id del = [NSApp delegate]; + BOOL result = NO; + + if ([del respondsToSelector: _cmd]) + { + result = [del application: theApp openURL: aURL]; + } + else if ([[NSDocumentController sharedDocumentController] + openDocumentWithContentsOfURL: aURL display: YES] != nil) + { + [NSApp activateIgnoringOtherApps: YES]; + result = YES; + } + else + { + NSString *s = [aURL absoluteString]; + + result = [self application: theApp openFile: s]; + } + return result; +} + - (BOOL) application: (NSApplication*)theApp printFile: (NSString*)file { diff --git a/Source/NSWorkspace.m b/Source/NSWorkspace.m index c894640a9..9846baae6 100644 --- a/Source/NSWorkspace.m +++ b/Source/NSWorkspace.m @@ -73,6 +73,12 @@ #include "GNUstepGUI/GSServicesManager.h" #include "GNUstepGUI/GSDisplayServer.h" +/* Informal protocol for method to ask an app to open a URL. + */ +@interface NSObject (OpenURL) +- (BOOL) application: (NSApplication*)a openURL: (NSURL*)u; +@end + /* Private method to check that a process exists. */ @interface NSProcessInfo (Private) @@ -806,6 +812,7 @@ static NSString *_rootPath = @"/"; { NSDictionary *map; NSString *appName; + NSPasteboard *pb; /* Look up an application to handle this URL scheme. * We get a dictionary containing all apps for the scheme. @@ -817,24 +824,16 @@ static NSString *_rootPath = @"/"; appName = [[map allKeys] lastObject]; if (appName != nil) { - NSString *urlString = [url absoluteString]; id app; /* Now try to get the application to open the URL. */ - app = [self _connectApplication: appName]; - if (app == nil) - { - NSArray *args; - - args = [NSArray arrayWithObjects: @"-GSFilePath", urlString, nil]; - return [self _launchApplication: appName arguments: args]; - } - else + app = GSContactApplication(appName, nil, nil); + if (app != nil) { NS_DURING { - [app application: NSApp openFile: urlString]; + [app application: NSApp openURL: url]; } NS_HANDLER { @@ -842,21 +841,16 @@ static NSString *_rootPath = @"/"; return NO; } NS_ENDHANDLER + [NSApp deactivate]; + return YES; } - [NSApp deactivate]; - return YES; - } - else - { - NSPasteboard *pb; - - /* No application found to open the URL. - * Try any OpenURL service available. - */ - pb = [NSPasteboard pasteboardWithUniqueName]; - [url writeToPasteboard: pb]; - return NSPerformService(@"OpenURL", pb); } + /* No application found to open the URL. + * Try any OpenURL service available. + */ + pb = [NSPasteboard pasteboardWithUniqueName]; + [url writeToPasteboard: pb]; + return NSPerformService(@"OpenURL", pb); } }