forked from pieter/gitx
-
Notifications
You must be signed in to change notification settings - Fork 2
/
PBCommitList.m
86 lines (71 loc) · 2.46 KB
/
PBCommitList.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
81
82
83
84
85
86
//
// PBCommitList.m
// GitX
//
// Created by Pieter de Bie on 9/11/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "PBCommitList.h"
#import "PBGitRevisionCell.h"
#import "PBWebHistoryController.h"
@implementation PBCommitList
@synthesize mouseDownPoint;
- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL) local
{
return NSDragOperationCopy;
}
- (void)keyDown:(NSEvent *)event
{
NSString* character = [event charactersIgnoringModifiers];
// Pass on command-shift up/down to the responder. We want the splitview to capture this.
if ([event modifierFlags] & NSShiftKeyMask && [event modifierFlags] & NSCommandKeyMask && ([event keyCode] == 0x7E || [event keyCode] == 0x7D)) {
[self.nextResponder keyDown:event];
return;
}
if ([character isEqualToString:@" "]) {
if (controller.selectedCommitDetailsIndex == 0) {
if ([event modifierFlags] & NSShiftKeyMask)
[webView scrollPageUp:self];
else
[webView scrollPageDown:self];
}
else
[controller toggleQLPreviewPanel:self];
}
else if ([character rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"jkcv"]].location == 0)
[webController sendKey: character];
else
[super keyDown: event];
}
- (void) copy:(id)sender
{
[controller copyCommitInfo];
};
- (void)mouseDown:(NSEvent *)theEvent
{
mouseDownPoint = [[self window] mouseLocationOutsideOfEventStream];
[super mouseDown:theEvent];
}
- (NSImage *)dragImageForRowsWithIndexes:(NSIndexSet *)dragRows
tableColumns:(NSArray *)tableColumns
event:(NSEvent *)dragEvent
offset:(NSPointPointer)dragImageOffset
{
NSPoint location = [self convertPointFromBase:mouseDownPoint];
int row = [self rowAtPoint:location];
int column = [self columnAtPoint:location];
PBGitRevisionCell *cell = (PBGitRevisionCell *)[self preparedCellAtColumn:column row:row];
NSRect cellFrame = [self frameOfCellAtColumn:column row:row];
int index = [cell indexAtX:(location.x - cellFrame.origin.x)];
if (index == -1)
return [super dragImageForRowsWithIndexes:dragRows tableColumns:tableColumns event:dragEvent offset:dragImageOffset];
NSRect rect = [cell rectAtIndex:index];
NSImage *newImage = [[NSImage alloc] initWithSize:NSMakeSize(rect.size.width + 3, rect.size.height + 3)];
rect.origin = NSMakePoint(0.5, 0.5);
[newImage lockFocus];
[cell drawLabelAtIndex:index inRect:rect];
[newImage unlockFocus];
*dragImageOffset = NSMakePoint(rect.size.width / 2 + 10, 0);
return newImage;
}
@end