From a2862a2d0dc26ad4b605247f20a8f35311239ecb Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Mon, 8 Jul 2013 20:47:28 +0200 Subject: [PATCH 1/2] Register URL type --- Resources/Info.plist | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 From 49712fad6e8ba61bee20c22100403db4df7396bb Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Mon, 8 Jul 2013 21:32:17 +0200 Subject: [PATCH 2/2] Open the clone panel for URLs in the form gitx://clonerepo/actual-url --- Classes/Controllers/ApplicationController.m | 43 +++++++++++++++++++-- 1 file changed, 39 insertions(+), 4 deletions(-) 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;