mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
93a027cccd
Mind you, these buttons cannot operate on the clicked branch like the context menu. Instead they always operate on the currently active branch (or its default remote).
63 lines
2.0 KiB
Objective-C
63 lines
2.0 KiB
Objective-C
//
|
|
// PBRefMenuItem.m
|
|
// GitX
|
|
//
|
|
// Created by Pieter de Bie on 01-11-08.
|
|
// Copyright 2008 Pieter de Bie. All rights reserved.
|
|
//
|
|
|
|
#import "PBRefMenuItem.h"
|
|
|
|
|
|
@implementation PBRefMenuItem
|
|
@synthesize ref, commit;
|
|
|
|
+ (PBRefMenuItem *)addRemoteMethod:(BOOL)hasRemote title:(NSString *)title action:(SEL)selector
|
|
{
|
|
PBRefMenuItem *item = [[PBRefMenuItem alloc] initWithTitle:title action:selector keyEquivalent:@""];
|
|
[item setEnabled:hasRemote];
|
|
return item;
|
|
}
|
|
|
|
+ (NSArray *)defaultMenuItemsForRef:(PBGitRef *)ref commit:(PBGitCommit *)commit target:(id)target
|
|
{
|
|
NSMutableArray *array = [NSMutableArray array];
|
|
NSString *type = [ref type];
|
|
if ([type isEqualToString:@"remote"])
|
|
type = @"remote branch";
|
|
else if ([type isEqualToString:@"head"])
|
|
type = @"branch";
|
|
|
|
NSString *remote = [[[commit repository] config] valueForKeyPath:[NSString stringWithFormat:@"branch.%@.remote", [ref shortName]]];
|
|
BOOL hasRemote = (remote ? YES : NO);
|
|
|
|
if ([type isEqualToString:@"branch"]) {
|
|
[array addObject:[self addRemoteMethod:hasRemote title:@"Push branch to remote" action:@selector(pushRef:)]];
|
|
[array addObject:[self addRemoteMethod:hasRemote title:@"Pull down latest" action:@selector(pullRef:)]];
|
|
[array addObject:[self addRemoteMethod:hasRemote title:@"Rebase local changes with latest" action:@selector(rebaseRef:)]];
|
|
}
|
|
|
|
if ([type isEqualToString:@"branch"])
|
|
[array addObject:[[PBRefMenuItem alloc] initWithTitle:@"Checkout branch"
|
|
action:@selector(checkoutRef:)
|
|
keyEquivalent: @""]];
|
|
|
|
[array addObject:[[PBRefMenuItem alloc] initWithTitle:[@"Delete " stringByAppendingString:type]
|
|
action:@selector(removeRef:)
|
|
keyEquivalent: @""]];
|
|
if ([type isEqualToString:@"tag"])
|
|
[array addObject:[[PBRefMenuItem alloc] initWithTitle:@"View tag info"
|
|
action:@selector(tagInfo:)
|
|
keyEquivalent: @""]];
|
|
|
|
for (PBRefMenuItem *item in array)
|
|
{
|
|
[item setTarget: target];
|
|
[item setRef: ref];
|
|
[item setCommit:commit];
|
|
}
|
|
|
|
return array;
|
|
}
|
|
@end
|