From 7427cbe05d1d96490c18d642d5ea613d0f8b4caf Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Tue, 16 Jun 2009 19:40:18 +0100 Subject: [PATCH] HistoryController: Add "Open Files" menu item --- PBGitHistoryController.h | 1 + PBGitHistoryController.m | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/PBGitHistoryController.h b/PBGitHistoryController.h index f7298c4..6c99a20 100644 --- a/PBGitHistoryController.h +++ b/PBGitHistoryController.h @@ -47,6 +47,7 @@ - (NSArray *)menuItemsForPaths:(NSArray *)paths; - (void)showCommitsFromTree:(id)sender; - (void)showInFinderAction:(id)sender; +- (void)openFilesAction:(id)sender; - (void) copyCommitInfo; diff --git a/PBGitHistoryController.m b/PBGitHistoryController.m index a02c041..c4d2679 100644 --- a/PBGitHistoryController.m +++ b/PBGitHistoryController.m @@ -246,6 +246,19 @@ } +- (void)openFilesAction:(id)sender +{ + NSString *workingDirectory = [[repository workingDirectory] stringByAppendingString:@"/"]; + NSString *path; + NSWorkspace *ws = [NSWorkspace sharedWorkspace]; + + for (NSString *filePath in [sender representedObject]) { + path = [workingDirectory stringByAppendingPathComponent:filePath]; + [ws openFile:path]; + } +} + + - (NSMenu *)contextMenuForTreeView { NSArray *filePaths = [[treeController selectedObjects] valueForKey:@"fullPath"]; @@ -259,14 +272,17 @@ - (NSArray *)menuItemsForPaths:(NSArray *)paths { BOOL multiple = [paths count] != 1; - NSMenuItem *finderItem = [[NSMenuItem alloc] initWithTitle:multiple? @"Show items in Finder" : @"Show item in Finder" - action:@selector(showInFinderAction:) - keyEquivalent:@""]; NSMenuItem *historyItem = [[NSMenuItem alloc] initWithTitle:multiple? @"Show history of files" : @"Show history of file" action:@selector(showCommitsFromTree:) keyEquivalent:@""]; + NSMenuItem *finderItem = [[NSMenuItem alloc] initWithTitle:@"Show in Finder" + action:@selector(showInFinderAction:) + keyEquivalent:@""]; + NSMenuItem *openFilesItem = [[NSMenuItem alloc] initWithTitle:multiple? @"Open Files" : @"Open File" + action:@selector(openFilesAction:) + keyEquivalent:@""]; - NSArray *menuItems = [NSArray arrayWithObjects:historyItem, finderItem, nil]; + NSArray *menuItems = [NSArray arrayWithObjects:historyItem, finderItem, openFilesItem, nil]; for (NSMenuItem *item in menuItems) { [item setTarget:self]; [item setRepresentedObject:paths];