-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyTableView.m
81 lines (63 loc) · 2 KB
/
MyTableView.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#import "MyTableView.h"
#import "MyWorkingCopy.h"
#import "MyWorkingCopyController.h"
#import "TableViewDelegate.h"
#import "IconTextCell.h"
#import "IconUtils.h"
#import "ViewUtils.h"
@implementation MyTableView
// It's mandatory to subclass MyTableView to implement this method.
- (unsigned int) draggingSourceOperationMaskForLocal: (BOOL) isLocal
{
#pragma unused(isLocal)
return NSDragOperationCopy | NSDragOperationMove;
}
- (void) awakeFromNib
{
IconTextCell* const cell = [IconTextCell new];
[cell setLineBreakMode: NSLineBreakByTruncatingMiddle];
[cell setFont: [NSFont labelFontOfSize: 11]];
[cell setIconRef: GenericFileIcon()];
[[self tableColumnWithIdentifier: @"path"] setDataCell: cell];
[cell release];
[self setDoubleAction: @selector(onDoubleClick:)];
}
- (void) onDoubleClick: (id) sender
{
[[[[self delegate] document] controller] doubleClickInTableView: sender];
}
//----------------------------------------------------------------------------------------
// Subvert the 10.5 behaviour (which eats SOME of these events)
- (void) keyDown: (NSEvent*) theEvent
{
// dprintf("keyCode=0x%X", [theEvent keyCode]);
switch ([theEvent keyCode])
{
case 0x73: // Home
[self scrollRowToVisible: 0];
break;
case 0x77: // End
[self scrollRowToVisible: [self numberOfRows] - 1];
break;
case 0x74: // Page Up
case 0x79: // Page Down
case 0x7E: // Up
case 0x7D: // Down
[super keyDown: theEvent];
break;
default:
[[self nextResponder] keyDown: theEvent];
break;
}
}
//----------------------------------------------------------------------------------------
// Select row under mouse before showing contextual menu.
- (void) rightMouseDown: (NSEvent*) theEvent
{
const int row = [self rowAtPoint: locationInView(theEvent, self)];
if (row >= 0 && ![self isRowSelected: row])
[self selectRowIndexes: [NSIndexSet indexSetWithIndex: row]
byExtendingSelection: ([theEvent modifierFlags] & NSShiftKeyMask) != 0];
[super rightMouseDown: theEvent];
}
@end // MyTableView