Skip to content

Commit bee812f

Browse files
committed
only show images as images ;)
1 parent 7007996 commit bee812f

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

GLFileView.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
+(BOOL)isStartDiff:(NSString *)line;
3737
+(BOOL)isStartBlock:(NSString *)line;
3838

39+
+(NSArray *)getFilesNames:(NSString *)line;
40+
+(BOOL)isBinaryFile:(NSString *)line;
41+
+(NSString*)mimeTypeForFileName:(NSString*)file;
42+
+(BOOL)isImage:(NSString*)file;
43+
3944
@property(retain) NSMutableArray *groups;
4045
@property(retain) NSString *logFormat;
4146

GLFileView.m

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ - (MGScopeBarGroupSelectionMode)scopeBar:(MGScopeBar *)theScopeBar selectionMode
181181

182182
- (void)scopeBar:(MGScopeBar *)theScopeBar selectedStateChanged:(BOOL)selected forItem:(NSString *)identifier inGroup:(int)groupNumber
183183
{
184-
NSLog(@"startFile=%@ identifier=%@ groupNumber=%d",startFile,identifier,groupNumber);
185184
if((groupNumber==0) && (startFile!=identifier)){
186185
NSString *path = [NSString stringWithFormat:@"html/views/%@", identifier];
187186
NSString *html = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:path];
@@ -330,17 +329,19 @@ + (NSString *)parseDiff:(NSString *)txt
330329
}else if(inDiff){
331330
[res appendString:[NSString stringWithFormat:@"<p>%@</p>",line]];
332331
if([self isBinaryFile:line]){
333-
NSLog(@"line='%@'",line);
334332
[res appendString:@"</td></tr></thead><tbody>"];
335333
NSArray *files=[self getFilesNames:line];
336-
NSLog(@"files='%@'",files);
337334
if(![[files objectAtIndex:0] isAbsolutePath]){
338335
[res appendString:[NSString stringWithFormat:@"<tr><td colspan='3'>%@</td></tr>",[files objectAtIndex:0]]];
339-
[res appendString:[NSString stringWithFormat:@"<tr><td colspan='3'><img src='GitX://{SHA}:/prev/%@'/></td></tr>",[files objectAtIndex:0]]];
336+
if([GLFileView isImage:[files objectAtIndex:0]]){
337+
[res appendString:[NSString stringWithFormat:@"<tr><td colspan='3'><img src='GitX://{SHA}:/prev/%@'/></td></tr>",[files objectAtIndex:0]]];
338+
}
340339
}
341340
if(![[files objectAtIndex:1] isAbsolutePath]){
342341
[res appendString:[NSString stringWithFormat:@"<tr><td colspan='3'>%@</td></tr>",[files objectAtIndex:1]]];
343-
[res appendString:[NSString stringWithFormat:@"<tr><td colspan='3'><img src='GitX://{SHA}/%@'/></td></tr>",[files objectAtIndex:1]]];
342+
if([GLFileView isImage:[files objectAtIndex:1]]){
343+
[res appendString:[NSString stringWithFormat:@"<tr><td colspan='3'><img src='GitX://{SHA}/%@'/></td></tr>",[files objectAtIndex:1]]];
344+
}
344345
}
345346
}
346347
}
@@ -361,7 +362,6 @@ +(NSArray *)getFilesNames:(NSString *)line
361362
{
362363
NSString *a;
363364
NSString *b;
364-
NSLog(@"line='%@'",line);
365365
NSScanner *scanner=[NSScanner scannerWithString:line];
366366
if([scanner scanString:@"Binary files " intoString:NULL]){
367367
[scanner scanUpToString:@" and" intoString:&a];
@@ -374,10 +374,34 @@ +(NSArray *)getFilesNames:(NSString *)line
374374
if (![b isAbsolutePath]) {
375375
b=[b substringFromIndex:2];
376376
}
377-
377+
378378
return [NSArray arrayWithObjects:a,b,nil];
379379
}
380380

381+
+(NSString*)mimeTypeForFileName:(NSString*)name
382+
{
383+
NSString *mimeType = nil;
384+
NSInteger i=[name rangeOfString:@"." options:NSBackwardsSearch].location;
385+
if(i!=NSNotFound){
386+
NSString *ext=[name substringFromIndex:i+1];
387+
CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (CFStringRef)ext, NULL);
388+
if(UTI){
389+
CFStringRef registeredType = UTTypeCopyPreferredTagWithClass(UTI, kUTTagClassMIMEType);
390+
if(registeredType){
391+
mimeType = NSMakeCollectable(registeredType);
392+
}
393+
CFRelease(UTI);
394+
}
395+
}
396+
return mimeType;
397+
}
398+
399+
+(BOOL)isImage:(NSString*)file
400+
{
401+
NSString *mimeType=[GLFileView mimeTypeForFileName:file];
402+
return (mimeType!=nil) && ([mimeType rangeOfString:@"image/" options:NSCaseInsensitiveSearch].location!=NSNotFound);
403+
}
404+
381405
+(BOOL)isBinaryFile:(NSString *)line
382406
{
383407
return (([line length]>12) && [[line substringToIndex:12] isEqualToString:@"Binary files"]);

0 commit comments

Comments
 (0)