Permalink
Browse files

GitRevisionCell: Allow right-clicking on refs

This reuses the code in the RefController to show context menus
when right-clicking on refs.
  • Loading branch information...
1 parent e02ee52 commit a9dad9dd31d604501923304eba0b821bbff636ed @pieter committed Nov 1, 2008
@@ -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>"; };
@@ -469,6 +470,7 @@
F53FF2040E7ABB5300389171 /* PBGitRevSpecifier.m */,
F56174550E058893001DCD79 /* PBGitTree.h */,
F56174560E058893001DCD79 /* PBGitTree.m */,
+ F5FC43C30EBD050800191D80 /* PBRefContextDelegate.h */,
);
name = History;
sourceTree = "<group>";
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -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;
View
@@ -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
View
@@ -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
View
@@ -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;
View
@@ -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;
View
@@ -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!");

0 comments on commit a9dad9d

Please sign in to comment.