Skip to content

Commit 9898579

Browse files
committed
Merge pull request brotherbard#109 from fourplusone/master
Added ability to clone via gitx://clone/?repo=…
2 parents 5c7e052 + 98dfdb7 commit 9898579

File tree

6 files changed

+143
-2
lines changed

6 files changed

+143
-2
lines changed

AIURLAdditions.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Adium is the legal property of its developers, whose names are listed in the copyright file included
3+
* with this source distribution.
4+
*
5+
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6+
* General Public License as published by the Free Software Foundation; either version 2 of the License,
7+
* or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10+
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11+
* Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License along with this program; if not,
14+
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15+
*/
16+
17+
18+
/*!
19+
* Provides some additional functionality when working with \c NSURL objects.
20+
*/
21+
@interface NSURL (AIURLAdditions)
22+
23+
/**
24+
* @brief The length of the URL.
25+
*
26+
* @return The length (number of characters) of the absolute URL.
27+
*/
28+
@property (readonly, nonatomic) NSUInteger length;
29+
30+
/*!
31+
* @brief Returns the argument for the specified key in the query string component of
32+
* the URL.
33+
*
34+
* The search is case-sensitive, and the caller is responsible for removing any
35+
* percent escapes, as well as "+" escapes, too.
36+
*
37+
* @param key The key whose value should be located and returned.
38+
* @return The argument for the specified key, or \c nil if the key could not
39+
* be found in the query string.
40+
*/
41+
- (NSString *)queryArgumentForKey:(NSString *)key;
42+
- (NSString *)queryArgumentForKey:(NSString *)key withDelimiter:(NSString *)delimiter;
43+
44+
@end

AIURLAdditions.m

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Adium is the legal property of its developers, whose names are listed in the copyright file included
3+
* with this source distribution.
4+
*
5+
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6+
* General Public License as published by the Free Software Foundation; either version 2 of the License,
7+
* or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10+
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11+
* Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License along with this program; if not,
14+
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15+
*/
16+
17+
#import "AIURLAdditions.h"
18+
19+
@implementation NSURL (AIURLAdditions)
20+
21+
- (NSUInteger)length
22+
{
23+
return [[self absoluteString] length];
24+
}
25+
26+
- (NSString *)queryArgumentForKey:(NSString *)key withDelimiter:(NSString *)delimiter
27+
{
28+
for (NSString *obj in [[self query] componentsSeparatedByString:delimiter]) {
29+
NSArray *keyAndValue = [obj componentsSeparatedByString:@"="];
30+
31+
if (([keyAndValue count] >= 2) && ([[keyAndValue objectAtIndex:0] caseInsensitiveCompare:key] == NSOrderedSame)) {
32+
return [keyAndValue objectAtIndex:1];
33+
}
34+
}
35+
36+
return nil;
37+
}
38+
39+
- (NSString *)queryArgumentForKey:(NSString *)key
40+
{
41+
NSString *delimiter;
42+
43+
// The arguments in query strings can be delimited with a semicolon (';') or an ampersand ('&'). Since it's not
44+
// likely a single URL would use both types of delimeters, we'll attempt to pick one and use it.
45+
if ([[self query] rangeOfString:@";"].location != NSNotFound) {
46+
delimiter = @";";
47+
} else {
48+
// Assume '&' by default, since that's more common
49+
delimiter = @"&";
50+
}
51+
52+
return [self queryArgumentForKey:key withDelimiter:delimiter];
53+
}
54+
55+
@end

ApplicationController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
NSManagedObjectContext *managedObjectContext;
2121

2222
PBCloneRepositoryPanel *cloneRepositoryPanel;
23+
2324
}
2425

2526
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator;

ApplicationController.m

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#import "PBGitDefaults.h"
1818
#import "PBCloneRepositoryPanel.h"
1919
#import "Sparkle/SUUpdater.h"
20+
#import "AIURLAdditions.h"
2021

2122
@implementation ApplicationController
2223

@@ -61,6 +62,14 @@ - (void)registerServices
6162
}
6263
}
6364

65+
- (void)applicationWillFinishLaunching:(NSNotification*)notification
66+
{
67+
[[NSAppleEventManager sharedAppleEventManager] setEventHandler:self
68+
andSelector:@selector(getUrl:withReplyEvent:)
69+
forEventClass:kInternetEventClass
70+
andEventID:kAEGetURL];
71+
}
72+
6473
- (void)applicationDidFinishLaunching:(NSNotification*)notification
6574
{
6675
[[SUUpdater sharedUpdater] setSendsSystemProfile:YES];
@@ -76,7 +85,7 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification
7685

7786
BOOL hasOpenedDocuments = NO;
7887
NSArray *launchedDocuments = [[[PBRepositoryDocumentController sharedDocumentController] documents] copy];
79-
88+
8089
// Only try to open a default document if there are no documents open already.
8190
// For example, the application might have been launched by double-clicking a .git repository,
8291
// or by dragging a folder to the app icon
@@ -114,10 +123,25 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification
114123

115124
// The current directory was not enabled or could not be opened (most likely it’s not a git repository).
116125
// show an open panel for the user to select a repository to view
117-
if ([PBGitDefaults showOpenPanelOnLaunch] && !hasOpenedDocuments)
126+
if ([PBGitDefaults showOpenPanelOnLaunch] && !hasOpenedDocuments && cloneRepositoryPanel == nil)
118127
[[PBRepositoryDocumentController sharedDocumentController] openDocument:self];
119128
}
120129

