Skip to content

Commit 7e840e9

Browse files
committed
Fix Open File and Show in Finder context menu entries
The commit 9335f0e breaks the context menu entries (“Show in Finder” and “Open Files”) in the commit controller, as the code is moved from PBGitRepository to PBGitRepositoryDocument. The fix creates a new class PBOpenFiles that is used in PBGitHistoryController and PBGitIndexController.
1 parent c1d8f15 commit 7e840e9

File tree

7 files changed

+101
-52
lines changed

7 files changed

+101
-52
lines changed

Classes/Controllers/PBGitHistoryController.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#import "PBQLTextView.h"
3333
#import "GLFileView.h"
3434
#import "GitXCommitCopier.h"
35+
#import "PBOpenFiles.h"
3536

3637

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

596+
- (void) openFilesAction:(id) sender
597+
{
598+
[PBOpenFiles openFilesAction:sender with:repository.workingDirectoryURL];
599+
}
600+
601+
- (void) showInFinderAction:(id) sender
602+
{
603+
[PBOpenFiles showInFinderAction:sender with:repository.workingDirectoryURL];
604+
}
605+
595606
- (void) diffFilesAction:(id)sender
596607
{
597608
/* TODO: Move that to the document */

Classes/Controllers/PBGitIndexController.m

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#import "PBChangedFile.h"
1111
#import "PBGitRepository.h"
1212
#import "PBGitIndex.h"
13+
#import "PBOpenFiles.h"
1314

1415
#define FileChangesTableViewType @"GitFileChangedType"
1516

@@ -113,7 +114,7 @@ - (NSMenu *) menuForTable:(NSTableView *)table
113114

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

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

127128
if ([selectedFiles count] == 1) {
128129
NSMenuItem *showInFinderItem = [[NSMenuItem alloc] initWithTitle:@"Show in Finder" action:@selector(showInFinderAction:) keyEquivalent:@""];
129-
[showInFinderItem setTarget:commitController.repository];
130+
[showInFinderItem setTarget:self];
130131
[menu addItem:showInFinderItem];
131132
}
132133

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

221+
- (void) openFilesAction:(id) sender
222+
{
223+
[PBOpenFiles openFilesAction:sender with:commitController.repository.workingDirectoryURL];
224+
}
225+
220226
- (void) ignoreFilesAction:(id) sender
221227
{
222228
NSArray *selectedFiles = [sender representedObject];
@@ -227,6 +233,11 @@ - (void) ignoreFilesAction:(id) sender
227233
[commitController.index refresh];
228234
}
229235

236+
- (void) showInFinderAction:(id) sender
237+
{
238+
[PBOpenFiles showInFinderAction:sender with:commitController.repository.workingDirectoryURL];
239+
}
240+
230241
- (void)discardFilesAction:(id) sender
231242
{
232243
NSArray *selectedFiles = [sender representedObject];

Classes/Controllers/PBGitRepositoryDocument.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ extern NSString *PBGitRepositoryDocumentType;
2222
// Scripting Bridge
2323
- (void)findInModeScriptCommand:(NSScriptCommand *)command;
2424

25-
// Responder
26-
- (IBAction)showInFinderAction:(id)sender;
27-
- (IBAction)openFilesAction:(id)sender;
28-
2925
- (IBAction)showCommitView:(id)sender;
3026
- (IBAction)showHistoryView:(id)sender;
3127

Classes/Controllers/PBGitRepositoryDocument.m

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -133,52 +133,6 @@ - (void)showWindows
133133
[super showWindows];
134134
}
135135

136-
#pragma mark -
137-
#pragma mark NSResponder methods
138-
139-
- (NSArray *)selectedURLsFromSender:(id)sender {
140-
NSArray *selectedFiles = [sender representedObject];
141-
if ([selectedFiles count] == 0)
142-
return nil;
143-
144-
NSURL *workingDirectoryURL = self.repository.workingDirectoryURL;
145-
NSMutableArray *URLs = [NSMutableArray array];
146-
for (id file in selectedFiles) {
147-
NSString *path = file;
148-
// Those can be PBChangedFiles sent by PBGitIndexController. Get their path.
149-
if ([file respondsToSelector:@selector(path)]) {
150-
path = [file path];
151-
}
152-
153-
if (![path isKindOfClass:[NSString class]])
154-
continue;
155-
[URLs addObject:[workingDirectoryURL URLByAppendingPathComponent:path]];
156-
}
157-
158-
return URLs;
159-
}
160-
161-
- (IBAction)showInFinderAction:(id)sender {
162-
NSArray *URLs = [self selectedURLsFromSender:sender];
163-
if ([URLs count] == 0)
164-
return;
165-
166-
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:URLs];
167-
}
168-
169-
- (IBAction)openFilesAction:(id)sender {
170-
NSArray *URLs = [self selectedURLsFromSender:sender];
171-
172-
if ([URLs count] == 0)
173-
return;
174-
175-
[[NSWorkspace sharedWorkspace] openURLs:URLs
176-
withAppBundleIdentifier:nil
177-
options:0
178-
additionalEventParamDescriptor:nil
179-
launchIdentifiers:NULL];
180-
}
181-
182136
#pragma mark -
183137
#pragma mark AppleScript support
184138

