From 8896dc993c73c704d54b44ecbe2d025d0fc8ec16 Mon Sep 17 00:00:00 2001 From: German Laullon Date: Fri, 4 Mar 2011 13:38:55 -0800 Subject: [PATCH] basic FileMerge support --- GLFileView.m | 1 + PBGitXProtocol.m | 51 ++++++++++++++++++++++------------ PBWebController.m | 5 ++++ PBWebHistoryController.h | 1 + PBWebHistoryController.m | 7 +++++ html/views/history/history.css | 5 ++++ html/views/history/history.js | 6 ++++ 7 files changed, 58 insertions(+), 18 deletions(-) diff --git a/GLFileView.m b/GLFileView.m index 4999df4..27e8ac1 100644 --- a/GLFileView.m +++ b/GLFileView.m @@ -324,6 +324,7 @@ inDiff=TRUE; NSString *fileName=[self getFileName:line]; [res appendString:[NSString stringWithFormat:@"
",fileName]]; + [res appendString:[NSString stringWithFormat:@"",fileName]]; [res appendString:[NSString stringWithFormat:@"

%@

",line]]; }else if(inDiff){ [res appendString:[NSString stringWithFormat:@"

%@

",line]]; diff --git a/PBGitXProtocol.m b/PBGitXProtocol.m index 7d1e1bc..5fe8194 100644 --- a/PBGitXProtocol.m +++ b/PBGitXProtocol.m @@ -31,25 +31,40 @@ return; } - NSString *path=[[url path] substringFromIndex:1]; - NSString *v=@""; - if ([[path substringToIndex:5] isEqualToString:@"prev/"]) { - path=[path substringFromIndex:5]; - v=@"^"; + if ([[url host] isEqualToString:@"app"]) { + NSString *app=[[url path] substringFromIndex:1]; + NSString *appPath=[[NSWorkspace sharedWorkspace] fullPathForApplication:app]; + NSLog(@"app=%@ appPath=%@",app,appPath); + if(appPath){ + NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:appPath]; + NSLog(@"icon=%@",icon); + [[self client] URLProtocol:self didLoadData:[icon TIFFRepresentation]]; + [[self client] URLProtocolDidFinishLoading:self]; + }else{ + [[self client] URLProtocol:self didFailWithError:[NSError errorWithDomain:@"gitx" code:404 userInfo:nil]]; + } + }else { + + NSString *path=[[url path] substringFromIndex:1]; + NSString *v=@""; + if ([[path substringToIndex:5] isEqualToString:@"prev/"]) { + path=[path substringFromIndex:5]; + v=@"^"; + } + NSString *specifier = [NSString stringWithFormat:@"%@%@:%@", [url host], v,path]; + handle = [repo handleInWorkDirForArguments:[NSArray arrayWithObjects:@"cat-file", @"blob", specifier, nil]]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishFileLoad:) name:NSFileHandleReadToEndOfFileCompletionNotification object:handle]; + [handle readToEndOfFileInBackgroundAndNotify]; + + NSURLResponse *response = [[NSURLResponse alloc] initWithURL:[[self request] URL] + MIMEType:nil + expectedContentLength:-1 + textEncodingName:nil]; + + [[self client] URLProtocol:self + didReceiveResponse:response + cacheStoragePolicy:NSURLCacheStorageNotAllowed]; } - NSString *specifier = [NSString stringWithFormat:@"%@%@:%@", [url host], v,path]; - handle = [repo handleInWorkDirForArguments:[NSArray arrayWithObjects:@"cat-file", @"blob", specifier, nil]]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishFileLoad:) name:NSFileHandleReadToEndOfFileCompletionNotification object:handle]; - [handle readToEndOfFileInBackgroundAndNotify]; - - NSURLResponse *response = [[NSURLResponse alloc] initWithURL:[[self request] URL] - MIMEType:nil - expectedContentLength:-1 - textEncodingName:nil]; - - [[self client] URLProtocol:self - didReceiveResponse:response - cacheStoragePolicy:NSURLCacheStorageNotAllowed]; } - (void) didFinishFileLoad:(NSNotification *)notification diff --git a/PBWebController.m b/PBWebController.m index ab890fb..7c18db8 100644 --- a/PBWebController.m +++ b/PBWebController.m @@ -76,6 +76,11 @@ NSLog(@"Error from webkit: %@", dictionary); } +- (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame +{ + NSLog(@"Message from webkit: %@", message); +} + - (NSURLRequest *)webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request diff --git a/PBWebHistoryController.h b/PBWebHistoryController.h index 0d887be..7f4fc4a 100644 --- a/PBWebHistoryController.h +++ b/PBWebHistoryController.h @@ -29,6 +29,7 @@ - (NSString *)parseHeader:(NSString *)txt withRefs:(NSString *)badges; - (NSMutableDictionary *)parseStats:(NSString *)txt; - (NSString *) someMethodThatReturnsSomeHashForSomeString:(NSString*)concat; +- (void) openFileMerge:(NSString*)file sha:(NSString *)sha; @property (readonly) NSString* diff; @end diff --git a/PBWebHistoryController.m b/PBWebHistoryController.m index d38a180..75d69ce 100644 --- a/PBWebHistoryController.m +++ b/PBWebHistoryController.m @@ -224,6 +224,13 @@ [historyController selectCommit:[PBGitSHA shaWithString:sha]]; } +- (void) openFileMerge:(NSString*)file sha:(NSString *)sha +{ + NSArray *args=[NSArray arrayWithObjects:@"difftool",@"--no-prompt",@"--tool=opendiff",[NSString stringWithFormat:@"%@^",sha],sha,file,nil]; + [historyController.repository handleForArguments:args]; +} + + - (void) sendKey: (NSString*) key { id script = [view windowScriptObject]; diff --git a/html/views/history/history.css b/html/views/history/history.css index 6ac1cda..8c073d4 100644 --- a/html/views/history/history.css +++ b/html/views/history/history.css @@ -317,4 +317,9 @@ a.showdiff { -webkit-box-shadow: 5px 5px 5px #ccc; width: 98%; margin: auto auto 20px 1%; +} + +.filemerge { + float: right; + text-align: center; } \ No newline at end of file diff --git a/html/views/history/history.js b/html/views/history/history.js index e37baee..6a3b3e1 100644 --- a/html/views/history/history.js +++ b/html/views/history/history.js @@ -2,6 +2,12 @@ var selectCommit = function(a) { Controller.selectCommit_(a); } +var openFileMerge = function(file,sha) { + alert(file); + alert(sha); + Controller.openFileMerge_sha_(file,sha); +} + var showImage = function(element, filename) { element.outerHTML = '';