Skip to content

Commit

Permalink
Merge pull request pieter#8 from tsparber/fix-openfiles
Browse files Browse the repository at this point in the history
Fix Open File and Show in Finder context menu entries
  • Loading branch information
ssp authored Aug 3, 2016
2 parents c1d8f15 + 7e840e9 commit cc714ae
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 52 deletions.
11 changes: 11 additions & 0 deletions Classes/Controllers/PBGitHistoryController.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#import "PBQLTextView.h"
#import "GLFileView.h"
#import "GitXCommitCopier.h"
#import "PBOpenFiles.h"


#define kHistorySelectedDetailIndexKey @"PBHistorySelectedDetailIndex"
Expand Down Expand Up @@ -592,6 +593,16 @@ - (void) checkoutFiles:(id)sender
[repository checkoutFiles:files fromRefish:self.selectedCommits.firstObject];
}

- (void) openFilesAction:(id) sender
{
[PBOpenFiles openFilesAction:sender with:repository.workingDirectoryURL];
}

- (void) showInFinderAction:(id) sender
{
[PBOpenFiles showInFinderAction:sender with:repository.workingDirectoryURL];
}

- (void) diffFilesAction:(id)sender
{
/* TODO: Move that to the document */
Expand Down
15 changes: 13 additions & 2 deletions Classes/Controllers/PBGitIndexController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "PBChangedFile.h"
#import "PBGitRepository.h"
#import "PBGitIndex.h"
#import "PBOpenFiles.h"

#define FileChangesTableViewType @"GitFileChangedType"

Expand Down Expand Up @@ -113,7 +114,7 @@ - (NSMenu *) menuForTable:(NSTableView *)table

NSString *title = [selectedFiles count] == 1 ? @"Open file" : @"Open files";
NSMenuItem *openItem = [[NSMenuItem alloc] initWithTitle:title action:@selector(openFilesAction:) keyEquivalent:@""];
[openItem setTarget:commitController.repository];
[openItem setTarget:self];
[menu addItem:openItem];

// Attempt to ignore
Expand All @@ -126,7 +127,7 @@ - (NSMenu *) menuForTable:(NSTableView *)table

if ([selectedFiles count] == 1) {
NSMenuItem *showInFinderItem = [[NSMenuItem alloc] initWithTitle:@"Show in Finder" action:@selector(showInFinderAction:) keyEquivalent:@""];
[showInFinderItem setTarget:commitController.repository];
[showInFinderItem setTarget:self];
[menu addItem:showInFinderItem];
}

Expand Down Expand Up @@ -217,6 +218,11 @@ - (void) unstageFilesAction:(id) sender
[commitController.index unstageFiles:[sender representedObject]];
}

- (void) openFilesAction:(id) sender
{
[PBOpenFiles openFilesAction:sender with:commitController.repository.workingDirectoryURL];
}

- (void) ignoreFilesAction:(id) sender
{
NSArray *selectedFiles = [sender representedObject];
Expand All @@ -227,6 +233,11 @@ - (void) ignoreFilesAction:(id) sender
[commitController.index refresh];
}

- (void) showInFinderAction:(id) sender
{
[PBOpenFiles showInFinderAction:sender with:commitController.repository.workingDirectoryURL];
}

- (void)discardFilesAction:(id) sender
{
NSArray *selectedFiles = [sender representedObject];
Expand Down
4 changes: 0 additions & 4 deletions Classes/Controllers/PBGitRepositoryDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ extern NSString *PBGitRepositoryDocumentType;
// Scripting Bridge
- (void)findInModeScriptCommand:(NSScriptCommand *)command;

// Responder
- (IBAction)showInFinderAction:(id)sender;
- (IBAction)openFilesAction:(id)sender;

- (IBAction)showCommitView:(id)sender;
- (IBAction)showHistoryView:(id)sender;

Expand Down
46 changes: 0 additions & 46 deletions Classes/Controllers/PBGitRepositoryDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -133,52 +133,6 @@ - (void)showWindows
[super showWindows];
}

#pragma mark -
#pragma mark NSResponder methods

- (NSArray *)selectedURLsFromSender:(id)sender {
NSArray *selectedFiles = [sender representedObject];
if ([selectedFiles count] == 0)
return nil;

NSURL *workingDirectoryURL = self.repository.workingDirectoryURL;
NSMutableArray *URLs = [NSMutableArray array];
for (id file in selectedFiles) {
NSString *path = file;
// Those can be PBChangedFiles sent by PBGitIndexController. Get their path.
if ([file respondsToSelector:@selector(path)]) {
path = [file path];
}

if (![path isKindOfClass:[NSString class]])
continue;
[URLs addObject:[workingDirectoryURL URLByAppendingPathComponent:path]];
}

return URLs;
}

- (IBAction)showInFinderAction:(id)sender {
NSArray *URLs = [self selectedURLsFromSender:sender];
if ([URLs count] == 0)
return;

[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:URLs];
}

- (IBAction)openFilesAction:(id)sender {
NSArray *URLs = [self selectedURLsFromSender:sender];

if ([URLs count] == 0)
return;

[[NSWorkspace sharedWorkspace] openURLs:URLs
withAppBundleIdentifier:nil
options:0
additionalEventParamDescriptor:nil
launchIdentifiers:NULL];
}

#pragma mark -
#pragma mark AppleScript support

Expand Down
16 changes: 16 additions & 0 deletions Classes/Util/PBOpenFiles.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// PBOpenFiles.h
// GitX
//
// Created by Tommy Sparber on 02/08/16.
// Based on code by Etienne
//

#import <Foundation/Foundation.h>

@interface PBOpenFiles : NSObject

