-
Notifications
You must be signed in to change notification settings - Fork 0
/
PBFileChangesTableView.m
74 lines (58 loc) · 2.32 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
//
// 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
#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];
// TODO: Fix the coupling so we don't need the cast (at least).
return [(PBGitIndexController*)[self delegate] menuForTable: self];
}
return nil;
}
- (NSDragOperation) draggingSourceOperationMaskForLocal:(BOOL) local
{
return NSDragOperationEvery;
}
#pragma mark NSView overrides
- (void)keyDown:(NSEvent *)theEvent
{
PBGitIndexController* controller = (PBGitIndexController*)[self delegate];
bool isUnstagedView = [self tag] == 0;
bool isStagedView = !isUnstagedView;
bool commandDown = theEvent.modifierFlags & NSCommandKeyMask;
if([theEvent.characters isEqualTo:@"s"] && commandDown && isUnstagedView) {
int oldSelectedRowIndex = self.selectedRow;
[controller stageSelectedFiles];
// Try to select the file after the one that was just staged, which will have the same index now
int rowIndexToSelect = oldSelectedRowIndex;
if(rowIndexToSelect > self.numberOfRows - 1) {
rowIndexToSelect = self.numberOfRows - 1;
}
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:rowIndexToSelect] byExtendingSelection:NO];
}
else if([theEvent.characters isEqualTo:@"u"] && commandDown && isStagedView) {
int oldSelectedRowIndex = self.selectedRow;
[controller unstageSelectedFiles];
// Try to select the file after the one that was just staged, which will have the same index now
int rowIndexToSelect = oldSelectedRowIndex;
if(rowIndexToSelect > self.numberOfRows - 1) {
rowIndexToSelect = self.numberOfRows - 1;
}
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:rowIndexToSelect] byExtendingSelection:NO];
}
else {
[super keyDown:theEvent];
}
}
@end