make url loading easier

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@28106 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2009-03-20 10:17:29 +00:00
parent 1878af00d9
commit c15df7fc8b
3 changed files with 48 additions and 25 deletions

View file

@ -1,6 +1,10 @@
2009-03-20 Richard Frith-Macdonald <rfm@gnu.org>
* 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 <FredKiefer@gmx.de>

View file

@ -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
{

View file

@ -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);
}
}