mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 15:30:18 +00:00
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).
This commit is contained in:
+1
-1
@@ -291,7 +291,7 @@
|
||||
if (!ref)
|
||||
return [self menu];
|
||||
|
||||
NSArray *items = [contextMenuDelegate menuItemsForRef:ref commit:[self objectValue]];
|
||||
NSArray *items = [contextMenuDelegate menuItemsForRef:ref];
|
||||
NSMenu *menu = [[NSMenu alloc] init];
|
||||
for (NSMenuItem *item in items)
|
||||
[menu addItem:item];
|
||||
|
||||
@@ -9,5 +9,6 @@
|
||||
|
||||
|
||||
@protocol PBRefContextDelegate
|
||||
- (NSArray *) menuItemsForRef:(PBGitRef *)ref commit:(PBGitCommit *)commit;
|
||||
- (NSArray *) menuItemsForRef:(PBGitRef *)ref;
|
||||
- (NSArray *) menuItemsForCommit:(PBGitCommit *)commit;
|
||||
@end
|
||||
|
||||
+4
-1
@@ -13,6 +13,8 @@
|
||||
#import "PBGitCommit.h"
|
||||
#import "PBRefContextDelegate.h"
|
||||
|
||||
@class PBRefMenuItem;
|
||||
|
||||
@interface PBRefController : NSObject <PBRefContextDelegate> {
|
||||
IBOutlet __weak PBGitHistoryController *historyController;
|
||||
IBOutlet NSArrayController *commitController;
|
||||
@@ -29,7 +31,8 @@
|
||||
- (IBAction)closeSheet:(id) sender;
|
||||
- (IBAction)saveSheet:(id) sender;
|
||||
|
||||
- (NSArray *) menuItemsForRef:(PBGitRef *)ref commit:(PBGitCommit *)commit;
|
||||
- (NSArray *) menuItemsForRef:(PBGitRef *)ref;
|
||||
- (NSArray *) menuItemsForCommit:(PBGitCommit *)commit;
|
||||
|
||||
- (void) changeBranch:(NSMenuItem *)sender;
|
||||
- (void) selectCurrentBranch;
|
||||
|
||||
+18
-9
@@ -39,20 +39,21 @@
|
||||
if (returnCode == NSAlertDefaultReturn) {
|
||||
int ret = 1;
|
||||
PBRefMenuItem *refMenuItem = contextInfo;
|
||||
[historyController.repository outputForArguments:[NSArray arrayWithObjects:@"update-ref", @"-d", [[refMenuItem ref] ref], nil] retValue: &ret];
|
||||
[historyController.repository outputForArguments:[NSArray arrayWithObjects:@"update-ref", @"-d", [[refMenuItem refish] refishName], nil] retValue: &ret];
|
||||
if (ret) {
|
||||
NSLog(@"Removing ref failed!");
|
||||
return;
|
||||
}
|
||||
[historyController.repository removeBranch:[[PBGitRevSpecifier alloc] initWithRef:[refMenuItem ref]]];
|
||||
[[refMenuItem commit] removeRef:[refMenuItem ref]];
|
||||
[historyController.repository removeBranch:[[PBGitRevSpecifier alloc] initWithRef:[refMenuItem refish]]];
|
||||
PBGitCommit *commitForRef = [historyController.repository commitForRef:[refMenuItem refish]];
|
||||
[commitForRef removeRef:[refMenuItem refish]];
|
||||
[commitController rearrangeObjects];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) removeRef:(PBRefMenuItem *)sender
|
||||
{
|
||||
NSString *ref_desc = [NSString stringWithFormat:@"%@ %@", [[sender ref] type], [[sender ref] shortName]];
|
||||
NSString *ref_desc = [NSString stringWithFormat:@"%@ %@", [(PBGitRef *)[sender refish] type], [[sender refish] shortName]];
|
||||
NSString *question = [NSString stringWithFormat:@"Are you sure you want to remove the %@?", ref_desc];
|
||||
NSBeginAlertSheet([NSString stringWithFormat:@"Delete %@?", ref_desc], @"Delete", @"Cancel", nil, [[historyController view] window], self, @selector(removeRefSheetDidEnd:returnCode:contextInfo:), NULL, sender, question);
|
||||
}
|
||||
@@ -60,7 +61,7 @@
|
||||
- (void) checkoutRef:(PBRefMenuItem *)sender
|
||||
{
|
||||
int ret = 1;
|
||||
[historyController.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"checkout", [[sender ref] shortName], nil] retValue: &ret];
|
||||
[historyController.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"checkout", [[sender refish] shortName], nil] retValue: &ret];
|
||||
if (ret) {
|
||||
[[historyController.repository windowController] showMessageSheet:@"Checking out branch failed" infoText:@"There was an error checking out the branch. Perhaps your working directory is not clean?"];
|
||||
return;
|
||||
@@ -71,10 +72,10 @@
|
||||
|
||||
- (void) tagInfo:(PBRefMenuItem *)sender
|
||||
{
|
||||
NSString *message = [NSString stringWithFormat:@"Info for tag: %@", [[sender ref] shortName]];
|
||||
NSString *message = [NSString stringWithFormat:@"Info for tag: %@", [[sender refish] shortName]];
|
||||
|
||||
int ret = 1;
|
||||
NSString *info = [historyController.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"tag", @"-n50", @"-l", [[sender ref] shortName], nil] retValue: &ret];
|
||||
NSString *info = [historyController.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"tag", @"-n50", @"-l", [[sender refish] shortName], nil] retValue: &ret];
|
||||
|
||||
if (!ret) {
|
||||
[[historyController.repository windowController] showMessageSheet:message infoText:info];
|
||||
@@ -82,11 +83,19 @@
|
||||
return;
|
||||
}
|
||||
|
||||
- (NSArray *) menuItemsForRef:(PBGitRef *)ref commit:(PBGitCommit *)commit
|
||||
#pragma mark Contextual menus
|
||||
|
||||
- (NSArray *) menuItemsForRef:(PBGitRef *)ref
|
||||
{
|
||||
return [PBRefMenuItem defaultMenuItemsForRef:ref commit:commit target:self];
|
||||
return [PBRefMenuItem defaultMenuItemsForRef:ref inRepository:historyController.repository target:self];
|
||||
}
|
||||
|
||||
- (NSArray *) menuItemsForCommit:(PBGitCommit *)commit
|
||||
{
|
||||
return [PBRefMenuItem defaultMenuItemsForCommit:commit target:self];
|
||||
}
|
||||
|
||||
|
||||
# pragma mark Tableview delegate methods
|
||||
|
||||
- (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard*)pboard
|
||||
|
||||
+6
-6
@@ -11,13 +11,13 @@
|
||||
#import "PBGitCommit.h"
|
||||
|
||||
@interface PBRefMenuItem : NSMenuItem {
|
||||
PBGitRef *ref;
|
||||
PBGitCommit *commit;
|
||||
id <PBGitRefish> refish;
|
||||
}
|
||||
|
||||
@property (retain) PBGitCommit *commit;
|
||||
@property (retain) PBGitRef *ref;
|
||||
|
||||
+ (NSArray *)defaultMenuItemsForRef:(PBGitRef *)ref commit:(PBGitCommit *)commit target:(id)target;
|
||||
@property (retain) id <PBGitRefish> refish;
|
||||
|
||||
+ (PBRefMenuItem *) separatorItem;
|
||||
+ (NSArray *) defaultMenuItemsForRef:(PBGitRef *)ref inRepository:(PBGitRepository *)repo target:(id)target;
|
||||
+ (NSArray *) defaultMenuItemsForCommit:(PBGitCommit *)commit target:(id)target;
|
||||
|
||||
@end
|
||||
|
||||
+61
-26
@@ -10,37 +10,72 @@
|
||||
|
||||
|
||||
@implementation PBRefMenuItem
|
||||
@synthesize ref, commit;
|
||||
@synthesize refish;
|
||||
|
||||
+ (NSArray *)defaultMenuItemsForRef:(PBGitRef *)ref commit:(PBGitCommit *)commit target:(id)target
|
||||
+ (PBRefMenuItem *) itemWithTitle:(NSString *)title action:(SEL)selector enabled:(BOOL)isEnabled
|
||||
{
|
||||
NSMutableArray *array = [NSMutableArray array];
|
||||
NSString *type = [ref type];
|
||||
if ([type isEqualToString:@"remote"])
|
||||
type = @"remote branch";
|
||||
else if ([type isEqualToString:@"head"])
|
||||
type = @"branch";
|
||||
if (!isEnabled)
|
||||
selector = nil;
|
||||
|
||||
[array addObject:[[PBRefMenuItem alloc] initWithTitle:[@"Delete " stringByAppendingString:type]
|
||||
action:@selector(removeRef:)
|
||||
keyEquivalent: @""]];
|
||||
if ([type isEqualToString:@"branch"])
|
||||
[array addObject:[[PBRefMenuItem alloc] initWithTitle:@"Checkout branch"
|
||||
action:@selector(checkoutRef:)
|
||||
keyEquivalent: @""]];
|
||||
PBRefMenuItem *item = [[PBRefMenuItem alloc] initWithTitle:title action:selector keyEquivalent:@""];
|
||||
[item setEnabled:isEnabled];
|
||||
return item;
|
||||
}
|
||||
|
||||
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];
|
||||
|
||||
+ (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;
|
||||
}
|
||||
|
||||
return array;
|
||||
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
|
||||
|
||||
@@ -115,7 +115,7 @@ contextMenuItemsForElement:(NSDictionary *)element
|
||||
for (PBGitRef *ref in historyController.webCommit.refs)
|
||||
{
|
||||
if ([[ref shortName] isEqualToString:selectedRefString])
|
||||
return [contextMenuDelegate menuItemsForRef:ref commit:historyController.webCommit];
|
||||
return [contextMenuDelegate menuItemsForRef:ref];
|
||||
}
|
||||
NSLog(@"Could not find selected ref!");
|
||||
return defaultMenuItems;
|
||||
|
||||
Reference in New Issue
Block a user