Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMads Mætzke Tandrup2013-11-07 06:14:01 +0000
committerPascal Rapicault2015-10-11 01:03:57 +0000
commita112b30d15b5e21338cceb8b0dbf53e6cb95d74a (patch)
treed55fb15a8a9993894559743c012c77b962b5c99e /features/org.eclipse.equinox.executable.feature/library
parent898d143780c6887641a5b324bf1ff9c0cedb804e (diff)
downloadrt.equinox.framework-a112b30d15b5e21338cceb8b0dbf53e6cb95d74a.tar.gz
rt.equinox.framework-a112b30d15b5e21338cceb8b0dbf53e6cb95d74a.tar.xz
rt.equinox.framework-a112b30d15b5e21338cceb8b0dbf53e6cb95d74a.zip
[351303] Adding support to Cocoa for receiving open URL events from the OS X.
Using the solution for bug 178927 as reference. But adds the kAEGetURL event type to listen for URL events. Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=351303 Change-Id: Ibab65db8f370c71691befed45ead34126e7a63cc Signed-off-by: Mads Mætzke Tandrup <mads@maetzke-tandrup.dk>
Diffstat (limited to 'features/org.eclipse.equinox.executable.feature/library')
-rw-r--r--features/org.eclipse.equinox.executable.feature/library/carbon/eclipseCarbon.c62
1 files changed, 55 insertions, 7 deletions
diff --git a/features/org.eclipse.equinox.executable.feature/library/carbon/eclipseCarbon.c b/features/org.eclipse.equinox.executable.feature/library/carbon/eclipseCarbon.c
index 024f524d7..61bdb8eb3 100644
--- a/features/org.eclipse.equinox.executable.feature/library/carbon/eclipseCarbon.c
+++ b/features/org.eclipse.equinox.executable.feature/library/carbon/eclipseCarbon.c
@@ -162,11 +162,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];
@@ -195,21 +198,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
@@ -487,6 +531,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

Back to the top