Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gitx:// URL scheme #218

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions Classes/Controllers/ApplicationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions GitX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
isa = PBXGroup;
children = (
4AC42F7B16BFBAD2007CCA3A /* Foundation.framework */,
29B97324FDCFA39411CA2CEA /* AppKit.framework */,
4A40159814067B7A00DB9C07 /* AppKit.framework */,
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */,
Expand Down
13 changes: 13 additions & 0 deletions Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.12</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>net.phere.GitX.url-scheme</string>
<key>CFBundleURLSchemes</key>
<array>
<string>gitx</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>0.12</string>
<key>LSApplicationCategoryType</key>
Expand Down