|
29 | 29 | @interface PBGitHistoryController ()
|
30 | 30 |
|
31 | 31 | - (void) updateBranchFilterMatrix;
|
| 32 | +- (void) restoreFileBrowserSelection; |
| 33 | +- (void) saveFileBrowserSelection; |
32 | 34 |
|
33 | 35 | @end
|
34 | 36 |
|
@@ -89,8 +91,10 @@ - (void) updateKeys
|
89 | 91 |
|
90 | 92 | selectedCommit = [[commitController selectedObjects] lastObject];
|
91 | 93 |
|
92 |
| - if (self.selectedCommitDetailsIndex == kHistoryTreeViewIndex) |
| 94 | + if (self.selectedCommitDetailsIndex == kHistoryTreeViewIndex) { |
93 | 95 | self.gitTree = selectedCommit.tree;
|
| 96 | + [self restoreFileBrowserSelection]; |
| 97 | + } |
94 | 98 | else // kHistoryDetailViewIndex
|
95 | 99 | self.webCommit = selectedCommit;
|
96 | 100 |
|
@@ -153,15 +157,60 @@ - (void) updateStatus
|
153 | 157 | self.status = [NSString stringWithFormat:@"%d commits loaded", [[commitController arrangedObjects] count]];
|
154 | 158 | }
|
155 | 159 |
|
| 160 | +- (void) restoreFileBrowserSelection |
| 161 | +{ |
| 162 | + if (self.selectedCommitDetailsIndex != kHistoryTreeViewIndex) |
| 163 | + return; |
| 164 | + |
| 165 | + NSArray *children = [treeController content]; |
| 166 | + if ([children count] == 0) |
| 167 | + return; |
| 168 | + |
| 169 | + NSIndexPath *path = [[NSIndexPath alloc] init]; |
| 170 | + if ([currentFileBrowserSelectionPath count] == 0) |
| 171 | + path = [path indexPathByAddingIndex:0]; |
| 172 | + else { |
| 173 | + for (NSString *pathComponent in currentFileBrowserSelectionPath) { |
| 174 | + PBGitTree *child = nil; |
| 175 | + NSUInteger childIndex = 0; |
| 176 | + for (child in children) { |
| 177 | + if ([child.path isEqualToString:pathComponent]) { |
| 178 | + path = [path indexPathByAddingIndex:childIndex]; |
| 179 | + children = child.children; |
| 180 | + break; |
| 181 | + } |
| 182 | + childIndex++; |
| 183 | + } |
| 184 | + if (!child) |
| 185 | + return; |
| 186 | + } |
| 187 | + } |
| 188 | + |
| 189 | + [treeController setSelectionIndexPath:path]; |
| 190 | +} |
| 191 | + |
| 192 | +- (void) saveFileBrowserSelection |
| 193 | +{ |
| 194 | + NSArray *objects = [treeController selectedObjects]; |
| 195 | + NSArray *content = [treeController content]; |
| 196 | + |
| 197 | + if ([objects count] && [content count]) { |
| 198 | + PBGitTree *treeItem = [objects objectAtIndex:0]; |
| 199 | + currentFileBrowserSelectionPath = [treeItem.fullPath componentsSeparatedByString:@"/"]; |
| 200 | + } |
| 201 | +} |
| 202 | + |
156 | 203 | - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
|
157 | 204 | {
|
158 | 205 | if ([(NSString *)context isEqualToString: @"commitChange"]) {
|
159 | 206 | [self updateKeys];
|
| 207 | + [self restoreFileBrowserSelection]; |
160 | 208 | return;
|
161 | 209 | }
|
162 | 210 |
|
163 | 211 | if ([(NSString *)context isEqualToString: @"treeChange"]) {
|
164 | 212 | [self updateQuicklookForce: NO];
|
| 213 | + [self saveFileBrowserSelection]; |
165 | 214 | return;
|
166 | 215 | }
|
167 | 216 |
|
|
0 commit comments