Files
gitx/PBRefMenuItem.m
T
Nathan Kinsinger ff5f3f7979 Add methods dealing with menus needed for future features.
Switch from storing both the ref and the commit to storing just one or the other as a refish.

Change action methods that receive PBRefMenuItem to support the change in functionality. In particular the removeRefSheetDidEnd:returnCode:contextInfo: method in PBRefController now looks up the commit for the ref (this was the only place that needed both the ref and the commit).
2010-03-06 15:58:20 -07:00

82 lines
1.9 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 refish;
+ (PBRefMenuItem *) itemWithTitle:(NSString *)title action:(SEL)selector enabled:(BOOL)isEnabled
{
if (!isEnabled)
selector = nil;
PBRefMenuItem *item = [[PBRefMenuItem alloc] initWithTitle:title action:selector keyEquivalent:@""];
[item setEnabled:isEnabled];
return item;
}
+ (PBRefMenuItem *) separatorItem
{
PBRefMenuItem *item = (PBRefMenuItem *)[super separatorItem];
return item;
}
+ (NSArray *) defaultMenuItemsForRef:(PBGitRef *)ref inRepository:(PBGitRepository *)repo target:(id)target
{
if (!ref || !repo || !target) {
return nil;
}
NSMutableArray *items = [NSMutableArray array];
NSString *targetRefName = [ref shortName];
PBGitRef *headRef = [[repo headRef] ref];
BOOL isHead = [ref isEqualToRef:headRef];
// checkout ref
NSString *checkoutTitle = [@"Checkout " stringByAppendingString:targetRefName];
[items addObject:[PBRefMenuItem itemWithTitle:checkoutTitle action:@selector(checkoutRef:) enabled:!isHead]];
// view tag info
if ([ref isTag])
[items addObject:[PBRefMenuItem itemWithTitle:@"View tag info" action:@selector(tagInfo:) enabled:YES]];
// delete ref
[items addObject:[PBRefMenuItem separatorItem]];
NSString *deleteTitle = [NSString stringWithFormat:@"Delete %@…", targetRefName];
[items addObject:[PBRefMenuItem itemWithTitle:deleteTitle action:@selector(removeRef:) enabled:YES]];
for (PBRefMenuItem *item in items) {
[item setTarget:target];
[item setRefish:ref];
}
return items;
}
+ (NSArray *) defaultMenuItemsForCommit:(PBGitCommit *)commit target:(id)target
{
NSMutableArray *items = [NSMutableArray array];
for (PBRefMenuItem *item in items) {
[item setTarget:target];
[item setRefish:commit];
}
return items;
}
@end