mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
9f048f6363
Update the methods for creating a branch.
- create new class and xib PBCreateBranchSheet
- remove old addRef: methods and iVars from PBRefController
- remove old sheet from PBHistoryView.xib
- put the implementation method in PBGitRepository
- add a contextual menu item for commits
- shows an error sheet
- ask the commitController to rearrangeObjects to make sure the new branch is shown
- switch from using "update-ref" to "branch" so that branches starting at a remote branch will track automatically (or not depending on the repo's settings)
88 lines
2.2 KiB
Objective-C
88 lines
2.2 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]];
|
|
[items addObject:[PBRefMenuItem separatorItem]];
|
|
|
|
// create branch
|
|
[items addObject:[PBRefMenuItem itemWithTitle:@"Create branch…" action:@selector(createBranch:) enabled:YES]];
|
|
|
|
// 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];
|
|
|
|
[items addObject:[PBRefMenuItem itemWithTitle:@"Create Branch…" action:@selector(createBranch:) enabled:YES]];
|
|
|
|
for (PBRefMenuItem *item in items) {
|
|
[item setTarget:target];
|
|
[item setRefish:commit];
|
|
}
|
|
|
|
return items;
|
|
}
|
|
|
|
|
|
@end
|