Skip to content

Commit c16d5ad

Browse files
committed
Move IBActions out of PBRefController into PBGitHistoryController
1 parent 57365cf commit c16d5ad

File tree

4 files changed

+112
-137
lines changed

4 files changed

+112
-137
lines changed

Classes/Controllers/PBGitHistoryController.m

Lines changed: 108 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// Copyright 2008 __MyCompanyName__. All rights reserved.
77
//
88

9+
#import <Quartz/Quartz.h>
10+
911
#import "PBGitCommit.h"
1012
#import "PBGitTree.h"
1113
#import "PBGitRef.h"
@@ -30,8 +32,7 @@
3032
#import "GLFileView.h"
3133
#import "GitXCommitCopier.h"
3234
#import "NSSplitView+GitX.h"
33-
#import <Quartz/Quartz.h>
34-
35+
#import "PBRefMenuItem.h"
3536

3637
#define kHistorySelectedDetailIndexKey @"PBHistorySelectedDetailIndex"
3738
#define kHistoryDetailViewIndex 0
@@ -638,37 +639,130 @@ - (NSArray *)menuItemsForPaths:(NSArray *)paths
638639

639640
#pragma mark Repository Methods
640641

641-
- (IBAction) merge:(id)sender
642+
- (id <PBGitRefish>)refishForSender:(id)sender
643+
{
644+
return [self refishForSender:sender refishTypes:nil];
645+
}
646+
647+
- (id <PBGitRefish>)refishForSender:(id)sender refishTypes:(NSArray *)types
648+
{
649+
if ([sender isKindOfClass:[PBRefMenuItem class]]) {
650+
id <PBGitRefish> refish = [[(PBRefMenuItem *)sender refishs] firstObject];
651+
return refish;
652+
}
653+
654+
if ([types indexOfObject:kGitXCommitType] == NSNotFound)
655+
return nil;
656+
657+
return self.selectedCommits.firstObject;
658+
}
659+
660+
- (IBAction)fetchRemote:(id)sender
661+
{
662+
id <PBGitRefish> refish = [self refishForSender:sender refishTypes:@[kGitXBranchType]];
663+
if (!refish)
664+
return;
665+
666+
[self.windowController performFetchForRef:refish];
667+
}
668+
669+
- (IBAction)pullRemote:(id)sender
670+
{
671+
id <PBGitRefish> refish = [self refishForSender:sender refishTypes:@[kGitXBranchType]];
672+
if (!refish)
673+
return;
674+
675+
[self.windowController performPullForBranch:refish remote:nil rebase:NO];
676+
}
677+
678+
- (IBAction)pushUpdatesToRemote:(id)sender
679+
{
680+
id <PBGitRefish> refish = [self refishForSender:sender refishTypes:@[kGitXBranchType]];
681+
if (!refish)
682+
return;
683+
684+
PBGitRef *remoteRef = nil; // [(PBGitRef *)sender.refishs.firstObject remoteRef];
685+
686+
[self.windowController performPushForBranch:nil toRemote:remoteRef];
687+
}
688+
689+
- (IBAction)pushDefaultRemoteForRef:(id)sender
690+
{
691+
id <PBGitRefish> refish = [self refishForSender:sender refishTypes:@[kGitXBranchType]];
692+
if (!refish)
693+
return;
694+
695+
PBGitRef *ref = nil;
696+
697+
[self.windowController performPushForBranch:ref toRemote:nil];
698+
}
699+
700+
- (IBAction)pushToRemote:(id)sender
701+
{
702+
id <PBGitRefish> refish = [self refishForSender:sender refishTypes:@[kGitXBranchType]];
703+
if (!refish)
704+
return;
705+
706+
PBGitRef *ref = nil;
707+
NSString *remoteName = [sender representedObject];
708+
PBGitRef *remoteRef = [PBGitRef refFromString:[kGitXRemoteRefPrefix stringByAppendingString:remoteName]];
709+
710+
[self.windowController performPushForBranch:ref toRemote:remoteRef];
711+
}
712+
713+
- (IBAction)merge:(id)sender
714+
{
715+
id <PBGitRefish> refish = [self refishForSender:sender refishTypes:@[kGitXBranchType, kGitXCommitType, kGitXTagType]];
716+
if (!refish) return;
717+
718+
NSError *error = nil;
719+
BOOL success = [repository mergeWithRefish:refish error:&error];
720+
if (!success) {
721+
[self.windowController showErrorSheet:error];
722+
}
723+
}
724+
725+
- (IBAction)checkout:(id)sender
642726
{
643-
PBGitCommit *selectedCommit = self.selectedCommits.firstObject;
644-
if (!selectedCommit) return;
727+
id <PBGitRefish> refish = [self refishForSender:sender refishTypes:@[kGitXBranchType, kGitXCommitType, kGitXTagType]];
728+
if (!selectedCommits) return;
645729

646730
NSError *error = nil;
647-
BOOL success = [repository mergeWithRefish:selectedCommit error:&error];
731+
BOOL success = [repository checkoutRefish:refish error:&error];
648732
if (!success) {
649733
[self.windowController showErrorSheet:error];
650734
}
651735
}
652736

