Removed unneeded property. Changed how search tracks updates when file structure changes. Fixes #721

This commit is contained in:
Michael Starke 2021-11-02 14:05:05 +01:00
parent 59b28b4872
commit 2e46d7c121
2 changed files with 12 additions and 14 deletions

View File

@ -42,11 +42,11 @@ NSString *const kMPDocumentSearchResultsKey = @"kMPDocumentSearchResul
- (void)enterSearchWithContext:(MPEntrySearchContext *)context {
/* the search context is loaded via defaults */
self.searchContext = context;
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateSearch:) name:NSUndoManagerDidRedoChangeNotification object:self.undoManager];
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateSearch:) name:NSUndoManagerDidUndoChangeNotification object:self.undoManager];
/* Do not do this since it seems to break the undo/redo grouping completly!
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateSearch:) name:NSUndoManagerDidCloseUndoGroupNotification object:self.undoManager];
*/
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateSearch:) name:KPKTreeDidAddEntryNotification object:self.tree];
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateSearch:) name:KPKTreeDidAddGroupNotification object:self.tree];
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateSearch:) name:KPKTreeDidRemoveEntryNotification object:self.tree];
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateSearch:) name:KPKTreeDidRemoveGroupNotification object:self.tree];
[NSNotificationCenter.defaultCenter postNotificationName:MPDocumentDidEnterSearchNotification object:self];
[self updateSearch:self];
/* clear selection */
@ -77,11 +77,12 @@ NSString *const kMPDocumentSearchResultsKey = @"kMPDocumentSearchResul
}
- (void)exitSearch:(id)sender {
[NSNotificationCenter.defaultCenter removeObserver:self name:NSUndoManagerDidUndoChangeNotification object:self.undoManager];
[NSNotificationCenter.defaultCenter removeObserver:self name:NSUndoManagerDidRedoChangeNotification object:self.undoManager];
/* No need to do this since we did not register in the first place see [MPDocument enterSearchWithContext:]
[NSNotificationCenter.defaultCenter removeObserver:self name:NSUndoManagerDidCloseUndoGroupNotification object:self.undoManager];
*/
[NSNotificationCenter.defaultCenter removeObserver:self name:KPKTreeDidAddEntryNotification object:self.tree];
[NSNotificationCenter.defaultCenter removeObserver:self name:KPKTreeDidAddGroupNotification object:self.tree];
[NSNotificationCenter.defaultCenter removeObserver:self name:KPKTreeDidRemoveEntryNotification object:self.tree];
[NSNotificationCenter.defaultCenter removeObserver:self name:KPKTreeDidRemoveGroupNotification object:self.tree];
self.searchContext = nil;
[NSNotificationCenter.defaultCenter postNotificationName:MPDocumentDidExitSearchNotification object:self];
}

View File

@ -76,7 +76,6 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
}
@property (strong) MPContextBarViewController *contextBarViewController;
@property (strong) NSArray *filteredEntries;
@property (weak) IBOutlet NSTableView *entryTable;
@property (assign) MPDisplayMode displayMode;
@ -502,8 +501,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
- (void)_didUpdateSearchResults:(NSNotification *)notification {
NSArray *result = notification.userInfo[kMPDocumentSearchResultsKey];
NSAssert(result != nil, @"Results should never be nil");
self.filteredEntries = result;
self.entryArrayController.content = self.filteredEntries;
self.entryArrayController.content = result;
[self.entryTable tableColumnWithIdentifier:MPEntryTableParentColumnIdentifier].hidden = NO;
[self _updateContextBar];
}
@ -512,7 +510,6 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
- (void)_didExitSearch:(NSNotification *)notification {
[self.entryTable tableColumnWithIdentifier:MPEntryTableParentColumnIdentifier].hidden = YES;
self.entryArrayController.content = nil;
self.filteredEntries = nil;
self.displayMode = MPDisplayModeEntries;
[self _updateContextBar];
MPDocument *document = notification.object;