-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathNSTableView+Menu.m
37 lines (27 loc) · 934 Bytes
/
NSTableView+Menu.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//
// NSTableView+Menu.m
// data_m
//
// Created by Mike Fluff on 4/1/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "NSTableView+Menu.h"
@implementation NSTableView (ContextMenu)
- (NSMenu*)menuForEvent:(NSEvent*)event
{
NSPoint location = [self convertPoint:[event locationInWindow] fromView:nil];
NSInteger row = [self rowAtPoint:location];
if (!(row >= 0) || ([event type] != NSRightMouseDown)) {
return [super menuForEvent:event];
}
NSIndexSet *selected = [self selectedRowIndexes];
if (![selected containsIndex:row]) {
selected = [NSIndexSet indexSetWithIndex:row];
[self selectRowIndexes:selected byExtendingSelection:NO];
}
if ([[self delegate] respondsToSelector:@selector(tableView:menuForRows:)]) {
return [(id)[self delegate] tableView:self menuForRows:selected];
}
return [super menuForEvent:event];
}
@end