Browse files

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.
  • Loading branch information...
1 parent b0caa34 commit e76d483180078c5f15d2e4fbdc69d4a15b0f003a @pieter committed Nov 19, 2008
Showing with 21 additions and 2 deletions.
  1. +6 −0 PBFileChangesTableView.m
  2. +15 −2 PBGitIndexController.m
View
6 PBFileChangesTableView.m
@@ -18,4 +18,10 @@ - (NSMenu *)menuForEvent:(NSEvent *)theEvent
return nil;
}
+
+- (NSDragOperation) draggingSourceOperationMaskForLocal:(BOOL) local
+{
+ return NSDragOperationEvery;
+}
+
@end
View
17 PBGitIndexController.m
@@ -206,9 +206,22 @@ - (BOOL)tableView:(NSTableView *)tv
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;
}

0 comments on commit e76d483

Please sign in to comment.