653-
- (IBAction) cherryPick:(id)sender
737+
- (IBAction)cherryPick:(id)sender
654738
{
655-
PBGitCommit *selectedCommit = self.selectedCommits.firstObject;
656-
if (!selectedCommit) return;
739+
id <PBGitRefish> refish = [self refishForSender:sender refishTypes:@[kGitXCommitType]];
740+
if (!refish) return;
657741

658742
NSError *error = nil;
659-
BOOL success = [repository cherryPickRefish:selectedCommit error:&error];
743+
BOOL success = [repository cherryPickRefish:refish error:&error];
660744
if (!success) {
661745
[self.windowController showErrorSheet:error];
662746
}
663747
}
664748

665-
- (IBAction) rebase:(id)sender
749+
- (IBAction)rebase:(id)sender
666750
{
667-
PBGitCommit *selectedCommit = self.selectedCommits.firstObject;
668-
if (!selectedCommit) return;
751+
id <PBGitRefish> refish = [self refishForSender:sender refishTypes:@[kGitXBranchType]];
752+
if (!refish) return;
669753

670754
NSError *error = nil;
671-
BOOL success = [repository rebaseBranch:nil onRefish:selectedCommit error:&error];
755+
BOOL success = [repository rebaseBranch:nil onRefish:refish error:&error];
756+
if (!success) {
757+
[self.windowController showErrorSheet:error];
758+
}
759+
}
760+
761+
- (IBAction) rebaseHeadBranch:(id)sender
762+
{
763+
id <PBGitRefish> refish = [self refishForSender:sender refishTypes:@[kGitXBranchType]];
764+
NSError *error = nil;
765+
BOOL success = [self.repository rebaseBranch:nil onRefish:refish error:&error];
672766
if (!success) {
673767
[self.windowController showErrorSheet:error];
674768
}

Classes/Controllers/PBGitSidebarController.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#import "PBHistorySearchController.h"
1919
#import "PBGitStash.h"
2020
#import "PBGitSVStashItem.h"
21+
#import "PBGitRef.h"
2122

2223
@interface PBGitSidebarController ()
2324

Classes/Controllers/PBRefController.h

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,14 @@
77
//
88

99
#import <Cocoa/Cocoa.h>
10-
#import "PBGitHistoryController.h"
11-
#import "PBCommitList.h"
12-
#import "PBGitRef.h"
13-
#import "PBGitCommit.h"
1410
#import "PBRefContextDelegate.h"
1511

16-
@class PBRefMenuItem;
12+
@class PBGitHistoryController, PBCommitList;
1713

1814
@interface PBRefController : NSObject <PBRefContextDelegate> {
1915
__weak IBOutlet PBGitHistoryController *historyController;
2016
__weak IBOutlet NSArrayController *commitController;
2117
__weak IBOutlet PBCommitList *commitList;
2218
}
2319

24-
- (IBAction) fetchRemote:(PBRefMenuItem *)sender;
25-
- (IBAction) pullRemote:(PBRefMenuItem *)sender;
26-
- (IBAction) pushUpdatesToRemote:(PBRefMenuItem *)sender;
27-
- (IBAction) pushDefaultRemoteForRef:(PBRefMenuItem *)sender;
28-
- (IBAction) pushToRemote:(PBRefMenuItem *)sender;
29-
- (IBAction)showDeleteRefSheet:(PBRefMenuItem *)sender;
30-
31-
- (IBAction) checkout:(PBRefMenuItem *)sender;
32-
- (IBAction) merge:(PBRefMenuItem *)sender;
33-
- (IBAction) cherryPick:(PBRefMenuItem *)sender;
34-
- (IBAction) rebaseHeadBranch:(PBRefMenuItem *)sender;
35-
- (IBAction) copySHA:(PBRefMenuItem *)sender;
36-
- (IBAction) copyShortSHA:(PBRefMenuItem *)sender;
37-
- (IBAction) copyPatch:(PBRefMenuItem *)sender;
38-
- (IBAction) diffWithHEAD:(PBRefMenuItem *)sender;
39-
- (IBAction) showTagInfoSheet:(PBRefMenuItem *)sender;
40-
4120
@end

Classes/Controllers/PBRefController.m

Lines changed: 2 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99
#import "PBRefController.h"
1010
#import "PBGitRevisionCell.h"
1111
#import "PBRefMenuItem.h"
12-
#import "PBCreateBranchSheet.h"
13-
#import "PBCreateTagSheet.h"
1412
#import "PBGitDefaults.h"
1513
#import "PBDiffWindowController.h"
1614
#import "PBGitRevSpecifier.h"
1715
#import "PBGitStash.h"
1816
#import "GitXCommitCopier.h"
19-
17+
#import "PBCommitList.h"
18+
#import "PBGitHistoryController.h"
2019

2120

2221

@@ -27,104 +26,6 @@ - (void)awakeFromNib
2726
[commitList registerForDraggedTypes:[NSArray arrayWithObject:@"PBGitRef"]];
2827
}
2928

