mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
101 lines
3.0 KiB
Objective-C
101 lines
3.0 KiB
Objective-C
//
|
|
// PBLabelController.m
|
|
// GitX
|
|
//
|
|
// Created by Pieter de Bie on 21-10-08.
|
|
// Copyright 2008 Pieter de Bie. All rights reserved.
|
|
//
|
|
|
|
#import "PBRefController.h"
|
|
#import "PBGitRevisionCell.h"
|
|
|
|
@implementation PBRefController
|
|
|
|
- (void)awakeFromNib
|
|
{
|
|
[commitList registerForDraggedTypes:[NSArray arrayWithObject:@"PBGitRef"]];
|
|
}
|
|
|
|
- (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard*)pboard
|
|
{
|
|
NSPoint location = [tv convertPointFromBase:[(PBCommitList *)tv mouseDownPoint]];
|
|
int row = [tv rowAtPoint:location];
|
|
int column = [tv columnAtPoint:location];
|
|
if (column != 0)
|
|
return NO;
|
|
|
|
PBGitRevisionCell *cell = (PBGitRevisionCell *)[tv preparedCellAtColumn:column row:row];
|
|
|
|
int index = [cell indexAtX:location.x];
|
|
|
|
if (index == -1)
|
|
return NO;
|
|
|
|
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:[NSArray arrayWithObjects:[NSNumber numberWithInt:row], [NSNumber numberWithInt:index], NULL]];
|
|
[pboard declareTypes:[NSArray arrayWithObject:@"PBGitRef"] owner:self];
|
|
[pboard setData:data forType:@"PBGitRef"];
|
|
|
|
return YES;
|
|
}
|
|
|
|
- (NSDragOperation)tableView:(NSTableView*)tv
|
|
validateDrop:(id <NSDraggingInfo>)info
|
|
proposedRow:(int)row
|
|
proposedDropOperation:(NSTableViewDropOperation)operation
|
|
{
|
|
if (operation == NSTableViewDropAbove)
|
|
return NSDragOperationNone;
|
|
|
|
NSPasteboard *pboard = [info draggingPasteboard];
|
|
if ([pboard dataForType:@"PBGitRef"])
|
|
return NSDragOperationMove;
|
|
|
|
return NSDragOperationNone;
|
|
}
|
|
|
|
- (BOOL)tableView:(NSTableView *)aTableView
|
|
acceptDrop:(id <NSDraggingInfo>)info
|
|
row:(int)row
|
|
dropOperation:(NSTableViewDropOperation)operation
|
|
{
|
|
if (operation != NSTableViewDropOn)
|
|
return NO;
|
|
|
|
NSPasteboard *pboard = [info draggingPasteboard];
|
|
NSData *data = [pboard dataForType:@"PBGitRef"];
|
|
if (!data)
|
|
return NO;
|
|
|
|
NSArray *numbers = [NSKeyedUnarchiver unarchiveObjectWithData:data];
|
|
int oldRow = [[numbers objectAtIndex:0] intValue];
|
|
int oldRefIndex = [[numbers objectAtIndex:1] intValue];
|
|
PBGitCommit *oldCommit = [[commitController arrangedObjects] objectAtIndex: oldRow];
|
|
PBGitRef *ref = [[oldCommit refs] objectAtIndex:oldRefIndex];
|
|
|
|
PBGitCommit *dropCommit = [[commitController arrangedObjects] objectAtIndex:row];
|
|
|
|
int a = [[NSAlert alertWithMessageText:@"Change branch"
|
|
defaultButton:@"Change"
|
|
alternateButton:@"Cancel"
|
|
otherButton:nil
|
|
informativeTextWithFormat:@"Do you want to change branch\n\n\t'%@'\n\n to point to commit\n\n\t'%@'", [ref shortName], [dropCommit subject]] runModal];
|
|
if (a != NSAlertDefaultReturn)
|
|
return NO;
|
|
|
|
int retValue = 1;
|
|
[historyController.repository outputForArguments:[NSArray arrayWithObjects:@"update-ref", @"-mUpdate from GitX", [ref ref], [dropCommit sha], NULL] retValue:&retValue];
|
|
if (retValue)
|
|
return NO;
|
|
|
|
[dropCommit addRef:ref];
|
|
|
|
[oldCommit.refs removeObject:ref];
|
|
if ([oldCommit.refs count] == 0)
|
|
oldCommit.refs = NULL;
|
|
|
|
[commitController rearrangeObjects];
|
|
[aTableView needsToDrawRect:[aTableView rectOfRow:oldRow]];
|
|
return YES;
|
|
}
|
|
@end
|