Merge branch 'pu/pb/index_quick_fix' into stable
[GitX.git] / PBCommitList.m
blob9f764225cbb205ad66d377cbc7d9dda2b087cb39
1 //
2 //  PBCommitList.m
3 //  GitX
4 //
5 //  Created by Pieter de Bie on 9/11/08.
6 //  Copyright 2008 __MyCompanyName__. All rights reserved.
7 //
9 #import "PBCommitList.h"
10 #import "PBGitRevisionCell.h"
11 #import "PBWebHistoryController.h"
13 @implementation PBCommitList
15 @synthesize mouseDownPoint;
16 - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL) local
18         return NSDragOperationCopy;
21 - (void)keyDown:(NSEvent *)event
23         NSString* character = [event charactersIgnoringModifiers];
25         // Pass on command-shift up/down to the responder. We want the splitview to capture this.
26         if ([event modifierFlags] & NSShiftKeyMask && [event modifierFlags] & NSCommandKeyMask && ([event keyCode] == 0x7E || [event keyCode] == 0x7D)) {
27                 [self.nextResponder keyDown:event];
28                 return;
29         }
31         if ([character isEqualToString:@" "])
32         {
33                 if ([event modifierFlags] & NSShiftKeyMask)
34                         [webView scrollPageUp: self];
35                 else
36                         [webView scrollPageDown: self];
37         }
38         else if ([character rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"jkcv"]].location == 0)
39                 [webController sendKey: character];
40         else
41                 [super keyDown: event];
44 - (void) copy:(id)sender
46         [controller copyCommitInfo];
47 };      
49 - (void)mouseDown:(NSEvent *)theEvent
51         mouseDownPoint = [[self window] mouseLocationOutsideOfEventStream];
52         [super mouseDown:theEvent];
55 - (NSImage *)dragImageForRowsWithIndexes:(NSIndexSet *)dragRows
56                                                         tableColumns:(NSArray *)tableColumns
57                                                                    event:(NSEvent *)dragEvent
58                                                                   offset:(NSPointPointer)dragImageOffset
60         NSPoint location = [self convertPointFromBase:mouseDownPoint];
61         int row = [self rowAtPoint:location];
62         int column = [self columnAtPoint:location];
63         PBGitRevisionCell *cell = (PBGitRevisionCell *)[self preparedCellAtColumn:column row:row];
65         int index = [cell indexAtX:location.x];
66         if (index == -1)
67                 return [super dragImageForRowsWithIndexes:dragRows tableColumns:tableColumns event:dragEvent offset:dragImageOffset];
69         NSRect rect = [cell rectAtIndex:index];
71         NSImage *newImage = [[NSImage alloc] initWithSize:NSMakeSize(rect.size.width + 3, rect.size.height + 3)];
72         rect.origin = NSMakePoint(0.5, 0.5);
74         [newImage lockFocus];
75         [cell drawLabelAtIndex:index inRect:rect];
76         [newImage unlockFocus];
78         *dragImageOffset = NSMakePoint(rect.size.width / 2 + 10, 0);
79         return newImage;
82 @end