mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
Add a --commit option to the CLI client
This changes a lot of code, so quick review: * RepositoryDocumentController now returns the document without selecting a ref * PBGitWindowController now optionally shows the default view, or selects no view at all * PBGitRepository keeps a pointer to its WindowController so that it can change views
This commit is contained in:
+16
-6
@@ -9,6 +9,8 @@
|
||||
#import "PBCLIProxy.h"
|
||||
#import "PBRepositoryDocumentController.h"
|
||||
#import "PBGitRevSpecifier.h"
|
||||
#import "PBGitRepository.h"
|
||||
#import "PBGitWindowController.h"
|
||||
|
||||
@implementation PBCLIProxy
|
||||
@synthesize connection;
|
||||
@@ -31,14 +33,22 @@
|
||||
// FIXME I found that creating this redundant NSURL reference was necessary to
|
||||
// work around an apparent bug with GC and Distributed Objects
|
||||
// I am not familiar with GC though, so perhaps I was doing something wrong.
|
||||
|
||||
NSURL* url = [NSURL fileURLWithPath:[repositoryPath path]];
|
||||
NSArray* arguments = [NSArray arrayWithArray:args];
|
||||
PBGitRevSpecifier* rev = [[PBGitRevSpecifier alloc] initWithParameters:arguments];
|
||||
if ([[PBRepositoryDocumentController sharedDocumentController] openRepositoryAtLocation: url RevSpecifier: rev]) {
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
return YES;
|
||||
|
||||
PBGitRepository *document = [[PBRepositoryDocumentController sharedDocumentController] documentForLocation:url];
|
||||
if (!document)
|
||||
return NO;
|
||||
|
||||
if ([arguments count] > 0 && ([[arguments objectAtIndex:0] isEqualToString:@"--commit"] ||
|
||||
[[arguments objectAtIndex:0] isEqualToString:@"-c"]))
|
||||
((PBGitWindowController *)document.windowController).selectedViewIndex = 1;
|
||||
else {
|
||||
PBGitRevSpecifier* rev = [[PBGitRevSpecifier alloc] initWithParameters:arguments];
|
||||
[document selectBranch: [document addBranch: rev]];
|
||||
}
|
||||
return NO;
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
|
||||
return YES;
|
||||
}
|
||||
@end
|
||||
|
||||
+4
-1
@@ -14,6 +14,8 @@ extern NSString* PBGitRepositoryErrorDomain;
|
||||
|
||||
@interface PBGitRepository : NSDocument {
|
||||
PBGitRevList* revisionList;
|
||||
NSWindowController *windowController;
|
||||
|
||||
NSMutableArray* branches;
|
||||
NSIndexSet* currentBranch;
|
||||
NSMutableDictionary* refs;
|
||||
@@ -45,9 +47,10 @@ extern NSString* PBGitRepositoryErrorDomain;
|
||||
+ (NSURL*)gitDirForURL:(NSURL*)repositoryURL;
|
||||
+ (NSURL*)baseDirForURL:(NSURL*)repositoryURL;
|
||||
|
||||
- (id) initWithURL: (NSURL*) path andRevSpecifier:(PBGitRevSpecifier*) rev;
|
||||
- (id) initWithURL: (NSURL*) path;
|
||||
- (void) setup;
|
||||
|
||||
@property (readonly) NSWindowController *windowController;
|
||||
@property (retain) PBGitRevList* revisionList;
|
||||
@property (assign) NSMutableArray* branches;
|
||||
@property (assign) NSIndexSet* currentBranch;
|
||||
|
||||
+23
-8
@@ -19,7 +19,7 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
|
||||
|
||||
@implementation PBGitRepository
|
||||
|
||||
@synthesize revisionList, branches, currentBranch, refs;
|
||||
@synthesize revisionList, branches, currentBranch, refs, windowController;
|
||||
static NSString* gitPath;
|
||||
|
||||
+ (void) initialize
|
||||
@@ -131,12 +131,11 @@ static NSString* gitPath;
|
||||
|
||||
- (void) setup
|
||||
{
|
||||
self.branches = [NSMutableArray array];
|
||||
[self reloadRefs];
|
||||
revisionList = [[PBGitRevList alloc] initWithRepository:self];
|
||||
}
|
||||
|
||||
- (id) initWithURL: (NSURL*) path andRevSpecifier:(PBGitRevSpecifier*) rev
|
||||
- (id) initWithURL: (NSURL*) path
|
||||
{
|
||||
NSURL* gitDirURL = [PBGitRepository gitDirForURL:path];
|
||||
if (!gitDirURL)
|
||||
@@ -146,10 +145,16 @@ static NSString* gitPath;
|
||||
[self setFileURL: gitDirURL];
|
||||
|
||||
[self setup];
|
||||
[self selectBranch: [self addBranch: rev]];
|
||||
|
||||
// We don't want the window controller to display anything yet..
|
||||
// We'll leave that to the caller of this method.
|
||||
windowController = [[PBGitWindowController alloc] initWithRepository:self displayDefault:NO];
|
||||
[self addWindowController:windowController];
|
||||
[self showWindows];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
// The fileURL the document keeps is to the .git dir, but that’s pretty
|
||||
// useless for display in the window title bar, so we show the directory above
|
||||
- (NSString*)displayName
|
||||
@@ -163,11 +168,11 @@ static NSString* gitPath;
|
||||
// Overridden to create our custom window controller
|
||||
- (void)makeWindowControllers
|
||||
{
|
||||
PBGitWindowController* controller = [[PBGitWindowController alloc] initWithRepository:self];
|
||||
[self addWindowController:controller];
|
||||
[controller release];
|
||||
windowController = [[PBGitWindowController alloc] initWithRepository:self displayDefault:YES];
|
||||
[self addWindowController:windowController];
|
||||
}
|
||||
|
||||
|
||||
- (void) addRef: (PBGitRef *) ref fromParameters: (NSArray *) components
|
||||
{
|
||||
NSString* type = [components objectAtIndex:1];
|
||||
@@ -192,6 +197,7 @@ static NSString* gitPath;
|
||||
- (BOOL) reloadRefs
|
||||
{
|
||||
BOOL ret = NO;
|
||||
self.branches = [NSMutableArray array];
|
||||
NSString* output = [PBEasyPipe outputForCommand:gitPath withArgs:[NSArray arrayWithObjects:@"for-each-ref", @"--format=%(refname) %(objecttype) %(objectname) %(*objectname)", @"refs", nil] inDir: self.fileURL.path];
|
||||
NSArray* lines = [output componentsSeparatedByString:@"\n"];
|
||||
refs = [NSMutableDictionary dictionary];
|
||||
@@ -240,6 +246,14 @@ static NSString* gitPath;
|
||||
return rev;
|
||||
}
|
||||
|
||||
- (void) showHistoryView
|
||||
{
|
||||
if (!windowController)
|
||||
return;
|
||||
|
||||
((PBGitWindowController *)windowController).selectedViewIndex = 0;
|
||||
}
|
||||
|
||||
- (void) selectBranch: (PBGitRevSpecifier*) rev
|
||||
{
|
||||
int i;
|
||||
@@ -247,11 +261,12 @@ static NSString* gitPath;
|
||||
PBGitRevSpecifier* aRev = [branches objectAtIndex:i];
|
||||
if (rev == aRev) {
|
||||
self.currentBranch = [NSIndexSet indexSetWithIndex:i];
|
||||
[self showHistoryView];
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void) readCurrentBranch
|
||||
{
|
||||
[self selectBranch: [self addBranch: [self headRef]]];
|
||||
|
||||
@@ -13,18 +13,18 @@
|
||||
IBOutlet NSSearchField* searchField;
|
||||
IBOutlet NSArrayController* searchController;
|
||||
IBOutlet NSArrayController *branchesController;
|
||||
PBGitRepository* repository;
|
||||
__weak PBGitRepository* repository;
|
||||
int selectedViewIndex;
|
||||
IBOutlet NSView* contentView;
|
||||
NSViewController* viewController;
|
||||
}
|
||||
|
||||
@property (retain) PBGitRepository *repository;
|
||||
@property (assign) __weak PBGitRepository *repository;
|
||||
@property (readonly) NSViewController *viewController;
|
||||
@property (assign) int selectedViewIndex;
|
||||
@property (retain) NSArrayController *searchController;
|
||||
|
||||
- (id)initWithRepository:(PBGitRepository*)theRepository;
|
||||
- (id)initWithRepository:(PBGitRepository*)theRepository displayDefault:(BOOL)display;
|
||||
|
||||
- (void)changeViewController:(NSInteger)whichViewTag;
|
||||
- (void) focusOnSearchField;
|
||||
|
||||
@@ -16,13 +16,20 @@
|
||||
|
||||
@synthesize repository, viewController, searchController, selectedViewIndex;
|
||||
|
||||
- (id)initWithRepository:(PBGitRepository*)theRepository;
|
||||
- (id)initWithRepository:(PBGitRepository*)theRepository displayDefault:(BOOL)displayDefault
|
||||
{
|
||||
if(self = [self initWithWindowNibName:@"RepositoryWindow"])
|
||||
{
|
||||
self.repository = theRepository;
|
||||
[self showWindow:nil];
|
||||
}
|
||||
|
||||
if (displayDefault) {
|
||||
self.selectedViewIndex = [[NSUserDefaults standardUserDefaults] integerForKey:@"selectedViewIndex"];
|
||||
} else {
|
||||
self.selectedViewIndex = -1;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -76,7 +83,6 @@
|
||||
// We bind this ourselves because otherwise we would lose our selection
|
||||
[branchesController bind:@"selectionIndexes" toObject:repository withKeyPath:@"currentBranch" options:nil];
|
||||
|
||||
self.selectedViewIndex = [[NSUserDefaults standardUserDefaults] integerForKey:@"selectedViewIndex"];
|
||||
[[self window] setAutorecalculatesContentBorderThickness:NO forEdge:NSMinYEdge];
|
||||
[[self window] setContentBorderThickness:35.0f forEdge:NSMinYEdge];
|
||||
|
||||
|
||||
@@ -15,5 +15,5 @@
|
||||
|
||||
}
|
||||
|
||||
- (id) openRepositoryAtLocation:(NSURL*) url RevSpecifier:(PBGitRevSpecifier*) rev;
|
||||
- (id) documentForLocation:(NSURL*) url;
|
||||
@end
|
||||
|
||||
@@ -31,20 +31,17 @@
|
||||
[super noteNewRecentDocumentURL:[PBGitRepository baseDirForURL:url]];
|
||||
}
|
||||
|
||||
- (id) openRepositoryAtLocation:(NSURL*) url RevSpecifier:(PBGitRevSpecifier*) rev
|
||||
- (id) documentForLocation:(NSURL*) url
|
||||
{
|
||||
id document = [self documentForURL:url];
|
||||
if (!document) {
|
||||
document = [[PBGitRepository alloc] initWithURL:url andRevSpecifier:rev];
|
||||
if (!document)
|
||||
return nil;
|
||||
|
||||
if (!(document = [[PBGitRepository alloc] initWithURL:url]))
|
||||
return NO;
|
||||
|
||||
[self addDocument:document];
|
||||
[document makeWindowControllers];
|
||||
} else {
|
||||
[document selectBranch: [document addBranch: rev]];
|
||||
}
|
||||
[document showWindows];
|
||||
|
||||
return document;
|
||||
}
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user