From b28afa1644e149a36f10e19bc156093a9e3c6afa Mon Sep 17 00:00:00 2001 From: Nathan Kinsinger Date: Sat, 4 Sep 2010 17:57:12 -0600 Subject: [PATCH] Add the contextual menu to the other columns of the commit list Now all the columns have the menu for the commit, not just the subject column. --- GitXTextFieldCell.h | 3 +- GitXTextFieldCell.m | 17 +++++++++ PBGitHistoryView.xib | 85 +++++++++++++++++++++++++++++++++--------- PBRefContextDelegate.h | 4 ++ PBRefController.h | 1 + PBRefController.m | 9 +++++ 6 files changed, 101 insertions(+), 18 deletions(-) diff --git a/GitXTextFieldCell.h b/GitXTextFieldCell.h index 4bd3ec7..1161dca 100644 --- a/GitXTextFieldCell.h +++ b/GitXTextFieldCell.h @@ -7,10 +7,11 @@ // #import +#import "PBRefContextDelegate.h" @interface GitXTextFieldCell : NSTextFieldCell { - + IBOutlet id contextMenuDelegate; } @end diff --git a/GitXTextFieldCell.m b/GitXTextFieldCell.m index bc95397..9e90193 100644 --- a/GitXTextFieldCell.m +++ b/GitXTextFieldCell.m @@ -7,6 +7,8 @@ // #import "GitXTextFieldCell.h" +#import "PBGitCommit.h" +#import "PBRefController.h" @implementation GitXTextFieldCell @@ -17,4 +19,19 @@ return nil; } +- (NSMenu *)menuForEvent:(NSEvent *)anEvent inRect:(NSRect)cellFrame ofView:(NSTableView *)commitList +{ + NSInteger rowIndex = [commitList rowAtPoint:(cellFrame.origin)]; + NSArray *items = [contextMenuDelegate menuItemsForRow:rowIndex]; + if (!items) + return nil; + + NSMenu *menu = [[NSMenu alloc] init]; + [menu setAutoenablesItems:NO]; + for (NSMenuItem *item in items) + [menu addItem:item]; + + return menu; +} + @end diff --git a/PBGitHistoryView.xib b/PBGitHistoryView.xib index f9e2774..4bda4c9 100644 --- a/PBGitHistoryView.xib +++ b/PBGitHistoryView.xib @@ -1616,14 +1616,6 @@ 95 - - - delegate - - - - 96 - delegate @@ -1696,14 +1688,6 @@ 234 - - - dataSource - - - - 235 - contextMenuDelegate @@ -2097,13 +2081,69 @@ 436 + + + contextMenuDelegate + + + + 438 + + + + contextMenuDelegate + + + + 439 + + + + contextMenuDelegate + + + + 440 + + + + contextMenuDelegate + + + + 441 + + + + contextMenuDelegate + + + + 442 + + + + delegate + + + + 444 + + + + dataSource + + + + 445 + searchController - 437 + 446 @@ -3064,6 +3104,17 @@ GitXTextFieldCell NSTextFieldCell + + contextMenuDelegate + id + + + contextMenuDelegate + + contextMenuDelegate + id + + IBProjectSource GitXTextFieldCell.h diff --git a/PBRefContextDelegate.h b/PBRefContextDelegate.h index 1b7a973..9112b8f 100644 --- a/PBRefContextDelegate.h +++ b/PBRefContextDelegate.h @@ -7,8 +7,12 @@ // +@class PBGitRef; +@class PBGitCommit; + @protocol PBRefContextDelegate - (NSArray *) menuItemsForRef:(PBGitRef *)ref; - (NSArray *) menuItemsForCommit:(PBGitCommit *)commit; +- (NSArray *)menuItemsForRow:(NSInteger)rowIndex; @end diff --git a/PBRefController.h b/PBRefController.h index 76e5cd8..15df74b 100644 --- a/PBRefController.h +++ b/PBRefController.h @@ -43,6 +43,7 @@ - (NSArray *) menuItemsForRef:(PBGitRef *)ref; - (NSArray *) menuItemsForCommit:(PBGitCommit *)commit; +- (NSArray *)menuItemsForRow:(NSInteger)rowIndex; @end diff --git a/PBRefController.m b/PBRefController.m index ca560a1..26dd6f2 100644 --- a/PBRefController.m +++ b/PBRefController.m @@ -275,6 +275,15 @@ return [PBRefMenuItem defaultMenuItemsForCommit:commit target:self]; } +- (NSArray *)menuItemsForRow:(NSInteger)rowIndex +{ + NSArray *commits = [commitController arrangedObjects]; + if ([commits count] <= rowIndex) + return nil; + + return [self menuItemsForCommit:[commits objectAtIndex:rowIndex]]; +} + # pragma mark Tableview delegate methods