-
Notifications
You must be signed in to change notification settings - Fork 602
/
Copy pathPBRepositoryDocumentController.m
81 lines (66 loc) · 2.21 KB
/
PBRepositoryDocumentController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//
// PBRepositoryDocumentController.mm
// GitX
//
// Created by Ciarán Walsh on 15/08/2008.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "PBRepositoryDocumentController.h"
#import "PBGitRepository.h"
#import "PBGitRevList.h"
@implementation PBRepositoryDocumentController
// This method is overridden to configure the open panel to only allow
// selection of directories
- (NSInteger)runModalOpenPanel:(NSOpenPanel *)openPanel forTypes:(NSArray *)extensions
{
[openPanel setCanChooseFiles:YES];
[openPanel setCanChooseDirectories:YES];
return [openPanel runModalForDirectory:nil file:nil types:[NSArray arrayWithObject: @"git"]];
}
// Convert paths to the .git dir before searching for an already open document
- (id)documentForURL:(NSURL *)URL
{
return [super documentForURL:[PBGitRepository gitDirForURL:URL]];
}
- (void)noteNewRecentDocumentURL:(NSURL*)url
{
[super noteNewRecentDocumentURL:[PBGitRepository baseDirForURL:url]];
}
- (id) documentForLocation:(NSURL*) url
{
id document = [self documentForURL:url];
if (!document) {
if (!(document = [[PBGitRepository alloc] initWithURL:url]))
return nil;
[self addDocument:document];
}
else
[document showWindows];
return document;
}
- (IBAction)newDocument:(id)sender
{
NSOpenPanel *op = [NSOpenPanel openPanel];
[op setCanChooseFiles:NO];
[op setCanChooseDirectories:YES];
[op setAllowsMultipleSelection:NO];
[op setMessage:@"Initialize a repository here:"];
[op setTitle:@"New Repository"];
if ([op runModal] == NSFileHandlingPanelOKButton)
{
NSString *path = [op filename];
int terminationStatus;
NSString *result = [PBEasyPipe outputForCommand:[PBGitBinary path] withArgs:[NSArray arrayWithObjects:@"init", @"-q", nil] inDir:path inputString:nil retValue:&terminationStatus];
if (terminationStatus == 0)
[self openDocumentWithContentsOfURL:[op URL] display:YES error:NULL];
else
NSRunAlertPanel(@"Failed to create new Git repository", @"Git returned the following error when trying to create the repository: %@", nil, nil, nil, result);
}
}
- (BOOL)validateMenuItem:(NSMenuItem *)item
{
if ([item action] == @selector(newDocument:))
return ([PBGitBinary path] != nil);
return [super validateMenuItem:item];
}
@end