From 6fcc12d69d7782b035738ba912c7beff46af625d Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Tue, 18 Nov 2008 23:52:46 +0100 Subject: [PATCH] CommitView: Allow drag 'n drop of staged / unstaged files --- PBGitCommitView.xib | 72 ++++++++++++++++++++++++++---------------- PBGitIndexController.m | 49 ++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 28 deletions(-) diff --git a/PBGitCommitView.xib b/PBGitCommitView.xib index 9dd1770..470dc78 100644 --- a/PBGitCommitView.xib +++ b/PBGitCommitView.xib @@ -48,7 +48,7 @@ 1044 - + 6 System controlColor @@ -678,19 +678,19 @@ 1.600000e+01 1.000000e+02 - + 292 {{264, 10}, {169, 17}} YES - + 68288064 272630784 Label - - + + @@ -847,7 +847,7 @@ YES - + PBGitIndexController @@ -1066,14 +1066,14 @@ indexController - + 256 commitController - + 257 @@ -1082,7 +1082,7 @@ delegate - + 258 @@ -1090,14 +1090,14 @@ delegate - + 259 unstagedFilesController - + 260 @@ -1105,7 +1105,7 @@ stagedFilesController - + 261 @@ -1114,14 +1114,14 @@ indexController - + 262 stagedTable - + 263 @@ -1129,7 +1129,7 @@ unstagedTable - + 264 @@ -1137,7 +1137,7 @@ stagedButtonCell - + 265 @@ -1145,7 +1145,7 @@ unstagedButtonCell - + 266 @@ -1153,7 +1153,7 @@ rowClicked: - + 268 @@ -1161,7 +1161,7 @@ rowClicked: - + 269 @@ -1169,10 +1169,10 @@ value: selection.commitBlobSHA - + - + value: selection.commitBlobSHA value @@ -1182,6 +1182,22 @@ 274 + + + dataSource + + + + 276 + + + + dataSource + + + + 277 + @@ -1220,7 +1236,7 @@ - + @@ -1505,22 +1521,22 @@ 254 - + 270 - + YES - + 271 - - + + @@ -1643,7 +1659,7 @@ - 275 + 277 diff --git a/PBGitIndexController.m b/PBGitIndexController.m index 3591b97..a754b43 100644 --- a/PBGitIndexController.m +++ b/PBGitIndexController.m @@ -9,6 +9,8 @@ #import "PBGitIndexController.h" #import "PBChangedFile.h" +#define FileChangesTableViewType @"GitFileChangedType" + @implementation PBGitIndexController - (void)awakeFromNib @@ -18,6 +20,10 @@ [unstagedTable setTarget:self]; [stagedTable setTarget:self]; + + [unstagedTable registerForDraggedTypes: [NSArray arrayWithObject:FileChangesTableViewType]]; + [stagedTable registerForDraggedTypes: [NSArray arrayWithObject:FileChangesTableViewType]]; + } - (void) stageFiles:(NSArray *)files @@ -195,6 +201,49 @@ [self tableClicked: tableView]; } +- (BOOL)tableView:(NSTableView *)tv +writeRowsWithIndexes:(NSIndexSet *)rowIndexes + toPasteboard:(NSPasteboard*)pboard +{ + // Copy the row numbers to the pasteboard. + NSData *data = [NSKeyedArchiver archivedDataWithRootObject:rowIndexes]; + [pboard declareTypes:[NSArray arrayWithObject:FileChangesTableViewType] owner:self]; + [pboard setData:data forType:FileChangesTableViewType]; + return YES; +} + +- (NSDragOperation)tableView:(NSTableView*)tableView + validateDrop:(id )info + proposedRow:(int)row + proposedDropOperation:(NSTableViewDropOperation)operation +{ + if ([info draggingSource] == tableView) + return NSDragOperationNone; + + [tableView setDropRow:-1 dropOperation:NSTableViewDropOn]; + return NSDragOperationCopy; +} + +- (BOOL)tableView:(NSTableView *)aTableView + acceptDrop:(id )info + row:(int)row + dropOperation:(NSTableViewDropOperation)operation +{ + NSPasteboard* pboard = [info draggingPasteboard]; + NSData* rowData = [pboard dataForType:FileChangesTableViewType]; + NSIndexSet* rowIndexes = [NSKeyedUnarchiver unarchiveObjectWithData:rowData]; + + NSArrayController *controller = [aTableView tag] == 0 ? stagedFilesController : unstagedFilesController; + NSArray *files = [[controller arrangedObjects] objectsAtIndexes:rowIndexes]; + + if ([aTableView tag] == 0) + [self unstageFiles:files]; + else + [self stageFiles:files]; + + return YES; +} + # pragma mark WebKit Accessibility + (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector