mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
CommitView: Don't change selection when refreshing
We used to read in a completely new array when refreshing the index. The problem with this is that the selection changes when reading in the new array. We avoid this by changing the current array, rather than loading in a completely new one.
This commit is contained in:
+2
-2
@@ -19,6 +19,7 @@ typedef enum {
|
||||
NSString *path;
|
||||
BOOL hasCachedChanges;
|
||||
BOOL hasUnstagedChanges;
|
||||
BOOL shouldBeDeleted;
|
||||
|
||||
// Index and HEAD stuff, to be used to revert changes
|
||||
NSString *commitBlobSHA;
|
||||
@@ -30,8 +31,7 @@ typedef enum {
|
||||
|
||||
@property (copy) NSString *path, *commitBlobSHA, *commitBlobMode;
|
||||
@property (assign) PBChangedFileStatus status;
|
||||
@property (assign) BOOL hasCachedChanges;
|
||||
@property (assign) BOOL hasUnstagedChanges;
|
||||
@property (assign) BOOL hasCachedChanges, hasUnstagedChanges, shouldBeDeleted;
|
||||
|
||||
- (NSImage *)icon;
|
||||
- (NSString *)indexInfo;
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
|
||||
@implementation PBChangedFile
|
||||
|
||||
@synthesize path, status, hasCachedChanges, hasUnstagedChanges, commitBlobSHA, commitBlobMode;
|
||||
@synthesize path, status, hasCachedChanges, hasUnstagedChanges, commitBlobSHA, commitBlobMode, shouldBeDeleted;
|
||||
|
||||
- (id) initWithPath:(NSString *)p
|
||||
{
|
||||
|
||||
+33
-7
@@ -16,6 +16,7 @@
|
||||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
self.files = [NSMutableArray array];
|
||||
[super awakeFromNib];
|
||||
[self refresh:self];
|
||||
|
||||
@@ -80,9 +81,11 @@
|
||||
|
||||
- (void) refresh:(id) sender
|
||||
{
|
||||
for (PBChangedFile *file in files)
|
||||
file.shouldBeDeleted = YES;
|
||||
|
||||
self.status = @"Refreshing index…";
|
||||
self.busy++;
|
||||
self.files = [NSMutableArray array];
|
||||
|
||||
[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"update-index", @"-q", @"--unmerged", @"--ignore-missing", @"--refresh", nil]];
|
||||
self.busy--;
|
||||
@@ -108,8 +111,6 @@
|
||||
[nc addObserver:self selector:@selector(readCachedFiles:) name:NSFileHandleReadToEndOfFileCompletionNotification object:handle];
|
||||
self.busy++;
|
||||
[handle readToEndOfFileInBackgroundAndNotify];
|
||||
|
||||
self.files = files;
|
||||
}
|
||||
|
||||
- (void) updateView
|
||||
@@ -119,10 +120,16 @@
|
||||
|
||||
- (void) doneProcessingIndex
|
||||
{
|
||||
if (!--self.busy)
|
||||
[self willChangeValueForKey:@"files"];
|
||||
if (!--self.busy) {
|
||||
self.status = @"Ready";
|
||||
[unstagedFilesController didChangeArrangementCriteria];
|
||||
[cachedFilesController didChangeArrangementCriteria];
|
||||
NSArray *filesToBeDeleted = [files filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"shouldBeDeleted == 1"]];
|
||||
for (PBChangedFile *file in filesToBeDeleted) {
|
||||
NSLog(@"Deleting file: %@", [file path]);
|
||||
[files removeObject:file];
|
||||
}
|
||||
}
|
||||
[self didChangeValueForKey:@"files"];
|
||||
}
|
||||
|
||||
- (void) readOtherFiles:(NSNotification *)notification;
|
||||
@@ -131,13 +138,31 @@
|
||||
for (NSString *line in lines) {
|
||||
if ([line length] == 0)
|
||||
continue;
|
||||
|
||||
BOOL added = NO;
|
||||
// Check if file is already in our index
|
||||
for (PBChangedFile *file in files) {
|
||||
if ([[file path] isEqualToString:line]) {
|
||||
file.shouldBeDeleted = NO;
|
||||
added = YES;
|
||||
file.status = NEW;
|
||||
file.hasCachedChanges = NO;
|
||||
file.hasUnstagedChanges = YES;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (added)
|
||||
continue;
|
||||
|
||||
// File does not exist yet, so add it
|
||||
PBChangedFile *file =[[PBChangedFile alloc] initWithPath:line];
|
||||
file.status = NEW;
|
||||
file.hasCachedChanges = NO;
|
||||
file.hasUnstagedChanges = YES;
|
||||
|
||||
[files addObject: file];
|
||||
}
|
||||
|
||||
[self doneProcessingIndex];
|
||||
}
|
||||
|
||||
@@ -161,6 +186,7 @@
|
||||
// but rather update it to incorporate our changes
|
||||
for (PBChangedFile *file in files) {
|
||||
if ([file.path isEqualToString:line]) {
|
||||
file.shouldBeDeleted = NO;
|
||||
if (cached) {
|
||||
file.commitBlobSHA = sha;
|
||||
file.commitBlobMode = mode;
|
||||
|
||||
Reference in New Issue
Block a user