Skip to content

Commit 4b85580

Browse files
committed
diff on file view
1 parent d1d4a2e commit 4b85580

File tree

5 files changed

+64
-25
lines changed

5 files changed

+64
-25
lines changed

GLFileView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
IBOutlet MGScopeBar *typeBar;
2121
NSMutableArray *groups;
2222
NSString *logFormat;
23+
NSString *diffType;
2324
IBOutlet NSView *accessoryView;
2425
IBOutlet NSSplitView *fileListSplitView;
2526
}

GLFileView.m

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,40 @@ - (void) awakeFromNib
5353
@"log", ITEM_IDENTIFIER,
5454
@"History", ITEM_NAME,
5555
nil],
56+
[NSDictionary dictionaryWithObjectsAndKeys:
57+
@"diff", ITEM_IDENTIFIER,
58+
@"Diff", ITEM_NAME,
59+
nil],
5660
nil];
5761
[self.groups addObject:[NSDictionary dictionaryWithObjectsAndKeys:
5862
[NSNumber numberWithBool:NO], GROUP_SEPARATOR,
5963
[NSNumber numberWithInt:MGRadioSelectionMode], GROUP_SELECTION_MODE, // single selection group.
6064
items, GROUP_ITEMS,
6165
nil]];
66+
67+
NSArray *difft = [NSArray arrayWithObjects:
68+
[NSDictionary dictionaryWithObjectsAndKeys:
69+
@"l", ITEM_IDENTIFIER,
70+
@"Local", ITEM_NAME,
71+
nil],
72+
[NSDictionary dictionaryWithObjectsAndKeys:
73+
@"h", ITEM_IDENTIFIER,
74+
@"HEAD", ITEM_NAME,
75+
nil],
76+
[NSDictionary dictionaryWithObjectsAndKeys:
77+
@"p", ITEM_IDENTIFIER,
78+
@"Previous", ITEM_NAME,
79+
nil],
80+
nil];
81+
[self.groups addObject:[NSDictionary dictionaryWithObjectsAndKeys:
82+
[NSNumber numberWithBool:NO], GROUP_SEPARATOR,
83+
[NSNumber numberWithInt:MGRadioSelectionMode], GROUP_SELECTION_MODE, // single selection group.
84+
difft, GROUP_ITEMS,
85+
@"Diff with:",GROUP_LABEL,
86+
nil]];
87+
6288
[typeBar reloadData];
63-
89+
6490
[fileListSplitView setHidden:YES];
6591
[self performSelector:@selector(restoreSplitViewPositiion) withObject:nil afterDelay:0];
6692
}
@@ -76,18 +102,20 @@ - (void) showFile
76102
NSArray *files=[historyController.treeController selectedObjects];
77103
if ([files count]>0) {
78104
PBGitTree *file=[files objectAtIndex:0];
79-
105+
80106
NSString *fileTxt = @"";
81107
if(startFile==@"fileview")
82108
fileTxt=[self parseHTML:[file textContents]];
83109
else if(startFile==@"blame")
84110
fileTxt=[self parseBlame:[file blame]];
85111
else if(startFile==@"log")
86-
fileTxt=[file log:logFormat];
87-
112+
fileTxt=[file log:logFormat];
113+
else if(startFile==@"diff")
114+
fileTxt=[file diff:diffType];
115+
88116
id script = [view windowScriptObject];
89117
NSString *filePath = [file fullPath];
90-
[script callWebScriptMethod:@"showFile" withArguments:[NSArray arrayWithObjects:fileTxt, filePath, nil]];
118+
[script callWebScriptMethod:@"showFile" withArguments:[NSArray arrayWithObjects:fileTxt, filePath, nil]];
91119
}
92120

93121
#if 0
@@ -146,11 +174,18 @@ - (MGScopeBarGroupSelectionMode)scopeBar:(MGScopeBar *)theScopeBar selectionMode
146174

