diff --git a/PBGitIndexController.h b/PBGitIndexController.h index 4cd18a5..ca1c4fd 100644 --- a/PBGitIndexController.h +++ b/PBGitIndexController.h @@ -11,6 +11,8 @@ #import "PBChangedFile.h" @interface PBGitIndexController : NSObject { + int contextSize; + IBOutlet NSArrayController *stagedFilesController, *unstagedFilesController; IBOutlet PBGitCommitController *commitController; @@ -21,6 +23,10 @@ IBOutlet NSTableView *stagedTable; } +@property (assign) int contextSize; + +- (NSString *) contextParameter; + - (void) stageFiles:(NSArray *)files; - (void) unstageFiles:(NSArray *)files; diff --git a/PBGitIndexController.m b/PBGitIndexController.m index b876ef2..d5dbb91 100644 --- a/PBGitIndexController.m +++ b/PBGitIndexController.m @@ -14,8 +14,12 @@ @implementation PBGitIndexController +@synthesize contextSize; + - (void)awakeFromNib { + contextSize = 3; + [unstagedTable setDoubleAction:@selector(tableClicked:)]; [stagedTable setDoubleAction:@selector(tableClicked:)]; @@ -123,7 +127,7 @@ if (file.status == NEW) return [commitController.repository outputForArguments:[NSArray arrayWithObjects:@"show", indexPath, nil]]; - return [commitController.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff-index", @"-p", @"--cached", [commitController parentTree], @"--", file.path, nil]]; + return [commitController.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff-index", [self contextParameter], @"--cached", [commitController parentTree], @"--", file.path, nil]]; } - (NSString *)unstagedChangesForFile:(PBChangedFile *)file @@ -131,15 +135,17 @@ if (file.status == NEW) { NSStringEncoding encoding; NSError *error = nil; - NSString *contents = [NSString stringWithContentsOfFile:[[commitController.repository workingDirectory] stringByAppendingPathComponent:file.path] - usedEncoding:&encoding error:&error]; + NSString *path = [[commitController.repository workingDirectory] stringByAppendingPathComponent:file.path]; + NSString *contents = [NSString stringWithContentsOfFile:path + usedEncoding:&encoding + error:&error]; if (error) return nil; return contents; } - return [commitController.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", @"--", file.path, nil]]; + return [commitController.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", [self contextParameter], @"--", file.path, nil]]; } - (void) forceRevertChangesForFiles:(NSArray *)files @@ -368,6 +374,11 @@ writeRowsWithIndexes:(NSIndexSet *)rowIndexes return YES; } +- (NSString *) contextParameter +{ + return [[NSString alloc] initWithFormat:@"-U%i", contextSize]; +} + # pragma mark WebKit Accessibility + (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector diff --git a/PBWebChangesController.h b/PBWebChangesController.h index 796f2b4..0b0ec13 100644 --- a/PBWebChangesController.h +++ b/PBWebChangesController.h @@ -11,11 +11,13 @@ #import "PBGitCommitController.h" #import "PBChangedFile.h" +@class PBGitIndexController; + @interface PBWebChangesController : PBWebController { IBOutlet NSArrayController *unstagedFilesController; IBOutlet NSArrayController *cachedFilesController; IBOutlet PBGitCommitController *controller; - IBOutlet id indexController; + IBOutlet PBGitIndexController *indexController; PBChangedFile *selectedFile; BOOL selectedFileIsCached; @@ -25,4 +27,5 @@ - (void) setStateMessage:(NSString *)state; - (void) showMultiple:(NSArray *)files; +- (void) setContextSize:(int)size; @end diff --git a/PBWebChangesController.m b/PBWebChangesController.m index b15b18c..1e2dd0d 100644 --- a/PBWebChangesController.m +++ b/PBWebChangesController.m @@ -7,6 +7,7 @@ // #import "PBWebChangesController.h" +#import "PBGitIndexController.h" @implementation PBWebChangesController @@ -92,4 +93,12 @@ [script callWebScriptMethod:@"setState" withArguments: [NSArray arrayWithObject:state]]; } +- (void) setContextSize:(int)size +{ + if (size == indexController.contextSize) + return; + + indexController.contextSize = size; + [self refresh]; +} @end diff --git a/html/views/commit/commit.css b/html/views/commit/commit.css index 9812db8..7ae773a 100644 --- a/html/views/commit/commit.css +++ b/html/views/commit/commit.css @@ -48,6 +48,18 @@ table.diff { margin-top: 30px; } +#contextSize { + width: 80px; + margin-top: -0.5px; + float: right; + margin-right: 20px; +} + +#contextTitle { + margin-right: 3px; + float: right; +} + .diff a.stagebutton { display: block; width: 40px; diff --git a/html/views/commit/commit.js b/html/views/commit/commit.js index bcae7f7..b766b93 100644 --- a/html/views/commit/commit.js +++ b/html/views/commit/commit.js @@ -1,6 +1,6 @@ var showNewFile = function(file) { - $('title').innerHTML = "New file: " + file.path; + setTitle("New file: " + file.path); var contents = IndexController.unstagedChangesForFile_(file); if (!contents) { @@ -17,15 +17,26 @@ var hideState = function() { } var setState = function(state) { + setTitle(state); + hideNotification(); $("state").style.display = ""; $("diff").style.display = "none"; $("state").innerHTML = state.escapeHTML(); } +var setTitle = function(status) { + $("status").innerHTML = status; + $("contextSize").style.display = "none"; + $("contextTitle").style.display = "none"; +} + +var displayContext = function() { + $("contextSize").style.display = ""; + $("contextTitle").style.display = ""; +} + var showFileChanges = function(file, cached) { if (!file) { - $("title").innerHTML = "No file selected"; - hideNotification(); setState("No file selected"); return; } @@ -33,16 +44,22 @@ var showFileChanges = function(file, cached) { hideNotification(); hideState(); + $("contextSize").oninput = function(element) { + Controller.setContextSize_($("contextSize").value); + } + if (file.status == 0) // New file? return showNewFile(file); var changes; if (cached) { - $("title").innerHTML = "Staged changes for " + file.path; + setTitle("Staged changes for " + file.path); + displayContext(); changes = IndexController.stagedChangesForFile_(file); } else { - $("title").innerHTML = "Unstaged changes for " + file.path; + setTitle("Unstaged changes for " + file.path); + displayContext(); changes = IndexController.unstagedChangesForFile_(file); } diff --git a/html/views/commit/index.html b/html/views/commit/index.html index d391ed6..cb3b6f0 100644 --- a/html/views/commit/index.html +++ b/html/views/commit/index.html @@ -13,7 +13,12 @@ -

Nothing to commit

+

+ + Context: + Nothing to commit + +