mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
Maintain the selection in the file browser when the commit selection changes
- only maintains one item, if multiple items are selected then only the first one will stay selected
- if the file is removed in the new commit then don't select anything, then if a new commit is selected that does have that file it will be selected again
- this does not maintain the expanded state of folders other than the one(s) that contain the selected file
- in PBGitHistory.xib Tree Controller turn off:
- Avoid Empty Selection
- Select Inserted Objects
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
IBOutlet NSArrayController* commitController;
|
||||
IBOutlet NSTreeController* treeController;
|
||||
IBOutlet NSOutlineView* fileBrowser;
|
||||
NSArray *currentFileBrowserSelectionPath;
|
||||
IBOutlet NSTableView* commitList;
|
||||
IBOutlet PBCollapsibleSplitView *historySplitView;
|
||||
QLPreviewPanel* previewPanel;
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
@interface PBGitHistoryController ()
|
||||
|
||||
- (void) updateBranchFilterMatrix;
|
||||
- (void) restoreFileBrowserSelection;
|
||||
- (void) saveFileBrowserSelection;
|
||||
|
||||
@end
|
||||
|
||||
@@ -89,8 +91,10 @@
|
||||
|
||||
selectedCommit = [[commitController selectedObjects] lastObject];
|
||||
|
||||
if (self.selectedCommitDetailsIndex == kHistoryTreeViewIndex)
|
||||
if (self.selectedCommitDetailsIndex == kHistoryTreeViewIndex) {
|
||||
self.gitTree = selectedCommit.tree;
|
||||
[self restoreFileBrowserSelection];
|
||||
}
|
||||
else // kHistoryDetailViewIndex
|
||||
self.webCommit = selectedCommit;
|
||||
|
||||
@@ -153,15 +157,60 @@
|
||||
self.status = [NSString stringWithFormat:@"%d commits loaded", [[commitController arrangedObjects] count]];
|
||||
}
|
||||
|
||||
- (void) restoreFileBrowserSelection
|
||||
{
|
||||
if (self.selectedCommitDetailsIndex != kHistoryTreeViewIndex)
|
||||
return;
|
||||
|
||||
NSArray *children = [treeController content];
|
||||
if ([children count] == 0)
|
||||
return;
|
||||
|
||||
NSIndexPath *path = [[NSIndexPath alloc] init];
|
||||
if ([currentFileBrowserSelectionPath count] == 0)
|
||||
path = [path indexPathByAddingIndex:0];
|
||||
else {
|
||||
for (NSString *pathComponent in currentFileBrowserSelectionPath) {
|
||||
PBGitTree *child = nil;
|
||||
NSUInteger childIndex = 0;
|
||||
for (child in children) {
|
||||
if ([child.path isEqualToString:pathComponent]) {
|
||||
path = [path indexPathByAddingIndex:childIndex];
|
||||
children = child.children;
|
||||
break;
|
||||
}
|
||||
childIndex++;
|
||||
}
|
||||
if (!child)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
[treeController setSelectionIndexPath:path];
|
||||
}
|
||||
|
||||
- (void) saveFileBrowserSelection
|
||||
{
|
||||
NSArray *objects = [treeController selectedObjects];
|
||||
NSArray *content = [treeController content];
|
||||
|
||||
if ([objects count] && [content count]) {
|
||||
PBGitTree *treeItem = [objects objectAtIndex:0];
|
||||
currentFileBrowserSelectionPath = [treeItem.fullPath componentsSeparatedByString:@"/"];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
|
||||
{
|
||||
if ([(NSString *)context isEqualToString: @"commitChange"]) {
|
||||
[self updateKeys];
|
||||
[self restoreFileBrowserSelection];
|
||||
return;
|
||||
}
|
||||
|
||||
if ([(NSString *)context isEqualToString: @"treeChange"]) {
|
||||
[self updateQuicklookForce: NO];
|
||||
[self saveFileBrowserSelection];
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -58,9 +58,7 @@
|
||||
</object>
|
||||
<string key="NSObjectClassName">PBGitTree</string>
|
||||
<object class="_NSManagedProxy" key="_NSManagedProxy"/>
|
||||
<bool key="NSAvoidsEmptySelection">YES</bool>
|
||||
<bool key="NSPreservesSelection">YES</bool>
|
||||
<bool key="NSSelectsInsertedObjects">YES</bool>
|
||||
<string key="NSTreeContentChildrenKey">children</string>
|
||||
<string key="NSTreeContentLeafKey">leaf</string>
|
||||
</object>
|
||||
|
||||
Reference in New Issue
Block a user