Skip to content

Commit 8896dc9

Browse files
committed
basic FileMerge support
1 parent a20e570 commit 8896dc9

File tree

7 files changed

+58
-18
lines changed

7 files changed

+58
-18
lines changed

GLFileView.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ + (NSString *)parseDiff:(NSString *)txt
324324
inDiff=TRUE;
325325
NSString *fileName=[self getFileName:line];
326326
[res appendString:[NSString stringWithFormat:@"<table id='%@' class='diff'><thead><tr><td colspan='3'>",fileName]];
327+
[res appendString:[NSString stringWithFormat:@"<div class='filemerge'><a href='' onclick='openFileMerge(\"%@\",\"{SHA}\"); return false;'><img src='GitX://app:/filemerge' width='32' height='32'/><br/>open in<br/>FileMerge</a></div>",fileName]];
327328
[res appendString:[NSString stringWithFormat:@"<p>%@</p>",line]];
328329
}else if(inDiff){
329330
[res appendString:[NSString stringWithFormat:@"<p>%@</p>",line]];

PBGitXProtocol.m

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,40 @@ -(void)startLoading
3131
return;
3232
}
3333

34-
NSString *path=[[url path] substringFromIndex:1];
35-
NSString *v=@"";
36-
if ([[path substringToIndex:5] isEqualToString:@"prev/"]) {
37-
path=[path substringFromIndex:5];
38-
v=@"^";
34+
if ([[url host] isEqualToString:@"app"]) {
35+
NSString *app=[[url path] substringFromIndex:1];
36+
NSString *appPath=[[NSWorkspace sharedWorkspace] fullPathForApplication:app];
37+
NSLog(@"app=%@ appPath=%@",app,appPath);
38+
if(appPath){
39+
NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:appPath];
40+
NSLog(@"icon=%@",icon);
41+
[[self client] URLProtocol:self didLoadData:[icon TIFFRepresentation]];
42+
[[self client] URLProtocolDidFinishLoading:self];
43+
}else{
44+
[[self client] URLProtocol:self didFailWithError:[NSError errorWithDomain:@"gitx" code:404 userInfo:nil]];
45+
}
46+
}else {
47+
48+
NSString *path=[[url path] substringFromIndex:1];
49+
NSString *v=@"";
50+
if ([[path substringToIndex:5] isEqualToString:@"prev/"]) {
51+
path=[path substringFromIndex:5];
52+
v=@"^";
53+
}
54+
NSString *specifier = [NSString stringWithFormat:@"%@%@:%@", [url host], v,path];
55+
handle = [repo handleInWorkDirForArguments:[NSArray arrayWithObjects:@"cat-file", @"blob", specifier, nil]];
56+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishFileLoad:) name:NSFileHandleReadToEndOfFileCompletionNotification object:handle];
57+
[handle readToEndOfFileInBackgroundAndNotify];
58+
59+
NSURLResponse *response = [[NSURLResponse alloc] initWithURL:[[self request] URL]
60+
MIMEType:nil
61+
expectedContentLength:-1
62+
textEncodingName:nil];
63+
64+
[[self client] URLProtocol:self
65+
didReceiveResponse:response
66+
cacheStoragePolicy:NSURLCacheStorageNotAllowed];
3967
}
40-
NSString *specifier = [NSString stringWithFormat:@"%@%@:%@", [url host], v,path];
41-
handle = [repo handleInWorkDirForArguments:[NSArray arrayWithObjects:@"cat-file", @"blob", specifier, nil]];
42-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishFileLoad:) name:NSFileHandleReadToEndOfFileCompletionNotification object:handle];
43-
[handle readToEndOfFileInBackgroundAndNotify];
44-
45-
NSURLResponse *response = [[NSURLResponse alloc] initWithURL:[[self request] URL]
46-
MIMEType:nil
47-
expectedContentLength:-1
48-
textEncodingName:nil];
49-
50-
[[self client] URLProtocol:self
51-
didReceiveResponse:response
52-
cacheStoragePolicy:NSURLCacheStorageNotAllowed];
5368
}
5469

5570
- (void) didFinishFileLoad:(NSNotification *)notification

PBWebController.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ - (void)webView:(WebView *)webView addMessageToConsole:(NSDictionary *)dictionar
7676
NSLog(@"Error from webkit: %@", dictionary);
7777
}
7878

79+
- (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame
80+
{
81+
NSLog(@"Message from webkit: %@", message);
82+
}
83+
7984
- (NSURLRequest *)webView:(WebView *)sender
8085
resource:(id)identifier
8186
willSendRequest:(NSURLRequest *)request

PBWebHistoryController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
- (NSString *)parseHeader:(NSString *)txt withRefs:(NSString *)badges;
3030
- (NSMutableDictionary *)parseStats:(NSString *)txt;
3131
- (NSString *) someMethodThatReturnsSomeHashForSomeString:(NSString*)concat;
32+
- (void) openFileMerge:(NSString*)file sha:(NSString *)sha;
3233

3334
@property (readonly) NSString* diff;
3435
@end

PBWebHistoryController.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,13 @@ - (void)selectCommit:(NSString *)sha
224224
[historyController selectCommit:[PBGitSHA shaWithString:sha]];
225225
}
226226

227+
- (void) openFileMerge:(NSString*)file sha:(NSString *)sha
228+
{
229+
NSArray *args=[NSArray arrayWithObjects:@"difftool",@"--no-prompt",@"--tool=opendiff",[NSString stringWithFormat:@"%@^",sha],sha,file,nil];
230+
[historyController.repository handleForArguments:args];
231+
}
232+
233+
227234
- (void) sendKey: (NSString*) key
228235
{
229236
id script = [view windowScriptObject];

html/views/history/history.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,9 @@ a.showdiff {
317317
-webkit-box-shadow: 5px 5px 5px #ccc;
318318
width: 98%;
319319
margin: auto auto 20px 1%;
320+
}
321+
322+
.filemerge {
323+
float: right;
324+
text-align: center;
320325
}

html/views/history/history.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ var selectCommit = function(a) {
22
Controller.selectCommit_(a);
33
}
44

5+
var openFileMerge = function(file,sha) {
6+
alert(file);
7+
alert(sha);
8+
Controller.openFileMerge_sha_(file,sha);
9+
}
10+
511
var showImage = function(element, filename)
612
{
713
element.outerHTML = '<img src="GitX://' + commit.sha + '/' + filename + '">';

0 commit comments

Comments
 (0)