Skip to content

Commit

Permalink
GitRevisionCell: Allow right-clicking on refs
Browse files Browse the repository at this point in the history
This reuses the code in the RefController to show context menus
when right-clicking on refs.
  • Loading branch information
pieter committed Nov 1, 2008
1 parent e02ee52 commit a9dad9d
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 83 deletions.
2 changes: 2 additions & 0 deletions GitX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
F5EF8C8D0E9D4A5D0050906B /* PBWebController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBWebController.m; sourceTree = "<group>"; };
F5FC41F20EBCBD4300191D80 /* PBGitXProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitXProtocol.h; sourceTree = "<group>"; };
F5FC41F30EBCBD4300191D80 /* PBGitXProtocol.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitXProtocol.m; sourceTree = "<group>"; };
F5FC43C30EBD050800191D80 /* PBRefContextDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBRefContextDelegate.h; sourceTree = "<group>"; };
F5FE6C010EB13BC900F30D12 /* PBServicesController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBServicesController.h; sourceTree = "<group>"; };
F5FE6C020EB13BC900F30D12 /* PBServicesController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBServicesController.m; sourceTree = "<group>"; };
F5FF4E160E0829C20006317A /* PBGitRevList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitRevList.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -469,6 +470,7 @@
F53FF2040E7ABB5300389171 /* PBGitRevSpecifier.m */,
F56174550E058893001DCD79 /* PBGitTree.h */,
F56174560E058893001DCD79 /* PBGitTree.m */,
F5FC43C30EBD050800191D80 /* PBRefContextDelegate.h */,
);
name = History;
sourceTree = "<group>";
Expand Down
168 changes: 89 additions & 79 deletions PBGitHistoryView.xib

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions PBGitRevisionCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
#import "PBGitGrapher.h"
#import "PBGraphCellInfo.h"
#import "PBGitHistoryController.h"
#import "PBRefContextDelegate.h"

@interface PBGitRevisionCell : NSActionCell {
id objectValue;
PBGraphCellInfo *cellInfo;
NSTextFieldCell *textCell;
IBOutlet PBGitHistoryController *controller;
IBOutlet id<PBRefContextDelegate> contextMenuDelegate;
}

- (int) indexAtX:(float)x;
Expand Down
23 changes: 23 additions & 0 deletions PBGitRevisionCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,27 @@ - (NSRect) rectAtIndex:(int)index
return [[[self rectsForRefsinRect:refRect] objectAtIndex:index] rectValue];
}

# pragma mark context menu delegate methods

- (NSMenu *) menuForEvent:(NSEvent *)event inRect:(NSRect)rect ofView:(NSView *)view
{
if (!contextMenuDelegate)
return [self menu];

int i = [self indexAtX:[view convertPointFromBase:[event locationInWindow]].x];
if (i < 0)
return [self menu];

id ref = [[[self objectValue] refs] objectAtIndex:i];
if (!ref)
return [self menu];

NSArray *items = [contextMenuDelegate menuItemsForRef:ref commit:[self objectValue]];
NSMenu *menu = [[NSMenu alloc] init];
for (NSMenuItem *item in items)
[menu addItem:item];
return menu;

return [self menu];
}
@end
13 changes: 13 additions & 0 deletions PBRefContextDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// PBRefContextDelegate.m
// GitX
//
// Created by Pieter de Bie on 01-11-08.
// Copyright 2008 Pieter de Bie. All rights reserved.
//



@protocol PBRefContextDelegate
- (NSArray *) menuItemsForRef:(PBGitRef *)ref commit:(PBGitCommit *)commit;
@end
3 changes: 2 additions & 1 deletion PBRefController.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
#import "PBCommitList.h"
#import "PBGitRef.h"
#import "PBGitCommit.h"
#import "PBRefContextDelegate.h"

@interface PBRefController : NSObject {
@interface PBRefController : NSObject <PBRefContextDelegate> {
IBOutlet __weak PBGitHistoryController *historyController;
IBOutlet NSArrayController *commitController;
IBOutlet PBCommitList *commitList;
Expand Down
4 changes: 2 additions & 2 deletions PBWebHistoryController.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

#import "PBGitCommit.h"
#import "PBGitHistoryController.h"
#import "PBRefController.h"
#import "PBRefContextDelegate.h"

@interface PBWebHistoryController : PBWebController {
IBOutlet PBGitHistoryController* historyController;
IBOutlet PBRefController *refController;
IBOutlet id<PBRefContextDelegate> contextMenuDelegate;

NSString* currentSha;
NSString* diff;
Expand Down
2 changes: 1 addition & 1 deletion PBWebHistoryController.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ - (NSArray *) webView:(WebView *)sender
for (PBGitRef *ref in historyController.webCommit.refs)
{
if ([[ref shortName] isEqualToString:selectedRefString])
return [refController menuItemsForRef:ref commit:historyController.webCommit];
return [contextMenuDelegate menuItemsForRef:ref commit:historyController.webCommit];
}
NSLog(@"Could not find selected ref!");

Expand Down

0 comments on commit a9dad9d

Please sign in to comment.