Skip to content

Commit

Permalink
Fix crashes on tab/window closing due to previously registed preferen…
Browse files Browse the repository at this point in the history
…ce observers not being removed.
  • Loading branch information
stuconnolly committed Mar 24, 2017
1 parent 4a18651 commit 4d450e1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
5 changes: 2 additions & 3 deletions Source/SPDatabaseDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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];
Expand Down
29 changes: 26 additions & 3 deletions Source/SPTableTriggers.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:)
Expand Down Expand Up @@ -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
Expand All @@ -642,7 +664,8 @@ - (void)dealloc
SPClear(editedTrigger);

[[NSNotificationCenter defaultCenter] removeObserver:self];
[prefs removeObserver:self forKeyPath:SPUseMonospacedFonts];

[self _removePreferenceObservers];

[super dealloc];
}
Expand Down

0 comments on commit 4d450e1

Please sign in to comment.