mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
CommitView: Allow changing of context size
This adds a slider in the commit view with which the user can change the context size. This is useful for example if the hunks are too big; by changing the context size, a hunk can be split and then the changes can be committed.
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
+15
-4
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,12 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1 id='title'><span id="status">Nothing to commit</span></h1>
|
||||
<h1 id='title'>
|
||||
<input type="range" min="1" max="8" value="3" id="contextSize">
|
||||
<span id="contextTitle">Context:</span>
|
||||
<span id="status">Nothing to commit</span>
|
||||
|
||||
</h1>
|
||||
|
||||
<div id="notification" style="display:none">
|
||||
<img src="../../images/spinner.gif" alt="Spinner" id="spinner"></img>
|
||||
|
||||
Reference in New Issue
Block a user