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 "PBCLIProxy.h"
|
||||||
#import "PBRepositoryDocumentController.h"
|
#import "PBRepositoryDocumentController.h"
|
||||||
#import "PBGitRevSpecifier.h"
|
#import "PBGitRevSpecifier.h"
|
||||||
|
#import "PBGitRepository.h"
|
||||||
|
#import "PBGitWindowController.h"
|
||||||
|
|
||||||
@implementation PBCLIProxy
|
@implementation PBCLIProxy
|
||||||
@synthesize connection;
|
@synthesize connection;
|
||||||
@@ -31,14 +33,22 @@
|
|||||||
// FIXME I found that creating this redundant NSURL reference was necessary to
|
// FIXME I found that creating this redundant NSURL reference was necessary to
|
||||||
// work around an apparent bug with GC and Distributed Objects
|
// work around an apparent bug with GC and Distributed Objects
|
||||||
// I am not familiar with GC though, so perhaps I was doing something wrong.
|
// I am not familiar with GC though, so perhaps I was doing something wrong.
|
||||||
|
|
||||||
NSURL* url = [NSURL fileURLWithPath:[repositoryPath path]];
|
NSURL* url = [NSURL fileURLWithPath:[repositoryPath path]];
|
||||||
NSArray* arguments = [NSArray arrayWithArray:args];
|
NSArray* arguments = [NSArray arrayWithArray:args];
|
||||||
PBGitRevSpecifier* rev = [[PBGitRevSpecifier alloc] initWithParameters:arguments];
|
|
||||||
if ([[PBRepositoryDocumentController sharedDocumentController] openRepositoryAtLocation: url RevSpecifier: rev]) {
|
PBGitRepository *document = [[PBRepositoryDocumentController sharedDocumentController] documentForLocation:url];
|
||||||
[NSApp activateIgnoringOtherApps:YES];
|
if (!document)
|
||||||
return YES;
|
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
|
@end
|
||||||
|
|||||||
+4
-1
@@ -14,6 +14,8 @@ extern NSString* PBGitRepositoryErrorDomain;
|
|||||||
|
|
||||||
@interface PBGitRepository : NSDocument {
|
@interface PBGitRepository : NSDocument {
|
||||||
PBGitRevList* revisionList;
|
PBGitRevList* revisionList;
|
||||||
|
NSWindowController *windowController;
|
||||||
|
|
||||||
NSMutableArray* branches;
|
NSMutableArray* branches;
|
||||||
NSIndexSet* currentBranch;
|
NSIndexSet* currentBranch;
|
||||||
NSMutableDictionary* refs;
|
NSMutableDictionary* refs;
|
||||||
@@ -45,9 +47,10 @@ extern NSString* PBGitRepositoryErrorDomain;
|
|||||||
+ (NSURL*)gitDirForURL:(NSURL*)repositoryURL;
|
+ (NSURL*)gitDirForURL:(NSURL*)repositoryURL;
|
||||||
+ (NSURL*)baseDirForURL:(NSURL*)repositoryURL;
|
+ (NSURL*)baseDirForURL:(NSURL*)repositoryURL;
|
||||||
|
|
||||||
- (id) initWithURL: (NSURL*) path andRevSpecifier:(PBGitRevSpecifier*) rev;
|
- (id) initWithURL: (NSURL*) path;
|
||||||
- (void) setup;
|
- (void) setup;
|
||||||
|
|
||||||
|
@property (readonly) NSWindowController *windowController;
|
||||||
@property (retain) PBGitRevList* revisionList;
|
@property (retain) PBGitRevList* revisionList;
|
||||||
@property (assign) NSMutableArray* branches;
|
@property (assign) NSMutableArray* branches;
|
||||||
@property (assign) NSIndexSet* currentBranch;
|
@property (assign) NSIndexSet* currentBranch;
|
||||||
|
|||||||
+23
-8
@@ -19,7 +19,7 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
|
|||||||
|
|
||||||
@implementation PBGitRepository
|
@implementation PBGitRepository
|
||||||
|
|
||||||
@synthesize revisionList, branches, currentBranch, refs;
|
@synthesize revisionList, branches, currentBranch, refs, windowController;
|
||||||
static NSString* gitPath;
|
static NSString* gitPath;
|
||||||
|
|
||||||
+ (void) initialize
|
+ (void) initialize
|
||||||
@@ -131,12 +131,11 @@ static NSString* gitPath;
|
|||||||
|
|
||||||
- (void) setup
|
- (void) setup
|
||||||
{
|
{
|
||||||
self.branches = [NSMutableArray array];
|
|
||||||
[self reloadRefs];
|
[self reloadRefs];
|
||||||
revisionList = [[PBGitRevList alloc] initWithRepository:self];
|
revisionList = [[PBGitRevList alloc] initWithRepository:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithURL: (NSURL*) path andRevSpecifier:(PBGitRevSpecifier*) rev
|
- (id) initWithURL: (NSURL*) path
|
||||||
{
|
{
|
||||||
NSURL* gitDirURL = [PBGitRepository gitDirForURL:path];
|
NSURL* gitDirURL = [PBGitRepository gitDirForURL:path];
|
||||||
if (!gitDirURL)
|
if (!gitDirURL)
|
||||||
@@ -146,10 +145,16 @@ static NSString* gitPath;
|
|||||||
[self setFileURL: gitDirURL];
|
[self setFileURL: gitDirURL];
|
||||||
|
|
||||||
[self setup];
|
[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;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The fileURL the document keeps is to the .git dir, but that’s pretty
|
// 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
|
// useless for display in the window title bar, so we show the directory above
|
||||||
- (NSString*)displayName
|
- (NSString*)displayName
|
||||||
@@ -163,11 +168,11 @@ static NSString* gitPath;
|
|||||||
// Overridden to create our custom window controller
|
// Overridden to create our custom window controller
|
||||||
- (void)makeWindowControllers
|
- (void)makeWindowControllers
|
||||||
{
|
{
|
||||||
PBGitWindowController* controller = [[PBGitWindowController alloc] initWithRepository:self];
|
windowController = [[PBGitWindowController alloc] initWithRepository:self displayDefault:YES];
|
||||||
[self addWindowController:controller];
|
[self addWindowController:windowController];
|
||||||
[controller release];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void) addRef: (PBGitRef *) ref fromParameters: (NSArray *) components
|
- (void) addRef: (PBGitRef *) ref fromParameters: (NSArray *) components
|
||||||
{
|
{
|
||||||
NSString* type = [components objectAtIndex:1];
|
NSString* type = [components objectAtIndex:1];
|
||||||
@@ -192,6 +197,7 @@ static NSString* gitPath;
|
|||||||
- (BOOL) reloadRefs
|
- (BOOL) reloadRefs
|
||||||
{
|
{
|
||||||
BOOL ret = NO;
|
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];
|
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"];
|
NSArray* lines = [output componentsSeparatedByString:@"\n"];
|
||||||
refs = [NSMutableDictionary dictionary];
|
refs = [NSMutableDictionary dictionary];
|
||||||
@@ -240,6 +246,14 @@ static NSString* gitPath;
|
|||||||
return rev;
|
return rev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) showHistoryView
|
||||||
|
{
|
||||||
|
if (!windowController)
|
||||||
|
return;
|
||||||
|
|
||||||
|
((PBGitWindowController *)windowController).selectedViewIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
- (void) selectBranch: (PBGitRevSpecifier*) rev
|
- (void) selectBranch: (PBGitRevSpecifier*) rev
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@@ -247,11 +261,12 @@ static NSString* gitPath;
|
|||||||
PBGitRevSpecifier* aRev = [branches objectAtIndex:i];
|
PBGitRevSpecifier* aRev = [branches objectAtIndex:i];
|
||||||
if (rev == aRev) {
|
if (rev == aRev) {
|
||||||
self.currentBranch = [NSIndexSet indexSetWithIndex:i];
|
self.currentBranch = [NSIndexSet indexSetWithIndex:i];
|
||||||
|
[self showHistoryView];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) readCurrentBranch
|
- (void) readCurrentBranch
|
||||||
{
|
{
|
||||||
[self selectBranch: [self addBranch: [self headRef]]];
|
[self selectBranch: [self addBranch: [self headRef]]];
|
||||||
|
|||||||
@@ -13,18 +13,18 @@
|
|||||||
IBOutlet NSSearchField* searchField;
|
IBOutlet NSSearchField* searchField;
|
||||||
IBOutlet NSArrayController* searchController;
|
IBOutlet NSArrayController* searchController;
|
||||||
IBOutlet NSArrayController *branchesController;
|
IBOutlet NSArrayController *branchesController;
|
||||||
PBGitRepository* repository;
|
__weak PBGitRepository* repository;
|
||||||
int selectedViewIndex;
|
int selectedViewIndex;
|
||||||
IBOutlet NSView* contentView;
|
IBOutlet NSView* contentView;
|
||||||
NSViewController* viewController;
|
NSViewController* viewController;
|
||||||
}
|
}
|
||||||
|
|
||||||
@property (retain) PBGitRepository *repository;
|
@property (assign) __weak PBGitRepository *repository;
|
||||||
@property (readonly) NSViewController *viewController;
|
@property (readonly) NSViewController *viewController;
|
||||||
@property (assign) int selectedViewIndex;
|
@property (assign) int selectedViewIndex;
|
||||||
@property (retain) NSArrayController *searchController;
|
@property (retain) NSArrayController *searchController;
|
||||||
|
|
||||||
- (id)initWithRepository:(PBGitRepository*)theRepository;
|
- (id)initWithRepository:(PBGitRepository*)theRepository displayDefault:(BOOL)display;
|
||||||
|
|
||||||
- (void)changeViewController:(NSInteger)whichViewTag;
|
- (void)changeViewController:(NSInteger)whichViewTag;
|
||||||
- (void) focusOnSearchField;
|
- (void) focusOnSearchField;
|
||||||
|
|||||||
@@ -16,13 +16,20 @@
|
|||||||
|
|
||||||
@synthesize repository, viewController, searchController, selectedViewIndex;
|
@synthesize repository, viewController, searchController, selectedViewIndex;
|
||||||
|
|
||||||
- (id)initWithRepository:(PBGitRepository*)theRepository;
|
- (id)initWithRepository:(PBGitRepository*)theRepository displayDefault:(BOOL)displayDefault
|
||||||
{
|
{
|
||||||
if(self = [self initWithWindowNibName:@"RepositoryWindow"])
|
if(self = [self initWithWindowNibName:@"RepositoryWindow"])
|
||||||
{
|
{
|
||||||
self.repository = theRepository;
|
self.repository = theRepository;
|
||||||
[self showWindow:nil];
|
[self showWindow:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (displayDefault) {
|
||||||
|
self.selectedViewIndex = [[NSUserDefaults standardUserDefaults] integerForKey:@"selectedViewIndex"];
|
||||||
|
} else {
|
||||||
|
self.selectedViewIndex = -1;
|
||||||
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +83,6 @@
|
|||||||
// We bind this ourselves because otherwise we would lose our selection
|
// We bind this ourselves because otherwise we would lose our selection
|
||||||
[branchesController bind:@"selectionIndexes" toObject:repository withKeyPath:@"currentBranch" options:nil];
|
[branchesController bind:@"selectionIndexes" toObject:repository withKeyPath:@"currentBranch" options:nil];
|
||||||
|
|
||||||
self.selectedViewIndex = [[NSUserDefaults standardUserDefaults] integerForKey:@"selectedViewIndex"];
|
|
||||||
[[self window] setAutorecalculatesContentBorderThickness:NO forEdge:NSMinYEdge];
|
[[self window] setAutorecalculatesContentBorderThickness:NO forEdge:NSMinYEdge];
|
||||||
[[self window] setContentBorderThickness:35.0f 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
|
@end
|
||||||
|
|||||||
@@ -31,20 +31,17 @@
|
|||||||
[super noteNewRecentDocumentURL:[PBGitRepository baseDirForURL:url]];
|
[super noteNewRecentDocumentURL:[PBGitRepository baseDirForURL:url]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) openRepositoryAtLocation:(NSURL*) url RevSpecifier:(PBGitRevSpecifier*) rev
|
- (id) documentForLocation:(NSURL*) url
|
||||||
{
|
{
|
||||||
id document = [self documentForURL:url];
|
id document = [self documentForURL:url];
|
||||||
if (!document) {
|
if (!document) {
|
||||||
document = [[PBGitRepository alloc] initWithURL:url andRevSpecifier:rev];
|
|
||||||
if (!document)
|
if (!(document = [[PBGitRepository alloc] initWithURL:url]))
|
||||||
return nil;
|
return NO;
|
||||||
|
|
||||||
[self addDocument:document];
|
[self addDocument:document];
|
||||||
[document makeWindowControllers];
|
|
||||||
} else {
|
|
||||||
[document selectBranch: [document addBranch: rev]];
|
|
||||||
}
|
}
|
||||||
[document showWindows];
|
|
||||||
return document;
|
return document;
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|||||||
Reference in New Issue
Block a user