30-
#pragma mark Fetch
31-
32-
- (void) fetchRemote:(PBRefMenuItem *)sender
33-
{
34-
id <PBGitRefish> refish = sender.refishs.firstObject;
35-
if ([refish refishType] == kGitXCommitType)
36-
return;
37-
38-
[historyController.windowController performFetchForRef:refish];
39-
}
40-
41-
42-
#pragma mark Pull
43-
44-
- (void) pullRemote:(PBRefMenuItem *)sender
45-
{
46-
id <PBGitRefish> refish = sender.refishs.firstObject;
47-
48-
[historyController.windowController performPullForBranch:refish remote:nil rebase:NO];
49-
}
50-
51-
52-
#pragma mark Push
53-
54-
- (void) pushUpdatesToRemote:(PBRefMenuItem *)sender
55-
{
56-
PBGitRef *remoteRef = [(PBGitRef *)sender.refishs.firstObject remoteRef];
57-
[historyController.windowController performPushForBranch:nil toRemote:remoteRef];
58-
}
59-
60-
- (void) pushDefaultRemoteForRef:(PBRefMenuItem *)sender
61-
{
62-
PBGitRef *ref = sender.refishs.firstObject;
63-
64-
[historyController.windowController performPushForBranch:ref toRemote:nil];
65-
}
66-
67-
- (void) pushToRemote:(PBRefMenuItem *)sender
68-
{
69-
PBGitRef *ref = sender.refishs.firstObject;;
70-
NSString *remoteName = [sender representedObject];
71-
PBGitRef *remoteRef = [PBGitRef refFromString:[kGitXRemoteRefPrefix stringByAppendingString:remoteName]];
72-
73-
[historyController.windowController performPushForBranch:ref toRemote:remoteRef];
74-
}
75-
76-
77-
#pragma mark Merge
78-
79-
- (void) merge:(PBRefMenuItem *)sender
80-
{
81-
id <PBGitRefish> refish = sender.refishs.firstObject;
82-
NSError *error = nil;
83-
BOOL success = [historyController.repository mergeWithRefish:refish error:&error];
84-
if (!success) {
85-
[historyController.windowController showErrorSheet:error];
86-
}
87-
}
88-
89-
90-
#pragma mark Checkout
91-
92-
- (void) checkout:(PBRefMenuItem *)sender
93-
{
94-
id <PBGitRefish> refish = sender.refishs.firstObject;
95-
NSError *error = nil;
96-
BOOL success = [historyController.repository checkoutRefish:refish error:&error];
97-
if (!success) {
98-
[historyController.windowController showErrorSheet:error];
99-
}
100-
}
101-
102-
103-
#pragma mark Cherry Pick
104-
105-
- (void) cherryPick:(PBRefMenuItem *)sender
106-
{
107-
id <PBGitRefish> refish = sender.refishs.firstObject;
108-
NSError *error = nil;
109-
BOOL success = [historyController.repository cherryPickRefish:refish error:&error];
110-
if (!success) {
111-
[historyController.windowController showErrorSheet:error];
112-
}
113-
}
114-
115-
116-
#pragma mark Rebase
117-
118-
- (void) rebaseHeadBranch:(PBRefMenuItem *)sender
119-
{
120-
id <PBGitRefish> refish = sender.refishs.firstObject;
121-
NSError *error = nil;
122-
BOOL success = [historyController.repository rebaseBranch:nil onRefish:refish error:&error];
123-
if (!success) {
124-
[historyController.windowController showErrorSheet:error];
125-
}
126-
}
127-
12829
#pragma mark Copy info
12930

13031
- (void) copySHA:(PBRefMenuItem *)sender

0 commit comments

Comments
 (0)