Skip to content

Commit 96a494c

Browse files
committed
Make the main menu item aware of the commit list
This is part of #132
1 parent 78734e3 commit 96a494c

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

Classes/Controllers/PBGitWindowController.m

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,9 @@ - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
8888

8989
- (BOOL) validateMenuItem:(NSMenuItem *)menuItem remoteTitle:(NSString *)localisationKeyWithRemote plainTitle:(NSString *)localizationKeyWithoutRemote
9090
{
91-
PBSourceViewItem *item = [self selectedItem];
92-
PBGitRef *ref = item.ref;
93-
94-
if (!ref && (item.parent == sidebarController.remotes)) {
95-
ref = [PBGitRef refFromString:[kGitXRemoteRefPrefix stringByAppendingString:item.title]];
96-
}
91+
PBGitRef *ref = [self selectedRef];
92+
if (!ref)
93+
return NO;
9794

9895
PBGitRef *remoteRef = [self.repository remoteRefForBranch:ref error:NULL];
9996
if (ref.isRemote || remoteRef) {
@@ -429,9 +426,25 @@ - (void)performPushForBranch:(PBGitRef *)branchRef toRemote:(PBGitRef *)remoteRe
429426
return _historyViewController.selectedCommits.firstObject;
430427
}
431428

432-
- (PBSourceViewItem *) selectedItem {
433-
NSOutlineView *sourceView = sidebarController.sourceView;
434-
return [sourceView itemAtRow:sourceView.selectedRow];
429+
- (PBGitRef *)selectedRef {
430+
id firstResponder = self.window.firstResponder;
431+
if (firstResponder == sidebarController.sourceView) {
432+
NSOutlineView *sourceView = sidebarController.sourceView;
433+
PBSourceViewItem *item = [sourceView itemAtRow:sourceView.selectedRow];
434+
PBGitRef *ref = item.ref;
435+
if (ref && (item.parent == sidebarController.remotes)) {
436+
ref = [PBGitRef refFromString:[kGitXRemoteRefPrefix stringByAppendingString:item.title]];
437+
}
438+
return ref;
439+
} else if (firstResponder == _historyViewController.commitList && _historyViewController.singleCommitSelected) {
440+
NSMutableArray *branchCommits = [NSMutableArray array];
441+
for (PBGitRef *ref in _historyViewController.selectedCommits.firstObject.refs) {
442+
if (!ref.isBranch) continue;
443+
[branchCommits addObject:ref];
444+
}
445+
return (branchCommits.count == 1 ? branchCommits.firstObject : nil);
446+
}
447+
return nil;
435448
}
436449

437450
- (IBAction) showAddRemoteSheet:(id)sender

0 commit comments

Comments
 (0)