diff --git a/Classes/Controllers/ApplicationController.m b/Classes/Controllers/ApplicationController.m
index 8225ab685..8ffd63982 100644
--- a/Classes/Controllers/ApplicationController.m
+++ b/Classes/Controllers/ApplicationController.m
@@ -98,9 +98,47 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification
setenv( "DISPLAY", "localhost:0", 1 );
[self registerServices];
+
+ [[NSAppleEventManager sharedAppleEventManager] setEventHandler: self andSelector: @selector(handleGetURLEvent:withReplyEvent:) forEventClass: kInternetEventClass andEventID: kAEGetURL];
+
started = YES;
}
+- (void)handleGetURLEvent: (NSAppleEventDescriptor *)event withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
+{
+ NSURL *url = [NSURL URLWithString: [[event paramDescriptorForKeyword: keyDirectObject] stringValue]];
+ if ([url.scheme.lowercaseString isEqualToString: @"gitx"]) {
+ [self handleGitXURL: url];
+ }
+}
+
+- (void)handleGitXURL: (NSURL *)url;
+{
+ NSString *command = url.host.lowercaseString;
+ if ([command isEqualToString: @"clonerepo"]) {
+ [self showClonePanelForURL: url.path];
+ return;
+ }
+}
+
+- (void)showClonePanelForURL: (NSString *)url;
+{
+ if (!cloneRepositoryPanel) {
+ cloneRepositoryPanel = [PBCloneRepositoryPanel panel];
+ }
+
+ if (url) {
+ NSRegularExpression *expr = [NSRegularExpression regularExpressionWithPattern: @"^/[a-z][a-z0-9+.-]*://" options: NSRegularExpressionCaseInsensitive error: NULL];
+ if ([expr rangeOfFirstMatchInString: url options: 0 range: NSMakeRange( 0, url.length )].location != NSNotFound) {
+ url = [url substringFromIndex: 1];
+ }
+ }
+
+ [cloneRepositoryPanel window]; // Need to load the window before we can access the repositoryURL outlet.
+ cloneRepositoryPanel.repositoryURL.stringValue = url;
+ [cloneRepositoryPanel showWindow: self];
+}
+
- (void) windowWillClose: sender
{
[firstResponder terminate: sender];
@@ -129,10 +167,7 @@ - (IBAction)showAboutPanel:(id)sender
- (IBAction) showCloneRepository:(id)sender
{
- if (!cloneRepositoryPanel)
- cloneRepositoryPanel = [PBCloneRepositoryPanel panel];
-
- [cloneRepositoryPanel showWindow:self];
+ [self showClonePanelForURL: nil];
}
- (IBAction)installCliTool:(id)sender;
diff --git a/GitX.xcodeproj/project.pbxproj b/GitX.xcodeproj/project.pbxproj
index 47e66ec3e..f55767b8d 100644
--- a/GitX.xcodeproj/project.pbxproj
+++ b/GitX.xcodeproj/project.pbxproj
@@ -765,6 +765,7 @@
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
isa = PBXGroup;
children = (
+ 4AC42F7B16BFBAD2007CCA3A /* Foundation.framework */,
29B97324FDCFA39411CA2CEA /* AppKit.framework */,
4A40159814067B7A00DB9C07 /* AppKit.framework */,
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */,
diff --git a/Resources/Info.plist b/Resources/Info.plist
index 9801bea3d..205f9bfa5 100644
--- a/Resources/Info.plist
+++ b/Resources/Info.plist
@@ -48,6 +48,19 @@
APPL
CFBundleShortVersionString
0.12
+ CFBundleURLTypes
+
+
+ CFBundleTypeRole
+ Editor
+ CFBundleURLName
+ net.phere.GitX.url-scheme
+ CFBundleURLSchemes
+
+ gitx
+
+
+
CFBundleVersion
0.12
LSApplicationCategoryType