Permalink
Browse files

When clearing search field, select the last search results

  • Loading branch information...
sleifer committed Aug 28, 2010
1 parent 46203e3 commit 098125d4921a2e837bcb9764290ffcc54bc7d7b5
Showing with 20 additions and 1 deletion.
  1. +2 −0 PBGitHistoryController.h
  2. +18 −1 PBGitHistoryController.m
View
@@ -54,13 +54,15 @@
PBGitTree *gitTree;
PBGitCommit *webCommit;
PBGitCommit *selectedCommit;
+ NSArray *lastSearchSelection;
}
@property (assign) int selectedCommitDetailsIndex;
@property (retain) PBGitCommit *webCommit;
@property (retain) PBGitTree* gitTree;
@property (readonly) NSArrayController *commitController;
@property (readonly) PBRefController *refController;
+@property (retain) NSArray *lastSearchSelection;
- (IBAction) setDetailedView:(id)sender;
- (IBAction) setTreeView:(id)sender;
View
@@ -39,14 +39,16 @@ - (void) saveFileBrowserSelection;
@implementation PBGitHistoryController
-@synthesize selectedCommitDetailsIndex, webCommit, gitTree, commitController, refController;
+
+@synthesize selectedCommitDetailsIndex, webCommit, gitTree, commitController, refController, lastSearchSelection;
- (void)awakeFromNib
{
self.selectedCommitDetailsIndex = [[NSUserDefaults standardUserDefaults] integerForKey:kHistorySelectedDetailIndexKey];
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.PBUseRelativeDates" options:NSKeyValueObservingOptionNew context:@"relativeDates"];
[commitController addObserver:self forKeyPath:@"selection" options:0 context:@"commitChange"];
+ [commitController addObserver:self forKeyPath:@"filterPredicate" options:0 context:@"filterChange"];
[commitController addObserver:self forKeyPath:@"arrangedObjects.@count" options:NSKeyValueObservingOptionInitial context:@"updateCommitCount"];
[treeController addObserver:self forKeyPath:@"selection" options:0 context:@"treeChange"];
@@ -244,6 +246,21 @@ - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(
return;
}
+ if ([(NSString *)context isEqualToString: @"filterChange"]) {
+ int count = [[commitController arrangedObjects] count];
+
+ if (count > 0 && [[searchField stringValue] length] != 0) {
+ lastSearchSelection = [NSArray arrayWithArray:[commitController arrangedObjects]];
+ } else if (count > 0 && [[searchField stringValue] length] == 0) {
+ [commitController setSelectedObjects:lastSearchSelection];
+ NSInteger newIndex = [[commitController selectionIndexes] firstIndex];
+ [commitList scrollRowToVisible:newIndex];
+ } else {
+ lastSearchSelection = nil;
+ }
+ return;
+ }
+
if ([(NSString*)context isEqualToString:@"relativeDates"]) {
[commitList reloadData];
return;

0 comments on commit 098125d

Please sign in to comment.