Skip to content

Commit 8c15c66

Browse files
committed
Open repositories through AppleEvents.
1 parent bcb418a commit 8c15c66

File tree

2 files changed

+18
-29
lines changed

2 files changed

+18
-29
lines changed

Classes/Controllers/ApplicationController.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
#import "ApplicationController.h"
10+
#import "PBRepositoryDocumentController.h"
1011
#import "PBGitRevisionCell.h"
1112
#import "PBGitWindowController.h"
1213
#import "PBServicesController.h"
@@ -70,6 +71,20 @@ - (void)registerServices
7071
}
7172
}
7273

74+
- (BOOL)application:(NSApplication *)sender openFile:(NSString *)filename {
75+
NSURL *repository = [NSURL fileURLWithPath:filename];
76+
NSError *error = nil;
77+
NSDocument *doc = [[PBRepositoryDocumentController sharedDocumentController] openDocumentWithContentsOfURL:repository
78+
display:YES
79+
error:&error];
80+
if (!doc) {
81+
NSLog(@"Error opening repository \"%@\": %@", repository.path, error);
82+
return NO;
83+
}
84+
85+
return YES;
86+
}
87+
7388
- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
7489
{
7590
if(!started || [[[NSDocumentController sharedDocumentController] documents] count])

Classes/gitx.m

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -116,35 +116,9 @@ void handleDiffWithArguments(NSURL *repositoryURL, NSArray *arguments)
116116

117117
void handleOpenRepository(NSURL *repositoryURL, NSMutableArray *arguments)
118118
{
119-
// if there are command line arguments send them to GitX through an Apple Event
120-
// the recordDescriptor will be stored in keyAEPropData inside the openDocument or openApplication event
121-
NSAppleEventDescriptor *recordDescriptor = nil;
122-
if ([arguments count]) {
123-
recordDescriptor = [NSAppleEventDescriptor recordDescriptor];
124-
125-
NSAppleEventDescriptor *listDescriptor = [NSAppleEventDescriptor listDescriptor];
126-
uint listIndex = 1; // AppleEvent list descriptor's are one based
127-
for (NSString *argument in arguments)
128-
[listDescriptor insertDescriptor:[NSAppleEventDescriptor descriptorWithString:argument] atIndex:listIndex++];
129-
130-
[recordDescriptor setParamDescriptor:listDescriptor forKeyword:kGitXAEKeyArgumentsList];
131-
132-
// this is used as a double check in GitX
133-
NSAppleEventDescriptor *url = [NSAppleEventDescriptor descriptorWithString:[repositoryURL absoluteString]];
134-
[recordDescriptor setParamDescriptor:url forKeyword:typeFileURL];
135-
}
136-
137-
// use NSWorkspace to open GitX and send the arguments
138-
// this allows the repository document to modify itself before it shows it's GUI
139-
BOOL didOpenURLs = [[NSWorkspace sharedWorkspace] openURLs:[NSArray arrayWithObject:repositoryURL]
140-
withAppBundleIdentifier:kGitXBundleIdentifier
141-
options:0
142-
additionalEventParamDescriptor:recordDescriptor
143-
launchIdentifiers:NULL];
144-
if (!didOpenURLs) {
145-
printf("Unable to open GitX.app\n");
146-
exit(2);
147-
}
119+
GitXApplication *gitXApp = [SBApplication applicationWithBundleIdentifier:kGitXBundleIdentifier];
120+
[gitXApp open:repositoryURL];
121+
return;
148122
}
149123

150124
void handleInit(NSURL *repositoryURL)

0 commit comments

Comments
 (0)