Permalink
Browse files

Fix crashes on tab/window closing due to previously registed preferen…

…ce observers not being removed.
  • Loading branch information...
stuconnolly committed Mar 24, 2017
1 parent 4a18651 commit 4d450e171fe429a5375c95dbc8372853a910c681
Showing with 28 additions and 6 deletions.
  1. +2 −3 Source/SPDatabaseDocument.m
  2. +26 −3 Source/SPTableTriggers.m
@@ -6435,7 +6435,6 @@ - (void)_addPreferenceObservers
[prefs addObserver:tableContentInstance forKeyPath:SPDisplayTableViewVerticalGridlines options:NSKeyValueObservingOptionNew context:NULL];
[prefs addObserver:customQueryInstance forKeyPath:SPDisplayTableViewVerticalGridlines options:NSKeyValueObservingOptionNew context:NULL];
[prefs addObserver:tableRelationsInstance forKeyPath:SPDisplayTableViewVerticalGridlines options:NSKeyValueObservingOptionNew context:NULL];
[prefs addObserver:tableTriggersInstance forKeyPath:SPDisplayTableViewVerticalGridlines options:NSKeyValueObservingOptionNew context:NULL];
[prefs addObserver:[SPQueryController sharedQueryController] forKeyPath:SPDisplayTableViewVerticalGridlines options:NSKeyValueObservingOptionNew context:NULL];
// Register observers for the when the UseMonospacedFonts preference changes
@@ -6461,14 +6460,14 @@ - (void)_removePreferenceObservers
[prefs removeObserver:self forKeyPath:SPDisplayTableViewVerticalGridlines];
[prefs removeObserver:tableSourceInstance forKeyPath:SPUseMonospacedFonts];
[prefs removeObserver:tableSourceInstance forKeyPath:SPDisplayTableViewVerticalGridlines];
[prefs removeObserver:tableContentInstance forKeyPath:SPGlobalResultTableFont];
[prefs removeObserver:tableContentInstance forKeyPath:SPDisplayBinaryDataAsHex];
[prefs removeObserver:tableContentInstance forKeyPath:SPDisplayTableViewVerticalGridlines];
[prefs removeObserver:customQueryInstance forKeyPath:SPDisplayTableViewVerticalGridlines];
[prefs removeObserver:tableRelationsInstance forKeyPath:SPDisplayTableViewVerticalGridlines];
[prefs removeObserver:tableSourceInstance forKeyPath:SPDisplayTableViewVerticalGridlines];
[prefs removeObserver:tableContentInstance forKeyPath:SPDisplayTableViewVerticalGridlines];
[prefs removeObserver:[SPQueryController sharedQueryController] forKeyPath:SPUseMonospacedFonts];
[prefs removeObserver:[SPQueryController sharedQueryController] forKeyPath:SPConsoleEnableLogging];
View
@@ -68,6 +68,8 @@ - (void)_toggleConfirmAddTriggerButtonEnabled;
- (void)_refreshTriggerDataForcingCacheRefresh:(BOOL)clearAllCaches;
- (void)_openTriggerSheet;
- (void)_reopenTriggerSheet:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
- (void)_addPreferenceObservers;
- (void)_removePreferenceObservers;
@end
@@ -114,8 +116,7 @@ - (void)awakeFromNib
[[column dataCell] setFont:useMonospacedFont ? [NSFont fontWithName:SPDefaultMonospacedFontName size:monospacedFontSize] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
}
// Register as an observer for the when the UseMonospacedFonts preference changes
[prefs addObserver:self forKeyPath:SPUseMonospacedFonts options:NSKeyValueObservingOptionNew context:NULL];
[self _addPreferenceObservers];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(triggerStatementTextDidChange:)
@@ -634,6 +635,27 @@ - (void)_reopenTriggerSheet:(NSWindow *)sheet returnCode:(NSInteger)returnCode c
[self performSelector:@selector(_openTriggerSheet) withObject:nil afterDelay:0.0];
}
/**
* Add any necessary preference observers to allow live updating on changes.
*/
- (void)_addPreferenceObservers
{
// Register as an observer for the when the UseMonospacedFonts preference changes
[prefs addObserver:self forKeyPath:SPUseMonospacedFonts options:NSKeyValueObservingOptionNew context:NULL];
// Register observers for when the DisplayTableViewVerticalGridlines preference changes
[prefs addObserver:self forKeyPath:SPDisplayTableViewVerticalGridlines options:NSKeyValueObservingOptionNew context:NULL];
}
/**
* Remove any previously added preference observers.
*/
- (void)_removePreferenceObservers
{
[prefs removeObserver:self forKeyPath:SPUseMonospacedFonts];
[prefs removeObserver:self forKeyPath:SPDisplayTableViewVerticalGridlines];
}
#pragma mark -
- (void)dealloc
@@ -642,7 +664,8 @@ - (void)dealloc
SPClear(editedTrigger);
[[NSNotificationCenter defaultCenter] removeObserver:self];
[prefs removeObserver:self forKeyPath:SPUseMonospacedFonts];
[self _removePreferenceObservers];
[super dealloc];
}

0 comments on commit 4d450e1

Please sign in to comment.