Skip to content

Commit

Permalink
Change some method calls so the custom query view controller gets not…
Browse files Browse the repository at this point in the history
…ified when the window is about to be closed and can stop a pending UI timer (#2775)
  • Loading branch information
dmoagx committed May 10, 2017
1 parent 9d8926a commit 23c4d04
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
8 changes: 3 additions & 5 deletions Source/SPCustomQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,14 @@
@class SPMySQLConnection;
@class SPMySQLStreamingResultStore;
@class SPTextView;

#ifdef SP_CODA
@class SPDatabaseDocument;
@class SPTablesList;
#endif


@interface SPCustomQuery : NSObject <NSTableViewDataSource, NSWindowDelegate, NSTableViewDelegate, SPDatabaseContentViewDelegate>
{
IBOutlet id tableDocumentInstance;
IBOutlet id tablesListInstance;
IBOutlet SPDatabaseDocument *tableDocumentInstance;
IBOutlet SPTablesList *tablesListInstance;

#ifndef SP_CODA
IBOutlet id queryFavoritesButton;
Expand Down
12 changes: 12 additions & 0 deletions Source/SPCustomQuery.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ @interface SPCustomQuery (PrivateAPI)

- (id)_resultDataItemAtRow:(NSInteger)row columnIndex:(NSUInteger)column preserveNULLs:(BOOL)preserveNULLs asPreview:(BOOL)asPreview;
+ (NSString *)linkToHelpTopic:(NSString *)aTopic;
- (void)documentWillClose:(NSNotification *)notification;

@end

Expand Down Expand Up @@ -3986,6 +3987,10 @@ - (void)awakeFromNib
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];
Expand Down Expand Up @@ -4046,6 +4051,13 @@ - (id)_resultDataItemAtRow:(NSInteger)row columnIndex:(NSUInteger)column preserv
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
Expand Down
6 changes: 3 additions & 3 deletions Source/SPDatabaseDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -6503,6 +6503,9 @@ - (void)_removePreferenceObservers
- (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];
Expand All @@ -6517,9 +6520,6 @@ - (void)dealloc
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);

Expand Down

0 comments on commit 23c4d04

Please sign in to comment.