From 853ad7c8df3ee4e21bc4e09e142917552a24238b Mon Sep 17 00:00:00 2001 From: Mike Czepiel Date: Mon, 26 Jan 2015 12:45:53 -0800 Subject: [PATCH 1/2] Allow dragging SHA from commit list as plain text MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now there’s a quick way to stick reference to a commit without losing your copy pasteboard. Eventually it would be nice if you could use this to start performing interactive rebasing. --- Classes/Controllers/PBRefController.m | 41 ++++++++++++++------------- Classes/PBCommitList.m | 7 ++++- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/Classes/Controllers/PBRefController.m b/Classes/Controllers/PBRefController.m index ec27403a4..ff737cea5 100644 --- a/Classes/Controllers/PBRefController.m +++ b/Classes/Controllers/PBRefController.m @@ -339,29 +339,32 @@ - (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexe NSPoint location = [(PBCommitList *)tv mouseDownPoint]; int row = [tv rowAtPoint:location]; int column = [tv columnAtPoint:location]; - int subjectColumn = [tv columnWithIdentifier:@"SubjectColumn"]; - if (column != subjectColumn) - return NO; PBGitRevisionCell *cell = (PBGitRevisionCell *)[tv preparedCellAtColumn:column row:row]; - NSRect cellFrame = [tv frameOfCellAtColumn:column row:row]; - - int index = [cell indexAtX:(location.x - cellFrame.origin.x)]; - - if (index == -1) - return NO; - - PBGitRef *ref = [[[cell objectValue] refs] objectAtIndex:index]; - if ([ref isTag] || [ref isRemoteBranch]) - return NO; + PBGitCommit *commit = [[commitController arrangedObjects] objectAtIndex:row]; - if ([[[historyController.repository headRef] ref] isEqualToRef:ref]) - 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"]; + int index = -1; + if ([cell respondsToSelector:@selector(indexAtX:)]) { + NSRect cellFrame = [tv frameOfCellAtColumn:column row:row]; + index = [cell indexAtX:(location.x - cellFrame.origin.x)]; + } + if (index != -1) { + PBGitRef *ref = [[commit refs] objectAtIndex:index]; + if ([ref isTag] || [ref isRemoteBranch]) + return NO; + + if ([[[historyController.repository headRef] ref] isEqualToRef:ref]) + 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"]; + } else { + [pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:self]; + [pboard setString:[commit shortName] forType:NSStringPboardType]; + } + return YES; } diff --git a/Classes/PBCommitList.m b/Classes/PBCommitList.m index 8892e131f..ad7c6d388 100644 --- a/Classes/PBCommitList.m +++ b/Classes/PBCommitList.m @@ -106,7 +106,12 @@ - (NSImage *)dragImageForRowsWithIndexes:(NSIndexSet *)dragRows PBGitRevisionCell *cell = (PBGitRevisionCell *)[self preparedCellAtColumn:column row:row]; NSRect cellFrame = [self frameOfCellAtColumn:column row:row]; - int index = [cell indexAtX:(location.x - cellFrame.origin.x)]; + int index = -1; + + if ([cell respondsToSelector:@selector(indexAtX:)]) { + index = [cell indexAtX:(location.x - cellFrame.origin.x)]; + } + if (index == -1) return [super dragImageForRowsWithIndexes:dragRows tableColumns:tableColumns event:dragEvent offset:dragImageOffset]; From 8cfa37b926902903d5af248870f339bf4cd414bc Mon Sep 17 00:00:00 2001 From: Mike Czepiel Date: Mon, 26 Jan 2015 13:08:57 -0800 Subject: [PATCH 2/2] Differentiate drag behavior based on drag column Only copy the short SHA when dragging that column, copy the subject info on any other column. This mirrors the option-copy vs copy behavior. --- Classes/Controllers/PBRefController.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Classes/Controllers/PBRefController.m b/Classes/Controllers/PBRefController.m index ff737cea5..7836bf69a 100644 --- a/Classes/Controllers/PBRefController.m +++ b/Classes/Controllers/PBRefController.m @@ -362,7 +362,15 @@ - (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexe [pboard setData:data forType:@"PBGitRef"]; } else { [pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:self]; - [pboard setString:[commit shortName] forType:NSStringPboardType]; + + NSString *info = nil; + if (column == [tv columnWithIdentifier:@"ShortSHAColumn"]) { + info = [commit shortName]; + } else { + info = [NSString stringWithFormat:@"%@ (%@)", [[commit realSha] substringToIndex:10], [commit subject]]; + } + + [pboard setString:info forType:NSStringPboardType]; } return YES;