|
25 | 25 | #import "GitXCommitCopier.h"
|
26 | 26 | #import "NSSplitView+GitX.h"
|
27 | 27 | #import "PBGitRevisionRow.h"
|
| 28 | +#import "PBGitRevisionCell.h" |
28 | 29 | #import "PBRefMenuItem.h"
|
29 | 30 | #import "PBGitStash.h"
|
30 | 31 |
|
@@ -157,6 +158,8 @@ - (void)loadView {
|
157 | 158 | // Add a menu that allows a user to select which columns to view
|
158 | 159 | [[commitList headerView] setMenu:[self tableColumnMenu]];
|
159 | 160 |
|
| 161 | + [commitList registerForDraggedTypes:[NSArray arrayWithObject:@"PBGitRef"]]; |
| 162 | + |
160 | 163 | [upperToolbarView setTopShade:237/255.0f bottomShade:216/255.0f];
|
161 | 164 | [scopeBarView setTopColor:[NSColor colorWithCalibratedHue:0.579 saturation:0.068 brightness:0.898 alpha:1.000]
|
162 | 165 | bottomColor:[NSColor colorWithCalibratedHue:0.579 saturation:0.119 brightness:0.765 alpha:1.000]];
|
@@ -609,6 +612,123 @@ - (void) diffFilesAction:(id)sender
|
609 | 612 | [PBDiffWindowController showDiffWindowWithFiles:[sender representedObject] fromCommit:self.selectedCommits.firstObject diffCommit:nil];
|
610 | 613 | }
|
611 | 614 |
|
| 615 | +#pragma mark - |
| 616 | +#pragma mark History table view delegate |
| 617 | + |
| 618 | +- (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard*)pboard |
| 619 | +{ |
| 620 | + NSPoint location = [(PBCommitList *)tv mouseDownPoint]; |
| 621 | + NSInteger row = [tv rowAtPoint:location]; |
| 622 | + NSInteger column = [tv columnAtPoint:location]; |
| 623 | + |
| 624 | + PBGitRevisionCell *cell = (PBGitRevisionCell *)[tv viewAtColumn:column row:row makeIfNecessary:NO]; |
| 625 | + PBGitCommit *commit = [[commitController arrangedObjects] objectAtIndex:row]; |
| 626 | + |
| 627 | + int index = -1; |
| 628 | + if ([cell respondsToSelector:@selector(indexAtX:)]) { |
| 629 | + NSRect cellFrame = [tv frameOfCellAtColumn:column row:row]; |
| 630 | + CGFloat deltaX = location.x - cellFrame.origin.x; |
| 631 | + index = [cell indexAtX:deltaX]; |
| 632 | + } |
| 633 | + |
| 634 | + if (index != -1) { |
| 635 | + PBGitRef *ref = [[commit refs] objectAtIndex:index]; |
| 636 | + if ([ref isTag] || [ref isRemoteBranch]) |
| 637 | + return NO; |
| 638 | + |
| 639 | + if ([[[repository headRef] ref] isEqualToRef:ref]) |
| 640 | + return NO; |
| 641 | + |
| 642 | + NSData *data = [NSKeyedArchiver archivedDataWithRootObject:[NSArray arrayWithObjects:[NSNumber numberWithInteger:row], [NSNumber numberWithInt:index], NULL]]; |
| 643 | + [pboard declareTypes:[NSArray arrayWithObject:@"PBGitRef"] owner:self]; |
| 644 | + [pboard setData:data forType:@"PBGitRef"]; |
| 645 | + } else { |
| 646 | + [pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:self]; |
| 647 | + |
| 648 | + NSString *info = nil; |
| 649 | + if (column == [tv columnWithIdentifier:@"ShortSHAColumn"]) { |
| 650 | + info = [commit shortName]; |
| 651 | + } else { |
| 652 | + info = [NSString stringWithFormat:@"%@ (%@)", [commit shortName], [commit subject]]; |
| 653 | + } |
| 654 | + |
| 655 | + [pboard setString:info forType:NSStringPboardType]; |
| 656 | + } |
| 657 | + |
| 658 | + return YES; |
| 659 | +} |
| 660 | + |
| 661 | +- (NSDragOperation)tableView:(NSTableView*)tv |
| 662 | + validateDrop:(id <NSDraggingInfo>)info |
| 663 | + proposedRow:(NSInteger)row |
| 664 | + proposedDropOperation:(NSTableViewDropOperation)operation |
| 665 | +{ |
| 666 | + if (operation == NSTableViewDropAbove) |
| 667 | + return NSDragOperationNone; |
| 668 | + |
| 669 | + NSPasteboard *pboard = [info draggingPasteboard]; |
| 670 | + if ([pboard dataForType:@"PBGitRef"]) |
| 671 | + return NSDragOperationMove; |
| 672 | + |
| 673 | + return NSDragOperationNone; |
| 674 | +} |
| 675 | + |
| 676 | +- (BOOL)tableView:(NSTableView *)aTableView |
| 677 | + acceptDrop:(id <NSDraggingInfo>)info |
| 678 | + row:(NSInteger)row |
| 679 | + dropOperation:(NSTableViewDropOperation)operation |
| 680 | +{ |
| 681 | + if (operation != NSTableViewDropOn) |
| 682 | + return NO; |
| 683 | + |
| 684 | + NSPasteboard *pboard = [info draggingPasteboard]; |
| 685 | + NSData *data = [pboard dataForType:@"PBGitRef"]; |
| 686 | + if (!data) |
| 687 | + return NO; |
| 688 | + |
| 689 | + NSArray *numbers = [NSKeyedUnarchiver unarchiveObjectWithData:data]; |
| 690 | + int oldRow = [[numbers objectAtIndex:0] intValue]; |
| 691 | + if (oldRow == row) |
| 692 | + return NO; |
| 693 | + |
| 694 | + int oldRefIndex = [[numbers objectAtIndex:1] intValue]; |
| 695 | + PBGitCommit *oldCommit = [[commitController arrangedObjects] objectAtIndex:oldRow]; |
| 696 | + PBGitRef *ref = [[oldCommit refs] objectAtIndex:oldRefIndex]; |
| 697 | + |
| 698 | + PBGitCommit *dropCommit = [[commitController arrangedObjects] objectAtIndex:row]; |
| 699 | + |
| 700 | + NSString *subject = [dropCommit subject]; |
| 701 | + if ([subject length] > 99) |
| 702 | + subject = [[subject substringToIndex:99] stringByAppendingString:@"…"]; |
| 703 | + |
| 704 | + NSAlert *alert = [[NSAlert alloc] init]; |
| 705 | + alert.messageText = [NSString stringWithFormat:NSLocalizedString(@"Move %@: %@", @""), [ref refishType], [ref shortName]]; |
| 706 | + alert.informativeText = [NSString stringWithFormat:NSLocalizedString(@"Move the %@ to point to the commit: %@", @""), [ref refishType], subject]; |
| 707 | + |
| 708 | + [alert addButtonWithTitle:NSLocalizedString(@"Move", @"Move branch label - default button")]; |
| 709 | + [alert addButtonWithTitle:NSLocalizedString(@"Cancel", @"Move branch label - cancel button")]; |
| 710 | + |
| 711 | + PBGitWindowController *wc = self.windowController; |
| 712 | + [wc confirmDialog:alert |
| 713 | +suppressionIdentifier:kDialogAcceptDroppedRef |
| 714 | + forAction:^{ |
| 715 | + NSError *error = nil; |
| 716 | + if (![wc.repository updateReference:ref toPointAtCommit:dropCommit error:&error]) { |
| 717 | + [wc showErrorSheet:error]; |
| 718 | + return; |
| 719 | + } |
| 720 | + |
| 721 | + [dropCommit addRef:ref]; |
| 722 | + [oldCommit removeRef:ref]; |
| 723 | + }]; |
| 724 | + |
| 725 | + return YES; |
| 726 | +} |
| 727 | + |
| 728 | + |
| 729 | +#pragma mark - |
| 730 | +#pragma mark File browser |
| 731 | + |
612 | 732 | - (NSMenu *)contextMenuForTreeView
|
613 | 733 | {
|
614 | 734 | NSArray *filePaths = [[treeController selectedObjects] valueForKey:@"fullPath"];
|
|
0 commit comments