+ (void)showInFinderAction:(id)sender with:(NSURL *)workingDirectoryURL;
+ (void)openFilesAction:(id)sender with:(NSURL *)workingDirectoryURL;

@end
55 changes: 55 additions & 0 deletions Classes/Util/PBOpenFiles.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// PBOpenFiles.m
// GitX
//
// Created by Tommy Sparber on 02/08/16.
// Based on code by Etienne
//

#import "PBOpenFiles.h"

@implementation PBOpenFiles

+ (NSArray *)selectedURLsFromSender:(id)sender with:(NSURL *)workingDirectoryURL {
NSArray *selectedFiles = [sender representedObject];
if ([selectedFiles count] == 0)
return nil;

NSMutableArray *URLs = [NSMutableArray array];
for (id file in selectedFiles) {
NSString *path = file;
// Those can be PBChangedFiles sent by PBGitIndexController. Get their path.
if ([file respondsToSelector:@selector(path)]) {
path = [file path];
}

if (![path isKindOfClass:[NSString class]])
continue;
[URLs addObject:[workingDirectoryURL URLByAppendingPathComponent:path]];
}

return URLs;
}

+ (void)showInFinderAction:(id)sender with:(NSURL *)workingDirectoryURL {
NSArray *URLs = [self selectedURLsFromSender:sender with:workingDirectoryURL];
if ([URLs count] == 0)
return;

[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:URLs];
}

+ (void)openFilesAction:(id)sender with:(NSURL *)workingDirectoryURL {
NSArray *URLs = [self selectedURLsFromSender:sender with:workingDirectoryURL];

if ([URLs count] == 0)
return;

[[NSWorkspace sharedWorkspace] openURLs:URLs
withAppBundleIdentifier:nil
options:0
additionalEventParamDescriptor:nil
launchIdentifiers:NULL];
}

@end
6 changes: 6 additions & 0 deletions GitX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
4D3FB3E7198AEAAF000B4A58 /* PBGitRepositoryDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D3FB3E6198AEAAF000B4A58 /* PBGitRepositoryDocument.m */; };
551BF176112F3F4B00265053 /* gitx_askpasswd in Resources */ = {isa = PBXBuildFile; fileRef = 551BF111112F371800265053 /* gitx_askpasswd */; };
643952771603EF9B00BB7AFF /* PBGitSVSubmoduleItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 643952761603EF9B00BB7AFF /* PBGitSVSubmoduleItem.m */; };
658CD8671D50F93500F5F019 /* PBOpenFiles.m in Sources */ = {isa = PBXBuildFile; fileRef = 658CD8661D50F93500F5F019 /* PBOpenFiles.m */; };
6C25810B1C2720E60080A89A /* GitXCommitCopier.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C25810A1C2720E60080A89A /* GitXCommitCopier.m */; };
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
911112370E5A097800BF76B4 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 911112360E5A097800BF76B4 /* Security.framework */; };
Expand Down Expand Up @@ -580,6 +581,8 @@
551BF111112F371800265053 /* gitx_askpasswd */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = gitx_askpasswd; sourceTree = BUILT_PRODUCTS_DIR; };
643952751603EF9B00BB7AFF /* PBGitSVSubmoduleItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitSVSubmoduleItem.h; sourceTree = "<group>"; };
643952761603EF9B00BB7AFF /* PBGitSVSubmoduleItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitSVSubmoduleItem.m; sourceTree = "<group>"; };
658CD8651D50F93500F5F019 /* PBOpenFiles.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PBOpenFiles.h; path = Classes/Util/PBOpenFiles.h; sourceTree = SOURCE_ROOT; };
658CD8661D50F93500F5F019 /* PBOpenFiles.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PBOpenFiles.m; path = Classes/Util/PBOpenFiles.m; sourceTree = SOURCE_ROOT; };
6C2581091C2720E60080A89A /* GitXCommitCopier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GitXCommitCopier.h; sourceTree = "<group>"; };
6C25810A1C2720E60080A89A /* GitXCommitCopier.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GitXCommitCopier.m; sourceTree = "<group>"; };
77C82804067257F0000B614F /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
Expand Down Expand Up @@ -986,6 +989,8 @@
4A5D76B014A9A9CC00DF6C68 /* PBEasyFS.m */,
4A5D76B114A9A9CC00DF6C68 /* PBEasyPipe.h */,
4A5D76B214A9A9CC00DF6C68 /* PBEasyPipe.m */,
658CD8651D50F93500F5F019 /* PBOpenFiles.h */,
658CD8661D50F93500F5F019 /* PBOpenFiles.m */,
4AB71FF614B7EDD400F1DFFC /* RJModalRepoSheet.h */,
4AB71FF714B7EDD400F1DFFC /* RJModalRepoSheet.m */,
6C2581091C2720E60080A89A /* GitXCommitCopier.h */,
Expand Down Expand Up @@ -1427,6 +1432,7 @@
4A5D770A14A9A9CC00DF6C68 /* PBGitSVStageItem.m in Sources */,
4A5D770B14A9A9CC00DF6C68 /* PBGitSVTagItem.m in Sources */,
4A5D770C14A9A9CC00DF6C68 /* PBGitTree.m in Sources */,
658CD8671D50F93500F5F019 /* PBOpenFiles.m in Sources */,
4A5D770D14A9A9CC00DF6C68 /* PBGitXErrors.m in Sources */,
4A5D770E14A9A9CC00DF6C68 /* PBGitXProtocol.m in Sources */,
4A5D771114A9A9CC00DF6C68 /* GitXRelativeDateFormatter.m in Sources */,
Expand Down

0 comments on commit cc714ae

Please sign in to comment.