Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ticket #142: Add Show in Finder to Unstaged and Staged table views.

  • Loading branch information...
commit 3b6c2a304829a60a7421254a3e2f7be202621abc 1 parent 4e4ffcc
@charlesorourke charlesorourke authored pieter committed
Showing with 23 additions and 1 deletion.
  1. +5 −1 PBFileChangesTableView.m
  2. +18 −0 PBGitIndexController.m
View
6 PBFileChangesTableView.m
@@ -14,8 +14,12 @@ @implementation PBFileChangesTableView
#pragma mark NSTableView overrides
- (NSMenu *)menuForEvent:(NSEvent *)theEvent
{
- if ([self delegate])
+ if ([self delegate]) {
+ NSPoint eventLocation = [self convertPoint: [theEvent locationInWindow] fromView: nil];
+ NSInteger rowIndex = [self rowAtPoint:eventLocation];
+ [self selectRowIndexes:[NSIndexSet indexSetWithIndex:rowIndex] byExtendingSelection:TRUE];
return [[self delegate] menuForTable: self];
+ }
return nil;
}
View
18 PBGitIndexController.m
@@ -237,6 +237,13 @@ - (NSMenu *) menuForTable:(NSTableView *)table
[menu addItem:ignoreItem];
}
+ if ([selectedFiles count] == 1) {
+ NSMenuItem *showInFinderItem = [[NSMenuItem alloc] initWithTitle:@"Show in Finder" action:@selector(showInFinderAction:) keyEquivalent:@""];
+ [showInFinderItem setTarget:self];
+ [showInFinderItem setRepresentedObject:selectedFiles];
+ [menu addItem:showInFinderItem];
+ }
+
for (PBChangedFile *file in selectedFiles)
if (!file.hasUnstagedChanges)
return menu;
@@ -299,6 +306,17 @@ - (void) forceRevertFilesAction:(id) sender
[self forceRevertChangesForFiles:selectedFiles];
}
+- (void) showInFinderAction:(id) sender
+{
+ NSArray *selectedFiles = [sender representedObject];
+ if ([selectedFiles count] == 0)
+ return;
+ NSString *workingDirectory = [[commitController.repository workingDirectory] stringByAppendingString:@"/"];
+ NSString *path = [workingDirectory stringByAppendingPathComponent:[[selectedFiles objectAtIndex:0] path]];
+ NSWorkspace *ws = [NSWorkspace sharedWorkspace];
+ [ws selectFile: path inFileViewerRootedAtPath:nil];
+}
+
# pragma mark TableView icon delegate
- (void)tableView:(NSTableView*)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn*)tableColumn row:(NSInteger)rowIndex
Please sign in to comment.
Something went wrong with that request. Please try again.