From 5e4ba4f2663cf60a342d30d5cb9f08ca67b4bebc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mads=20M=C3=A6tzke=20Tandrup?= Date: Thu, 7 Nov 2013 07:14:01 +0100 Subject: [PATCH] Adding support to cocoa for receiving open URL events from the OS. Using the solution for bug 178927 as reference. But adds the event types to listen for URL events --- .../library/carbon/eclipseCarbon.c | 62 +++++++++++++++++++--- 1 file changed, 55 insertions(+), 7 deletions(-) diff --git a/bundles/org.eclipse.equinox.executable/library/carbon/eclipseCarbon.c b/bundles/org.eclipse.equinox.executable/library/carbon/eclipseCarbon.c index 7943957..2f5ad86 100644 --- a/bundles/org.eclipse.equinox.executable/library/carbon/eclipseCarbon.c +++ b/bundles/org.eclipse.equinox.executable/library/carbon/eclipseCarbon.c @@ -102,11 +102,14 @@ static NSWindow* window = nil; @interface AppleEventDelegate : NSObject - (void)handleOpenDocuments:(NSAppleEventDescriptor *)event withReplyEvent: (NSAppleEventDescriptor *)replyEvent; +- (void)handleGetURL:(NSAppleEventDescriptor *)event withReplyEvent: (NSAppleEventDescriptor *)replyEvent; @end @implementation AppleEventDelegate - NSTimer *timer; + NSTimer *timerOpenDocuments; NSMutableArray *files; - + NSTimer *timerOpenUrls; + NSMutableArray *urls; + - (void)handleOpenDocuments:(NSAppleEventDescriptor *)event withReplyEvent: (NSAppleEventDescriptor *)replyEvent { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; int count = [event numberOfItems]; @@ -135,21 +138,62 @@ static NSWindow* window = nil; } } - if (!timer) { - timer = [NSTimer scheduledTimerWithTimeInterval: 1.0 + if (!timerOpenDocuments) { + timerOpenDocuments = [NSTimer scheduledTimerWithTimeInterval: 1.0 target: self - selector: @selector(handleTimer:) + selector: @selector(handleOpenDocumentsTimer:) userInfo: nil repeats: YES]; } [pool release]; } -- (void) handleTimer: (NSTimer *) timer { + +- (void) handleOpenDocumentsTimer: (NSTimer *) timer { NSObject *delegate = [[NSApplication sharedApplication] delegate]; if (delegate != NULL && [delegate respondsToSelector: @selector(application:openFiles:)]) { [delegate performSelector:@selector(application:openFiles:) withObject:[NSApplication sharedApplication] withObject:files]; [files release]; - [timer invalidate]; + files = NULL; + [timerOpenDocuments invalidate]; + } +} + +- (void)handleGetURL:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent { + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + + NSString *url = [[event paramDescriptorForKeyword:keyDirectObject] stringValue]; + + NSObject *delegate = [[NSApplication sharedApplication] delegate]; + if (delegate != NULL && [delegate respondsToSelector: @selector(application:openUrls:)]) { + [delegate performSelector:@selector(application:openUrls:) withObject:[NSApplication sharedApplication] withObject:[NSArray arrayWithObject:url]]; + } else { + if (!urls) { + urls = [NSMutableArray arrayWithCapacity:1]; + [urls retain]; + } + + [urls addObject:url]; + + if (!timerOpenUrls) { + timerOpenUrls = [NSTimer scheduledTimerWithTimeInterval: 1.0 + target: self + selector: @selector(handleOpenUrlsTimer:) + userInfo: nil + repeats: YES]; + } + } + + [pool release]; +} + +- (void) handleOpenUrlsTimer: (NSTimer *) timer { + NSObject *delegate = [[NSApplication sharedApplication] delegate]; + if (delegate != NULL && [delegate respondsToSelector: @selector(application:openUrls:)]) { + [delegate performSelector:@selector(application:openUrls:) withObject:[NSApplication sharedApplication] withObject:urls]; + [urls release]; + urls = NULL; + [timerOpenUrls invalidate]; + timerOpenUrls = NULL; } } @end @@ -445,6 +489,10 @@ void installAppleEventHandler() { andSelector:@selector(handleOpenDocuments:withReplyEvent:) forEventClass:kCoreEventClass andEventID:kAEOpenDocuments]; + [manager setEventHandler:appleEventDelegate + andSelector:@selector(handleGetURL:withReplyEvent:) + forEventClass:kInternetEventClass + andEventID:kAEGetURL]; // [appleEventDelegate release]; [pool release]; #else -- 1.8.3.4 (Apple Git-47)