Classes/Util/PBOpenFiles.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// PBOpenFiles.h
3+
// GitX
4+
//
5+
// Created by Tommy Sparber on 02/08/16.
6+
// Based on code by Etienne
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@interface PBOpenFiles : NSObject
12+
13+
+ (void)showInFinderAction:(id)sender with:(NSURL *)workingDirectoryURL;
14+
+ (void)openFilesAction:(id)sender with:(NSURL *)workingDirectoryURL;
15+
16+
@end

Classes/Util/PBOpenFiles.m

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//
2+
// PBOpenFiles.m
3+
// GitX
4+
//
5+
// Created by Tommy Sparber on 02/08/16.
6+
// Based on code by Etienne
7+
//
8+
9+
#import "PBOpenFiles.h"
10+
11+
@implementation PBOpenFiles
12+
13+
+ (NSArray *)selectedURLsFromSender:(id)sender with:(NSURL *)workingDirectoryURL {
14+
NSArray *selectedFiles = [sender representedObject];
15+
if ([selectedFiles count] == 0)
16+
return nil;
17+
18+
NSMutableArray *URLs = [NSMutableArray array];
19+
for (id file in selectedFiles) {
20+
NSString *path = file;
21+
// Those can be PBChangedFiles sent by PBGitIndexController. Get their path.
22+
if ([file respondsToSelector:@selector(path)]) {
23+
path = [file path];
24+
}
25+
26+
if (![path isKindOfClass:[NSString class]])
27+
continue;
28+
[URLs addObject:[workingDirectoryURL URLByAppendingPathComponent:path]];
29+
}
30+
31+
return URLs;
32+
}
33+
34+
+ (void)showInFinderAction:(id)sender with:(NSURL *)workingDirectoryURL {
35+
NSArray *URLs = [self selectedURLsFromSender:sender with:workingDirectoryURL];
36+
if ([URLs count] == 0)
37+
return;
38+
39+
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:URLs];
40+
}
41+
42+
+ (void)openFilesAction:(id)sender with:(NSURL *)workingDirectoryURL {
43+
NSArray *URLs = [self selectedURLsFromSender:sender with:workingDirectoryURL];
44+
45+
if ([URLs count] == 0)
46+
return;
47+
48+
[[NSWorkspace sharedWorkspace] openURLs:URLs
49+
withAppBundleIdentifier:nil
50+
options:0
51+
additionalEventParamDescriptor:nil
52+
launchIdentifiers:NULL];
53+
}
54+
55+
@end