147175
- (void)scopeBar:(MGScopeBar *)theScopeBar selectedStateChanged:(BOOL)selected forItem:(NSString *)identifier inGroup:(int)groupNumber
148176
{
149-
startFile=identifier;
150-
NSString *path = [NSString stringWithFormat:@"html/views/%@", identifier];
151-
NSString *html = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:path];
152-
NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:html]];
153-
[[view mainFrame] loadRequest:request];
177+
if(groupNumber==0){
178+
NSString *path = [NSString stringWithFormat:@"html/views/%@", identifier];
179+
NSString *html = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:path];
180+
NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:html]];
181+
[[view mainFrame] loadRequest:request];
182+
startFile=identifier;
183+
}else if(groupNumber==1){
184+
diffType=identifier;
185+
if(startFile==@"diff"){
186+
[[view mainFrame] reload];
187+
}
188+
}
154189
}
155190

156191
- (NSView *)accessoryViewForScopeBar:(MGScopeBar *)scopeBar
@@ -167,7 +202,7 @@ - (void)closeView
167202
{
168203
[historyController.treeController removeObserver:self forKeyPath:@"selection"];
169204
[self saveSplitViewPosition];
170-
205+
171206
[super closeView];
172207
}
173208

@@ -277,23 +312,23 @@ - (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)pr
277312
- (void)splitView:(NSSplitView *)splitView resizeSubviewsWithOldSize:(NSSize)oldSize
278313
{
279314
NSRect newFrame = [splitView frame];
280-
315+
281316
float dividerThickness = [splitView dividerThickness];
282-
317+
283318
NSView *leftView = [[splitView subviews] objectAtIndex:0];
284319
NSRect leftFrame = [leftView frame];
285320
leftFrame.size.height = newFrame.size.height;
286-
321+
287322
if ((newFrame.size.width - leftFrame.size.width - dividerThickness) < kFileListSplitViewRightMin) {
288323
leftFrame.size.width = newFrame.size.width - kFileListSplitViewRightMin - dividerThickness;
289324
}
290-
325+
291326
NSView *rightView = [[splitView subviews] objectAtIndex:1];
292327
NSRect rightFrame = [rightView frame];
293328
rightFrame.origin.x = leftFrame.size.width + dividerThickness;
294329
rightFrame.size.width = newFrame.size.width - rightFrame.origin.x;
295330
rightFrame.size.height = newFrame.size.height;
296-
331+
297332
[leftView setFrame:leftFrame];
298333
[rightView setFrame:rightFrame];
299334
}
@@ -312,7 +347,7 @@ - (void)restoreSplitViewPositiion
312347
float position = [[NSUserDefaults standardUserDefaults] floatForKey:kHFileListSplitViewPositionDefault];
313348
if (position < 1.0)
314349
position = 200;
315-
350+
316351
[fileListSplitView setPosition:position ofDividerAtIndex:0];
317352
[fileListSplitView setHidden:NO];
318353
}

PBGitTree.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
@interface PBGitTree : NSObject {
1313
long long _fileSize;
14-
14+
1515
NSString* sha;
1616
NSString* path;
1717
PBGitRepository* repository;
1818
__weak PBGitTree* parent;
1919
NSArray* children;
2020
BOOL leaf;
21-
21+
2222
NSString* localFileName;
2323
NSDate* localMtime;
2424
}
@@ -29,6 +29,7 @@
2929
- (NSString *)textContents;
3030
- (NSString *)blame;
3131
- (NSString *) log:(NSString *)format;
32+
- (NSString *) diff:(NSString *)format;
3233

3334
- (NSString*) tmpFileNameForContents;
3435
- (long long)fileSize;

html/views/diff/diffWindow.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,11 @@ var setMessage = function(message) {
66
$("diff").style.display = "none";
77
}
88

9+
var showDiff = function(diff) {
10+
highlightDiff(diff, $("diff"));
11+
}
12+
13+
var showFile = function(txt) {
14+
showDiff(txt);
15+
return;
16+
}

html/views/diff/index.html

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@
99

1010
<link rel="stylesheet" href="diffWindow.css" type="text/css" media="screen" title="no title" charset="utf-8">
1111
<script src="diffWindow.js" type="text/javascript" charset="utf-8"></script>
12-
13-
<script type="text/javascript" charset="utf-8">
14-
var showDiff = function(diff) {
15-
highlightDiff(diff, $("diff"));
16-
}
17-
</script>
1812
</head>
1913

2014
<body>

0 commit comments

Comments
 (0)