diff --git a/English.lproj/MainMenu.xib b/English.lproj/MainMenu.xib index 1e9e26d..3e4d678 100644 --- a/English.lproj/MainMenu.xib +++ b/English.lproj/MainMenu.xib @@ -8,7 +8,7 @@ 353.00 YES - + YES @@ -213,7 +213,7 @@ YES - New + TmV34oCmA n 1048576 2147483647 @@ -222,7 +222,7 @@ - Open... + T3BlbuKApg o 1048576 2147483647 @@ -1212,6 +1212,14 @@ 933 + + + newDocument: + + + + 934 + @@ -2256,7 +2264,7 @@ - 933 + 934 diff --git a/PBRepositoryDocumentController.m b/PBRepositoryDocumentController.m index 4b7519c..fdfae3a 100644 --- a/PBRepositoryDocumentController.m +++ b/PBRepositoryDocumentController.m @@ -46,4 +46,36 @@ 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]; + NSInteger 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