From e76d483180078c5f15d2e4fbdc69d4a15b0f003a Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Wed, 19 Nov 2008 15:06:13 +0100 Subject: [PATCH] CommitView: Allow drag and drop to external applications This allows you to drag a changed file to for example XCode, so you can edit it. --- PBFileChangesTableView.m | 6 ++++++ PBGitIndexController.m | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/PBFileChangesTableView.m b/PBFileChangesTableView.m index 60c28a7..4f489e1 100644 --- a/PBFileChangesTableView.m +++ b/PBFileChangesTableView.m @@ -18,4 +18,10 @@ return nil; } + +- (NSDragOperation) draggingSourceOperationMaskForLocal:(BOOL) local +{ + return NSDragOperationEvery; +} + @end diff --git a/PBGitIndexController.m b/PBGitIndexController.m index a754b43..750bef2 100644 --- a/PBGitIndexController.m +++ b/PBGitIndexController.m @@ -206,9 +206,22 @@ 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 declareTypes:[NSArray arrayWithObjects:FileChangesTableViewType, NSFilenamesPboardType, nil] owner:self]; + + // Internal, for dragging from one tableview to the other + NSData *data = [NSKeyedArchiver archivedDataWithRootObject:rowIndexes]; [pboard setData:data forType:FileChangesTableViewType]; + + // External, to drag them to for example XCode or Textmate + NSArrayController *controller = [tv tag] == 0 ? unstagedFilesController : stagedFilesController; + NSArray *files = [[controller arrangedObjects] objectsAtIndexes:rowIndexes]; + NSString *workingDirectory = [commitController.repository workingDirectory]; + + NSMutableArray *filenames = [NSMutableArray arrayWithCapacity:[rowIndexes count]]; + for (PBChangedFile *file in files) + [filenames addObject:[workingDirectory stringByAppendingPathComponent:[file path]]]; + + [pboard setPropertyList:filenames forType:NSFilenamesPboardType]; return YES; }