HistoryView: don't load in commit information in a separate thread anymore
[GitX.git] / PBRepositoryDocumentController.m
blob83bd887e9eb33bb47df09a5b65489014aacbf9b5
1 //
2 //  PBRepositoryDocumentController.mm
3 //  GitX
4 //
5 //  Created by CiarĂ¡n Walsh on 15/08/2008.
6 //  Copyright 2008 __MyCompanyName__. All rights reserved.
7 //
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];
37         if (!document) {
38                 
39                 if (!(document = [[PBGitRepository alloc] initWithURL:url]))
40                         return nil;
42                 [self addDocument:document];
43         }
44         else
45                 [document showWindows];
47         return document;
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)
61         {
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];
68                 else
69                         NSRunAlertPanel(@"Failed to create new Git repository", @"Git returned the following error when trying to create the repository: %@", nil, nil, nil, result);
70         }
74 - (BOOL)validateMenuItem:(NSMenuItem *)item
76         if ([item action] == @selector(newDocument:))
77                 return ([PBGitBinary path] != nil);
78         return [super validateMenuItem:item];
81 @end