Skip to content

Commit d613145

Browse files
committed
Add »Pull« Menu-Items to Repository Menu
1 parent 6f49819 commit d613145

File tree

5 files changed

+58
-11
lines changed

5 files changed

+58
-11
lines changed

Classes/Controllers/PBGitSidebarController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
- (void)setHistorySearch:(NSString *)searchString mode:(NSInteger)mode;
4343

4444
@property(readonly) NSMutableArray *items;
45+
@property(readonly) PBSourceViewItem *remotes;
4546
@property(readonly) NSOutlineView *sourceView;
4647
@property(readonly) NSView *sourceListControlsView;
4748
@property(readonly) PBGitHistoryController *historyViewController;

Classes/Controllers/PBGitSidebarController.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ - (void) updateRemoteControls;
3131

3232
@implementation PBGitSidebarController
3333
@synthesize items;
34+
@synthesize remotes;
3435
@synthesize sourceView;
3536
@synthesize sourceListControlsView;
3637
@synthesize historyViewController;

Classes/Controllers/PBGitWindowController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
- (IBAction) fetchRemote:(id)sender;
5252
- (IBAction) fetchAllRemotes:(id)sender;
5353

54+
- (IBAction) pullRemote:(id)sender;
55+
- (IBAction) pullDefaultRemote:(id)sender;
56+
5457
- (IBAction) stashSave:(id) sender;
5558
- (IBAction) stashSaveWithKeepIndex:(id) sender;
5659
- (IBAction) stashPop:(id) sender;

Classes/Controllers/PBGitWindowController.m

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,33 @@ - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
6868
[menuItem setState:(contentController != sidebarController.commitViewController) ? YES : NO];
6969
return ![repository isBareRepository];
7070
} else if (menuItem.action == @selector(fetchRemote:)) {
71-
NSOutlineView *sourceView = sidebarController.sourceView;
72-
PBSourceViewItem *item = [sourceView itemAtRow:sourceView.selectedRow];
73-
if (item.ref.isRemote) {
74-
menuItem.title = [NSString stringWithFormat:NSLocalizedString(@"Fetch “%@", @"Fetch ”Remote Name“"), item.ref.remoteName];
75-
return YES;
76-
}
77-
menuItem.title = NSLocalizedString(@"Fetch", @"Fetch (without Remote Name for inactive menu item)");
78-
return NO;
71+
return [self validateMenuItem:menuItem remoteTitle:@"Fetch “%@" plainTitle:@"Fetch"];
72+
} else if (menuItem.action == @selector(pullRemote:)) {
73+
return [self validateMenuItem:menuItem remoteTitle:@"Pull From “%@" plainTitle:@"Pull"];
7974
}
8075

8176
return YES;
8277
}
8378

79+
- (BOOL) validateMenuItem:(NSMenuItem *)menuItem remoteTitle:(NSString *)localisationKeyWithRemote plainTitle:(NSString *)localizationKeyWithoutRemote
80+
{
81+
PBSourceViewItem *item = [self selectedItem];
82+
PBGitRef *ref = item.ref;
83+
84+
if (!ref && (item.parent == sidebarController.remotes)) {
85+
ref = [PBGitRef refFromString:[kGitXRemoteRefPrefix stringByAppendingString:item.title]];
86+
}
87+
88+
if (ref.isRemote) {
89+
menuItem.title = [NSString stringWithFormat:NSLocalizedString(localisationKeyWithRemote, @""), ref.remoteName];
90+
return YES;
91+
}
92+
93+
menuItem.title = NSLocalizedString(localizationKeyWithoutRemote, @"");
94+
return NO;
95+
}
96+
97+
8498
- (void) awakeFromNib
8599
{
86100
[[self window] setDelegate:self];
@@ -261,15 +275,30 @@ - (IBAction) showAddRemoteSheet:(id)sender
261275

262276

263277
- (IBAction) fetchRemote:(id)sender {
264-
NSOutlineView *sourceView = sidebarController.sourceView;
265-
PBSourceViewItem *item = [sourceView itemAtRow:sourceView.selectedRow];
266-
[repository beginFetchFromRemoteForRef:item.ref];
278+
PBGitRef *ref = [self selectedItem].ref;
279+
[repository beginFetchFromRemoteForRef:ref];
267280
}
268281

269282
- (IBAction) fetchAllRemotes:(id)sender {
270283
[repository beginFetchFromRemoteForRef:nil];
271284
}
272285

286+
- (IBAction) pullRemote:(id)sender {
287+
PBGitRef *ref = [self selectedItem].revSpecifier.ref;
288+
PBGitRef *remoteRef = [repository remoteRefForBranch:ref error:NULL];
289+
[repository beginPullFromRemote:remoteRef forRef:ref];
290+
}
291+
292+
- (IBAction) pullDefaultRemote:(id)sender {
293+
PBGitRef *ref = [self selectedItem].revSpecifier.ref;
294+
[repository beginPullFromRemote:nil forRef:ref];
295+
}
296+
297+
- (PBSourceViewItem *) selectedItem {
298+
NSOutlineView *sourceView = sidebarController.sourceView;
299+
return [sourceView itemAtRow:sourceView.selectedRow];
300+
}
301+
273302
- (IBAction) stashSave:(id) sender
274303
{
275304
[repository stashSaveWithKeepIndex:NO];

English.lproj/MainMenu.xib

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,19 @@
401401
<action selector="fetchAllRemotes:" target="-1" id="gQf-4H-0cg"/>
402402
</connections>
403403
</menuItem>
404+
<menuItem isSeparatorItem="YES" id="CDX-1D-7tK"/>
405+
<menuItem title="Pull" id="ka6-UF-ky7">
406+
<modifierMask key="keyEquivalentModifierMask"/>
407+
<connections>
408+
<action selector="pullRemote:" target="-1" id="Uq3-eV-MxO"/>
409+
</connections>
410+
</menuItem>
411+
<menuItem title="Pull From Default Remote" id="hpV-fp-aO8">
412+
<modifierMask key="keyEquivalentModifierMask"/>
413+
<connections>
414+
<action selector="pullDefaultRemote:" target="-1" id="X3P-VB-IDo"/>
415+
</connections>
416+
</menuItem>
404417
<menuItem isSeparatorItem="YES" id="bMk-cx-k5H"/>
405418
<menuItem title="Stash Save" keyEquivalent="y" id="Zqy-z5-0Jz">
406419
<connections>

0 commit comments

Comments
 (0)