forked from brotherbard/gitx
/
PBFileChangesTableView.m
76 lines (59 loc) · 1.9 KB
/
PBFileChangesTableView.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
//
// PBFileChangesTableView.m
// GitX
//
// Created by Pieter de Bie on 09-10-08.
// Copyright 2008 Pieter de Bie. All rights reserved.
//
#import "PBFileChangesTableView.h"
#import "PBGitIndexController.h"
@implementation PBFileChangesTableView
static const NSUInteger mouseMask = (NSLeftMouseDownMask | NSLeftMouseUpMask | NSRightMouseDownMask | NSRightMouseUpMask | NSOtherMouseDownMask | NSOtherMouseUpMask);
- (BOOL)becomeFirstResponder;
{
if (![super becomeFirstResponder])
return NO;
NSUInteger numberOfSelectedRows = [self numberOfSelectedRows];
NSUInteger numberOfRows = [self numberOfRows];
if ((NSEventMaskFromType([[NSApp currentEvent] type]) & ~mouseMask) &&
([self numberOfSelectedRows] == 0 && [self numberOfRows] > 0)) {
if (lastSelectedRowIndexes != nil && numberOfRows == lastRowCount)
[self selectRowIndexes:lastSelectedRowIndexes byExtendingSelection:NO];
else
[self selectRow:0 byExtendingSelection:NO];
}
[moveButton setKeyEquivalent:@"\r"];
if (numberOfSelectedRows > 0)
[moveButton setEnabled:YES];
return YES;
}
- (BOOL)resignFirstResponder;
{
if (![super resignFirstResponder])
return NO;
lastSelectedRowIndexes = [self selectedRowIndexes];
lastRowCount = [self numberOfRows];
[moveButton setKeyEquivalent:@""];
[moveButton setEnabled:NO];
return YES;
}
- (NSButton *)moveButton;
{
return moveButton;
}
#pragma mark NSTableView overrides
- (NSMenu *)menuForEvent:(NSEvent *)theEvent
{
if ([self delegate]) {
NSPoint eventLocation = [self convertPoint: [theEvent locationInWindow] fromView: nil];
NSInteger rowIndex = [self rowAtPoint:eventLocation];
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:rowIndex] byExtendingSelection:TRUE];
return [[self delegate] menuForTable: self];
}
return nil;
}
- (NSDragOperation) draggingSourceOperationMaskForLocal:(BOOL) local
{
return NSDragOperationEvery;
}
@end