2 // PBRepositoryDocumentController.mm
5 // Created by CiarĂ¡n Walsh on 15/08/2008.
6 // Copyright 2008 __MyCompanyName__. All rights reserved.
9 #import "PBRepositoryDocumentController.h"
10 #import "PBGitRepository.h"
11 #import "PBGitRevList.h"
13 @implementation PBRepositoryDocumentController
14 // This method is overridden to configure the open panel to only allow
15 // selection of directories
16 - (NSInteger)runModalOpenPanel:(NSOpenPanel *)openPanel forTypes:(NSArray *)extensions
18 [openPanel setCanChooseFiles:YES];
19 [openPanel setCanChooseDirectories:YES];
20 return [openPanel runModalForDirectory:nil file:nil types:[NSArray arrayWithObject: @"git"]];
23 // Convert paths to the .git dir before searching for an already open document
24 - (id)documentForURL:(NSURL *)URL
26 return [super documentForURL:[PBGitRepository gitDirForURL:URL]];
29 - (void)noteNewRecentDocumentURL:(NSURL*)url
31 [super noteNewRecentDocumentURL:[PBGitRepository baseDirForURL:url]];
34 - (id) documentForLocation:(NSURL*) url
36 id document = [self documentForURL:url];
39 if (!(document = [[PBGitRepository alloc] initWithURL:url]))
42 [self addDocument:document];
45 [document showWindows];
51 - (IBAction)newDocument:(id)sender
53 NSOpenPanel *op = [NSOpenPanel openPanel];
55 [op setCanChooseFiles:NO];
56 [op setCanChooseDirectories:YES];
57 [op setAllowsMultipleSelection:NO];
58 [op setMessage:@"Initialize a repository here:"];
59 [op setTitle:@"New Repository"];
60 if ([op runModal] == NSFileHandlingPanelOKButton)
62 NSString *path = [op filename];
63 int terminationStatus;
64 NSString *result = [PBEasyPipe outputForCommand:[PBGitBinary path] withArgs:[NSArray arrayWithObjects:@"init", @"-q", nil] inDir:path inputString:nil retValue:&terminationStatus];
66 if (terminationStatus == 0)
67 [self openDocumentWithContentsOfURL:[op URL] display:YES error:NULL];
69 NSRunAlertPanel(@"Failed to create new Git repository", @"Git returned the following error when trying to create the repository: %@", nil, nil, nil, result);
74 - (BOOL)validateMenuItem:(NSMenuItem *)item
76 if ([item action] == @selector(newDocument:))
77 return ([PBGitBinary path] != nil);
78 return [super validateMenuItem:item];