Skip to content

Commit a9dad9d

Browse files
committed
GitRevisionCell: Allow right-clicking on refs
This reuses the code in the RefController to show context menus when right-clicking on refs.
1 parent e02ee52 commit a9dad9d

8 files changed

+134
-83
lines changed

GitX.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@
207207
F5EF8C8D0E9D4A5D0050906B /* PBWebController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBWebController.m; sourceTree = "<group>"; };
208208
F5FC41F20EBCBD4300191D80 /* PBGitXProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitXProtocol.h; sourceTree = "<group>"; };
209209
F5FC41F30EBCBD4300191D80 /* PBGitXProtocol.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitXProtocol.m; sourceTree = "<group>"; };
210+
F5FC43C30EBD050800191D80 /* PBRefContextDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBRefContextDelegate.h; sourceTree = "<group>"; };
210211
F5FE6C010EB13BC900F30D12 /* PBServicesController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBServicesController.h; sourceTree = "<group>"; };
211212
F5FE6C020EB13BC900F30D12 /* PBServicesController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBServicesController.m; sourceTree = "<group>"; };
212213
F5FF4E160E0829C20006317A /* PBGitRevList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitRevList.h; sourceTree = "<group>"; };
@@ -469,6 +470,7 @@
469470
F53FF2040E7ABB5300389171 /* PBGitRevSpecifier.m */,
470471
F56174550E058893001DCD79 /* PBGitTree.h */,
471472
F56174560E058893001DCD79 /* PBGitTree.m */,
473+
F5FC43C30EBD050800191D80 /* PBRefContextDelegate.h */,
472474
);
473475
name = History;
474476
sourceTree = "<group>";

PBGitHistoryView.xib

Lines changed: 89 additions & 79 deletions
Large diffs are not rendered by default.

PBGitRevisionCell.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
#import "PBGitGrapher.h"
1111
#import "PBGraphCellInfo.h"
1212
#import "PBGitHistoryController.h"
13+
#import "PBRefContextDelegate.h"
1314

1415
@interface PBGitRevisionCell : NSActionCell {
1516
id objectValue;
1617
PBGraphCellInfo *cellInfo;
1718
NSTextFieldCell *textCell;
1819
IBOutlet PBGitHistoryController *controller;
20+
IBOutlet id<PBRefContextDelegate> contextMenuDelegate;
1921
}
2022

2123
- (int) indexAtX:(float)x;

PBGitRevisionCell.m

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,27 @@ - (NSRect) rectAtIndex:(int)index
278278
return [[[self rectsForRefsinRect:refRect] objectAtIndex:index] rectValue];
279279
}
280280

281+
# pragma mark context menu delegate methods
282+
283+
- (NSMenu *) menuForEvent:(NSEvent *)event inRect:(NSRect)rect ofView:(NSView *)view
284+
{
285+
if (!contextMenuDelegate)
286+
return [self menu];
287+
288+
int i = [self indexAtX:[view convertPointFromBase:[event locationInWindow]].x];
289+
if (i < 0)
290+
return [self menu];
291+
292+
id ref = [[[self objectValue] refs] objectAtIndex:i];
293+
if (!ref)
294+
return [self menu];
295+
296+
NSArray *items = [contextMenuDelegate menuItemsForRef:ref commit:[self objectValue]];
297+
NSMenu *menu = [[NSMenu alloc] init];
298+
for (NSMenuItem *item in items)
299+
[menu addItem:item];
300+
return menu;
301+
302+
return [self menu];
303+
}
281304
@end

PBRefContextDelegate.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// PBRefContextDelegate.m
3+
// GitX
4+
//
5+
// Created by Pieter de Bie on 01-11-08.
6+
// Copyright 2008 Pieter de Bie. All rights reserved.
7+
//
8+
9+
10+
11+
@protocol PBRefContextDelegate
12+
- (NSArray *) menuItemsForRef:(PBGitRef *)ref commit:(PBGitCommit *)commit;
13+
@end

PBRefController.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
#import "PBCommitList.h"
1212
#import "PBGitRef.h"
1313
#import "PBGitCommit.h"
14+
#import "PBRefContextDelegate.h"
1415

15-
@interface PBRefController : NSObject {
16+
@interface PBRefController : NSObject <PBRefContextDelegate> {
1617
IBOutlet __weak PBGitHistoryController *historyController;
1718
IBOutlet NSArrayController *commitController;
1819
IBOutlet PBCommitList *commitList;

PBWebHistoryController.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
#import "PBGitCommit.h"
1313
#import "PBGitHistoryController.h"
14-
#import "PBRefController.h"
14+
#import "PBRefContextDelegate.h"
1515

1616
@interface PBWebHistoryController : PBWebController {
1717
IBOutlet PBGitHistoryController* historyController;
18-
IBOutlet PBRefController *refController;
18+
IBOutlet id<PBRefContextDelegate> contextMenuDelegate;
1919

2020
NSString* currentSha;
2121
NSString* diff;

PBWebHistoryController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ - (NSArray *) webView:(WebView *)sender
8686
for (PBGitRef *ref in historyController.webCommit.refs)
8787
{
8888
if ([[ref shortName] isEqualToString:selectedRefString])
89-
return [refController menuItemsForRef:ref commit:historyController.webCommit];
89+
return [contextMenuDelegate menuItemsForRef:ref commit:historyController.webCommit];
9090
}
9191
NSLog(@"Could not find selected ref!");
9292

0 commit comments

Comments
 (0)