aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStuart Connolly <stuart02@gmail.com>2017-03-24 22:21:56 +0000
committerStuart Connolly <stuart02@gmail.com>2017-03-24 22:21:56 +0000
commit4d450e171fe429a5375c95dbc8372853a910c681 (patch)
tree09eaf7cdeb590ef285a370682e32271a9b5769b4
parent4a186517155223c48255e9952d002f465c567626 (diff)
downloadsequelpro-4d450e171fe429a5375c95dbc8372853a910c681.tar.gz
sequelpro-4d450e171fe429a5375c95dbc8372853a910c681.tar.bz2
sequelpro-4d450e171fe429a5375c95dbc8372853a910c681.zip
Fix crashes on tab/window closing due to previously registed preference observers not being removed.
-rw-r--r--Source/SPDatabaseDocument.m5
-rw-r--r--Source/SPTableTriggers.m29
2 files changed, 28 insertions, 6 deletions
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m
index 50993583..08b2737d 100644
--- a/Source/SPDatabaseDocument.m
+++ b/Source/SPDatabaseDocument.m
@@ -6435,7 +6435,6 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0;
[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 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0;
[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];
diff --git a/Source/SPTableTriggers.m b/Source/SPTableTriggers.m
index 02a7503a..23911279 100644
--- a/Source/SPTableTriggers.m
+++ b/Source/SPTableTriggers.m
@@ -68,6 +68,8 @@ static SPTriggerEventTag TagForEvent(NSString *mysql);
- (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 @@ static SPTriggerEventTag TagForEvent(NSString *mysql);
[[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 @@ static SPTriggerEventTag TagForEvent(NSString *mysql);
[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 @@ static SPTriggerEventTag TagForEvent(NSString *mysql);
SPClear(editedTrigger);
[[NSNotificationCenter defaultCenter] removeObserver:self];
- [prefs removeObserver:self forKeyPath:SPUseMonospacedFonts];
+
+ [self _removePreferenceObservers];
[super dealloc];
}