GitX.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
4D3FB3E7198AEAAF000B4A58 /* PBGitRepositoryDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D3FB3E6198AEAAF000B4A58 /* PBGitRepositoryDocument.m */; };
156156
551BF176112F3F4B00265053 /* gitx_askpasswd in Resources */ = {isa = PBXBuildFile; fileRef = 551BF111112F371800265053 /* gitx_askpasswd */; };
157157
643952771603EF9B00BB7AFF /* PBGitSVSubmoduleItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 643952761603EF9B00BB7AFF /* PBGitSVSubmoduleItem.m */; };
158+
658CD8671D50F93500F5F019 /* PBOpenFiles.m in Sources */ = {isa = PBXBuildFile; fileRef = 658CD8661D50F93500F5F019 /* PBOpenFiles.m */; };
158159
6C25810B1C2720E60080A89A /* GitXCommitCopier.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C25810A1C2720E60080A89A /* GitXCommitCopier.m */; };
159160
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
160161
911112370E5A097800BF76B4 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 911112360E5A097800BF76B4 /* Security.framework */; };
@@ -580,6 +581,8 @@
580581
551BF111112F371800265053 /* gitx_askpasswd */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = gitx_askpasswd; sourceTree = BUILT_PRODUCTS_DIR; };
581582
643952751603EF9B00BB7AFF /* PBGitSVSubmoduleItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitSVSubmoduleItem.h; sourceTree = "<group>"; };
582583
643952761603EF9B00BB7AFF /* PBGitSVSubmoduleItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitSVSubmoduleItem.m; sourceTree = "<group>"; };
584+
658CD8651D50F93500F5F019 /* PBOpenFiles.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PBOpenFiles.h; path = Classes/Util/PBOpenFiles.h; sourceTree = SOURCE_ROOT; };
585+
658CD8661D50F93500F5F019 /* PBOpenFiles.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PBOpenFiles.m; path = Classes/Util/PBOpenFiles.m; sourceTree = SOURCE_ROOT; };
583586
6C2581091C2720E60080A89A /* GitXCommitCopier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GitXCommitCopier.h; sourceTree = "<group>"; };
584587
6C25810A1C2720E60080A89A /* GitXCommitCopier.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GitXCommitCopier.m; sourceTree = "<group>"; };
585588
77C82804067257F0000B614F /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
@@ -986,6 +989,8 @@
986989
4A5D76B014A9A9CC00DF6C68 /* PBEasyFS.m */,
987990
4A5D76B114A9A9CC00DF6C68 /* PBEasyPipe.h */,
988991
4A5D76B214A9A9CC00DF6C68 /* PBEasyPipe.m */,
992+
658CD8651D50F93500F5F019 /* PBOpenFiles.h */,
993+
658CD8661D50F93500F5F019 /* PBOpenFiles.m */,
989994
4AB71FF614B7EDD400F1DFFC /* RJModalRepoSheet.h */,
990995
4AB71FF714B7EDD400F1DFFC /* RJModalRepoSheet.m */,
991996
6C2581091C2720E60080A89A /* GitXCommitCopier.h */,
@@ -1427,6 +1432,7 @@
14271432
4A5D770A14A9A9CC00DF6C68 /* PBGitSVStageItem.m in Sources */,
14281433
4A5D770B14A9A9CC00DF6C68 /* PBGitSVTagItem.m in Sources */,
14291434
4A5D770C14A9A9CC00DF6C68 /* PBGitTree.m in Sources */,
1435+
658CD8671D50F93500F5F019 /* PBOpenFiles.m in Sources */,
14301436
4A5D770D14A9A9CC00DF6C68 /* PBGitXErrors.m in Sources */,
14311437
4A5D770E14A9A9CC00DF6C68 /* PBGitXProtocol.m in Sources */,
14321438
4A5D771114A9A9CC00DF6C68 /* GitXRelativeDateFormatter.m in Sources */,

0 commit comments

Comments
 (0)