Skip to content

Commit da6a75c

Browse files
committed
error control & and html/css/javascript reorder.
1 parent 6a4f5bd commit da6a75c

File tree

16 files changed

+370
-1199
lines changed

16 files changed

+370
-1199
lines changed

GLFileView.m

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,31 @@ - (void) showFile
101101

102102
NSString *fileTxt = @"";
103103
if(startFile==@"fileview"){
104-
fileTxt=[self parseHTML:[file textContents:&theError]];
104+
fileTxt=[file textContents:&theError];
105+
if(!theError)
106+
fileTxt=[self parseHTML:fileTxt];
105107
}else if(startFile==@"blame"){
106-
fileTxt=[self parseBlame:[file blame:&theError]];
108+
fileTxt=[file blame:&theError];
109+
if(!theError)
110+
fileTxt=[self parseBlame:fileTxt];
107111
}else if(startFile==@"log"){
108112
fileTxt=[file log:logFormat error:&theError];
109113
}else if(startFile==@"diff"){
110114
fileTxt=[file diff:diffType error:&theError];
115+
if(!theError)
116+
fileTxt=[self parseDiff:fileTxt];
111117
}
112118

113119
id script = [view windowScriptObject];
114-
if(theError==nil){
120+
if(!theError){
115121
NSString *filePath = [file fullPath];
116122
[script callWebScriptMethod:@"showFile" withArguments:[NSArray arrayWithObjects:fileTxt, filePath, nil]];
117123
}else{
118124
[script callWebScriptMethod:@"setMessage" withArguments:[NSArray arrayWithObjects:[theError localizedDescription], nil]];
119125
}
120126
}
121127

122-
#if 0
128+
#if 1
123129
NSString *dom=[[[[view mainFrame] DOMDocument] documentElement] outerHTML];
124130
NSString *tmpFile=@"~/tmp/test.html";
125131
[dom writeToFile:[tmpFile stringByExpandingTildeInPath] atomically:true encoding:NSUTF8StringEncoding error:nil];
@@ -217,6 +223,59 @@ - (NSString *) parseHTML:(NSString *)txt
217223
return txt;
218224
}
219225

226+
- (NSString *) parseDiff:(NSString *)txt
227+
{
228+
txt=[self parseHTML:txt];
229+
230+
NSArray *lines = [txt componentsSeparatedByString:@"\n"];
231+
NSString *line;
232+
NSMutableString *res=[NSMutableString string];
233+
234+
[res appendString:@"<table class='diff'>"];
235+
int i=0;
236+
while(i<[lines count]){
237+
line=[lines objectAtIndex:i];
238+
if([[line substringToIndex:2] isEqualToString:@"@@"]){
239+
240+
int l_int,l_count,l_line;
241+
int r_int,r_count,r_line;
242+
243+
NSString *header=[line substringFromIndex:3];
244+
NSRange hr = NSMakeRange(0, [header rangeOfString:@" @@"].location);
245+
header=[header substringWithRange:hr];
246+
247+
NSArray *pos=[header componentsSeparatedByString:@" "];
248+
NSArray *pos_l=[[pos objectAtIndex:0] componentsSeparatedByString:@","];
249+
NSArray *pos_r=[[pos objectAtIndex:1] componentsSeparatedByString:@","];
250+
l_line=l_int=abs([[pos_l objectAtIndex:0]integerValue]);
251+
l_count=[[pos_l objectAtIndex:1]integerValue];
252+
r_line=r_int=[[pos_r objectAtIndex:0]integerValue];
253+
r_count=[[pos_r objectAtIndex:1]integerValue];
254+
255+
[res appendString:[NSString stringWithFormat:@"<tr class='header'><td colspan=3>%@</td></tr>",line]];
256+
257+
do{
258+
line=[lines objectAtIndex:++i];
259+
NSString *s=[line substringToIndex:1];
260+
line=[line substringFromIndex:1];
261+
262+
if([s isEqualToString:@" "]){
263+
[res appendString:[NSString stringWithFormat:@"<tr><td class='l'>%d</td><td class='r'>%d</td>",l_line++,r_line++]];
264+
}else if([s isEqualToString:@"-"]){
265+
[res appendString:[NSString stringWithFormat:@"<tr class='l'><td class='l'>%d</td><td class='r'></td>",l_line++]];
266+
}else if([s isEqualToString:@"+"]){
267+
[res appendString:[NSString stringWithFormat:@"<tr class='r'><td class='l'></td><td class='r'>%d</td>",r_line++]];
268+
}
269+
[res appendString:[NSString stringWithFormat:@"<td class='code'>%@</td></tr>",line]];
270+
}while(l_line<(l_int+l_count) && r_line<(r_int+r_count));
271+
272+
}
273+
i++;
274+
}
275+
[res appendString:@"</table>"];
276+
return res;
277+
}
278+
220279
- (NSString *) parseBlame:(NSString *)txt
221280
{
222281
txt=[self parseHTML:txt];

GitX.xcodeproj/project.pbxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,6 @@
11581158
isa = PBXProject;
11591159
buildConfigurationList = 26FC0A880875C7B200E6366F /* Build configuration list for PBXProject "GitX" */;
11601160
compatibilityVersion = "Xcode 3.1";
1161-
developmentRegion = English;
11621161
hasScannedForEncodings = 1;
11631162
knownRegions = (
11641163
English,

html/css/GitX.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
@import url("diff.css");
22
@import url("notification.css");
33

4+
45
body {
56
margin: 0;
67
margin-top: 5px;
78
width: 100%;
89
font-family: 'Lucida Grande', Arial;
910
}
11+
12+
#message {
13+
margin-left: 20px;
14+
margin-right: 20px;
15+
margin-top: 40px;
16+
text-align: center;
17+
font-size: 200%;
18+
padding: 20px;
19+
width: auto;
20+
21+
background-color: #B4D7FF;
22+
border: 2px solid #45A1FE;
23+
24+
-webkit-border-radius: 10px;
25+
}
26+

html/views/blame/blame.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
var setMessage = function(message) {
2+
$("message").style.display = "";
3+
$("message").innerHTML = message.escapeHTML();
4+
$("blame").style.display = "none";
5+
}
6+
17
var showFile = function(txt) {
2-
$("txt").style.display = "";
3-
$("txt").innerHTML="<pre>"+txt+"</pre>";
8+
$("blame").style.display = "";
9+
$("blame").innerHTML="<pre>"+txt+"</pre>";
10+
$("message").style.display = "none";
411

512
SyntaxHighlighter.defaults['toolbar'] = false;
6-
713
SyntaxHighlighter.highlight();
814
return;
915
}

0 commit comments

Comments
 (0)