130+
- (void)getUrl:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
131+
{
132+
NSString *urlString = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
133+
NSURL *url = [NSURL URLWithString:urlString];
134+
135+
if ([url.host isEqual:@"clone"]) {
136+
NSString * repo = [[url queryArgumentForKey:@"repo"] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
137+
138+
[self showCloneRepository:self];
139+
140+
[cloneRepositoryPanel.repositoryURL setStringValue:repo];
141+
}
142+
143+
}
144+
121145
- (void) windowWillClose: sender
122146
{
123147
[firstResponder terminate: sender];

GitX.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
217FF0BB12A1CB3300785A65 /* PBGitResetController.m in Sources */ = {isa = PBXBuildFile; fileRef = 217FF0B712A1CB3300785A65 /* PBGitResetController.m */; };
5555
217FF0BE12A1CB3E00785A65 /* PBRevealWithFinderCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = 217FF0BC12A1CB3E00785A65 /* PBRevealWithFinderCommand.m */; };
5656
21CF0B24129C7ED90065B37C /* TrackableOutlineView.m in Sources */ = {isa = PBXBuildFile; fileRef = 21CF0B23129C7ED90065B37C /* TrackableOutlineView.m */; };
57+
2CC9B39713E86B35002EA416 /* AIURLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 2CC9B39613E86B35002EA416 /* AIURLAdditions.m */; };
5758
310DC1D81240599E0017A0F7 /* GLFileView.m in Sources */ = {isa = PBXBuildFile; fileRef = 310DC1D71240599E0017A0F7 /* GLFileView.m */; };
5859
311D4F561370C9A50061CFD3 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 311D4F551370C9A50061CFD3 /* Security.framework */; };
5960
311D4F5B1370CD150061CFD3 /* ScriptingBridge.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 311D4F5A1370CD150061CFD3 /* ScriptingBridge.framework */; };
@@ -297,6 +298,8 @@
297298
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
298299
29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
299300
29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
301+
2CC9B39513E86B2F002EA416 /* AIURLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIURLAdditions.h; sourceTree = "<group>"; };
302+
2CC9B39613E86B35002EA416 /* AIURLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIURLAdditions.m; sourceTree = "<group>"; };
300303
310DC1D61240599E0017A0F7 /* GLFileView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GLFileView.h; sourceTree = "<group>"; };
301304
310DC1D71240599E0017A0F7 /* GLFileView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GLFileView.m; sourceTree = "<group>"; };
302305
311D4F551370C9A50061CFD3 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = /System/Library/Frameworks/Security.framework; sourceTree = "<absolute>"; };
@@ -986,6 +989,8 @@
986989
F57CC43E0E05E472000472E2 /* Aux */ = {
987990
isa = PBXGroup;
988991
children = (
992+
2CC9B39613E86B35002EA416 /* AIURLAdditions.m */,
993+
2CC9B39513E86B2F002EA416 /* AIURLAdditions.h */,
989994
31460C79124185B900B90AED /* MGScopeBar */,
990995
47DBDBC80E95016F00671A1E /* PBNSURLPathUserDefaultsTransfomer.h */,
991996
47DBDBC90E95016F00671A1E /* PBNSURLPathUserDefaultsTransfomer.m */,
@@ -1479,6 +1484,7 @@
14791484
DDB8FE0113998CE2001A9EE2 /* PBStashContentController.m in Sources */,
14801485
89087CA613A3E46B00911503 /* PBWebCommitController.m in Sources */,
14811486
8998B1C613A55B3500121729 /* PBWebStashController.m in Sources */,
1487+
2CC9B39713E86B35002EA416 /* AIURLAdditions.m in Sources */,
14821488
);
14831489
runOnlyForDeploymentPostprocessing = 0;
14841490
};

Info.plist

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@
5050
<string>APPL</string>
5151
<key>CFBundleSignature</key>
5252
<string>????</string>
53+
<key>CFBundleURLTypes</key>
54+
<array>
55+
<dict>
56+
<key>CFBundleTypeRole</key>
57+
<string>Editor</string>
58+
<key>CFBundleURLSchemes</key>
59+
<array>
60+
<string>gitx</string>
61+
</array>
62+
</dict>
63+
</array>
5364
<key>CFBundleVersion</key>
5465
<string>SHORT_VERSION</string>
5566
<key>CFBundleGitVersion</key>

0 commit comments

Comments
 (0)