16
16
#import " PBAddRemoteSheet.h"
17
17
#import " PBGitSidebarController.h"
18
18
#import " PBGitGradientBarView.h"
19
+ #import " PBDiffWindowController.h"
19
20
#define QLPreviewPanel NSClassFromString (@" QLPreviewPanel" )
20
21
21
22
@@ -294,6 +295,10 @@ - (void) checkoutFiles:(id)sender
294
295
[repository checkoutFiles: files fromRefish: realCommit];
295
296
}
296
297
298
+ - (void ) diffFilesAction : (id )sender
299
+ {
300
+ [PBDiffWindowController showDiffWindowWithFiles: [sender representedObject ] fromCommit: realCommit diffCommit: nil ];
301
+ }
297
302
298
303
- (NSMenu *)contextMenuForTreeView
299
304
{
@@ -315,6 +320,15 @@ - (NSArray *)menuItemsForPaths:(NSArray *)paths
315
320
NSMenuItem *historyItem = [[NSMenuItem alloc ] initWithTitle: multiple? @" Show history of files" : @" Show history of file"
316
321
action: @selector (showCommitsFromTree: )
317
322
keyEquivalent: @" " ];
323
+
324
+ PBGitRef *headRef = [[repository headRef ] ref ];
325
+ NSString *headRefName = [headRef shortName ];
326
+ NSString *diffTitle = [NSString stringWithFormat: @" Diff %@ with %@ " , multiple ? @" files" : @" file" , headRefName];
327
+ BOOL isHead = [[realCommit realSha ] isEqualToString: [repository headSHA ]];
328
+ NSMenuItem *diffItem = [[NSMenuItem alloc ] initWithTitle: diffTitle
329
+ action: isHead ? nil : @selector (diffFilesAction: )
330
+ keyEquivalent: @" " ];
331
+
318
332
NSMenuItem *checkoutItem = [[NSMenuItem alloc ] initWithTitle: multiple ? @" Checkout files" : @" Checkout file"
319
333
action: @selector (checkoutFiles: )
320
334
keyEquivalent: @" " ];
@@ -325,7 +339,7 @@ - (NSArray *)menuItemsForPaths:(NSArray *)paths
325
339
action: @selector (openFilesAction: )
326
340
keyEquivalent: @" " ];
327
341
328
- NSArray *menuItems = [NSArray arrayWithObjects: historyItem, checkoutItem, finderItem, openFilesItem, nil ];
342
+ NSArray *menuItems = [NSArray arrayWithObjects: historyItem, diffItem, checkoutItem, finderItem, openFilesItem, nil ];
329
343
for (NSMenuItem *item in menuItems) {
330
344
[item setTarget: self ];
331
345
[item setRepresentedObject: filePaths];
0 commit comments