From 23c4d04e433f9eb21872edacc41173e34ec45ac2 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 10 May 2017 23:59:27 +0200 Subject: Change some method calls so the custom query view controller gets notified when the window is about to be closed and can stop a pending UI timer (#2775) --- Source/SPCustomQuery.h | 8 +++----- Source/SPCustomQuery.m | 12 ++++++++++++ Source/SPDatabaseDocument.m | 6 +++--- 3 files changed, 18 insertions(+), 8 deletions(-) (limited to 'Source') diff --git a/Source/SPCustomQuery.h b/Source/SPCustomQuery.h index fe31be6d..7491b304 100644 --- a/Source/SPCustomQuery.h +++ b/Source/SPCustomQuery.h @@ -57,16 +57,14 @@ @class SPMySQLConnection; @class SPMySQLStreamingResultStore; @class SPTextView; - -#ifdef SP_CODA @class SPDatabaseDocument; @class SPTablesList; -#endif + @interface SPCustomQuery : NSObject { - IBOutlet id tableDocumentInstance; - IBOutlet id tablesListInstance; + IBOutlet SPDatabaseDocument *tableDocumentInstance; + IBOutlet SPTablesList *tablesListInstance; #ifndef SP_CODA IBOutlet id queryFavoritesButton; diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m index 3cbd6a4d..c14c275d 100644 --- a/Source/SPCustomQuery.m +++ b/Source/SPCustomQuery.m @@ -70,6 +70,7 @@ - (id)_resultDataItemAtRow:(NSInteger)row columnIndex:(NSUInteger)column preserveNULLs:(BOOL)preserveNULLs asPreview:(BOOL)asPreview; + (NSString *)linkToHelpTopic:(NSString *)aTopic; +- (void)documentWillClose:(NSNotification *)notification; @end @@ -3986,6 +3987,10 @@ selector:@selector(endDocumentTaskForTab:) name:SPDocumentTaskEndNotification object:tableDocumentInstance]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(documentWillClose:) + name:SPDocumentWillCloseNotification + object:tableDocumentInstance]; #ifndef SP_CODA [prefs addObserver:self forKeyPath:SPGlobalResultTableFont options:NSKeyValueObservingOptionNew context:NULL]; @@ -4046,6 +4051,13 @@ return value; } +//this method is called right before the UI objects are deallocated +- (void)documentWillClose:(NSNotification *)notification +{ + // if a result load is in progress we must stop the timer or it may try to call invalid IBOutlets + [self clearQueryLoadTimer]; +} + #pragma mark - - (void)dealloc diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index d19b3f4c..2581967c 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -6503,6 +6503,9 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; - (void)dealloc { NSAssert([NSThread isMainThread], @"Calling %s from a background thread is not supported!", __func__); + + // Tell listeners that this database document is being closed - fixes retain cycles and allows cleanup + [[NSNotificationCenter defaultCenter] postNotificationName:SPDocumentWillCloseNotification object:self]; // Unregister observers [self _removePreferenceObservers]; @@ -6517,9 +6520,6 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; for (id retainedObject in nibObjectsToRelease) [retainedObject release]; SPClear(nibObjectsToRelease); - - // Tell listeners that this database document is being closed - fixes retain cycles and allows cleanup - [[NSNotificationCenter defaultCenter] postNotificationName:SPDocumentWillCloseNotification object:self]; SPClear(databaseStructureRetrieval); -- cgit v1.2.3