From 4ed7911c6fa48d0875499dc8ce0a1ef6d32276b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Berg?= Date: Mon, 5 Apr 2010 21:24:00 +0200 Subject: [PATCH] Multiple changes to -selectCommit: from PBGitHistoryController. - Change return type from void to BOOL to convey if selecting succeeded or not. - Return NO if the cliArgs from sharedApplicationController contain "--commit", since then we need to just show the commit stage. Updating the commit list selection is not necessary. In fact, it will confuse order among consequent calls. - If the oldIndex equals NSNotFound, try to get the index of the currently selected object by finding it among the content object of the commitController. If we find it we save the result in an ivar called selectedCommit so that subsequent calls will always have this available as an alternative back-up plan. --- PBGitHistoryController.h | 5 +++-- PBGitHistoryController.m | 22 ++++++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/PBGitHistoryController.h b/PBGitHistoryController.h index aab2831..6d46ad1 100644 --- a/PBGitHistoryController.h +++ b/PBGitHistoryController.h @@ -71,11 +71,12 @@ - (IBAction) setDetailedView:(id)sender; - (IBAction) setTreeView:(id)sender; - (IBAction) setBranchFilter:(id)sender; - -- (void) selectCommit: (NSString*) commit; - (IBAction) refresh:(id)sender; - (IBAction) toggleQLPreviewPanel:(id)sender; - (IBAction) openSelectedFile:(id)sender; + +- (BOOL) selectCommit: (NSString*) commit; + - (void) updateQuicklookForce: (BOOL) force; diff --git a/PBGitHistoryController.m b/PBGitHistoryController.m index f883848..48895f8 100644 --- a/PBGitHistoryController.m +++ b/PBGitHistoryController.m @@ -424,18 +424,32 @@ return selectedCommits; } -- (void) selectCommit:(NSString *)commitSHA +- (BOOL) selectCommit:(NSString *)commitSHA { + ApplicationController * appController = [ApplicationController sharedApplicationController]; + if (appController.launchedFromGitx && [appController.cliArgs isEqualToString:@"--commit"]) { + return NO; + } + NSLog(@"[%@ %s]: SHA = %@", [self class], _cmd, commitSHA); if (!forceSelectionUpdate && [[selectedCommit realSha] isEqualToString:commitSHA]) - return; + return NO; NSInteger oldIndex = [[commitController selectionIndexes] firstIndex]; + if (oldIndex == NSNotFound) { + oldIndex = [[commitController content] indexOfObject:selectedCommit]; + } NSArray *selectedCommits = [self selectedObjectsForSHA:commitSHA]; + selectedCommit = [selectedCommits objectAtIndex:0]; + [commitController setSelectedObjects:selectedCommits]; - if (repository.currentBranchFilter != kGitXSelectedBranchFilter) - [self scrollSelectionToTopOfViewFrom:oldIndex]; + if (repository.currentBranchFilter != kGitXSelectedBranchFilter) { + NSLog(@"[%@ %s] currentBranchFilter = %@", [self class], _cmd, PBStringFromBranchFilterType(repository.currentBranchFilter)); + [self scrollSelectionToTopOfViewFrom:oldIndex]; + } + + return YES; } - (BOOL) hasNonlinearPath