first attempt at implementing -openURL: for NSWorkspace

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@27846 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2009-02-11 13:13:19 +00:00
parent bee145baba
commit 093bd1976e
3 changed files with 154 additions and 3 deletions

View file

@ -65,6 +65,7 @@
#include "AppKit/NSWorkspace.h"
#include "AppKit/NSApplication.h"
#include "AppKit/NSImage.h"
#include "AppKit/NSPasteboard.h"
#include "AppKit/NSView.h"
#include "AppKit/NSPanel.h"
#include "AppKit/NSWindow.h"
@ -803,7 +804,55 @@ static NSString *_rootPath = @"/";
}
else
{
return NO;
NSDictionary *map;
NSString *appName;
/* Look up an application to handle this URL scheme.
*/
map = [applications objectForKey: @"GSSchemesMap"];
appName = [map objectForKey: [[url scheme] lowercaseString]];
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
{
NS_DURING
{
[app application: NSApp openFile: urlString];
}
NS_HANDLER
{
NSWarnLog(@"Failed to contact '%@' to open file", appName);
return NO;
}
NS_ENDHANDLER
}
[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);
}
}
}