diff options
author | Max <post@wickenrode.com> | 2015-10-18 09:03:18 +0200 |
---|---|---|
committer | Max <post@wickenrode.com> | 2015-10-18 09:03:18 +0200 |
commit | ba5b71d5bb64fdc40a4a9eaeb7867fdaea8a1673 (patch) | |
tree | 1cb4bf35415923cb53247fcbb1b68c08a3d59a46 /Source/SPWindowController.m | |
parent | bc61f825d02eac931b0bbfdebacc4ccb320a9237 (diff) | |
download | sequelpro-ba5b71d5bb64fdc40a4a9eaeb7867fdaea8a1673.tar.gz sequelpro-ba5b71d5bb64fdc40a4a9eaeb7867fdaea8a1673.tar.bz2 sequelpro-ba5b71d5bb64fdc40a4a9eaeb7867fdaea8a1673.zip |
Fix a crash that could happen when exiting fullscreen mode on 10.11
(backport of d4641ec90fe1b50fca0256e26338d955290fd8b7)
Diffstat (limited to 'Source/SPWindowController.m')
-rw-r--r-- | Source/SPWindowController.m | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/Source/SPWindowController.m b/Source/SPWindowController.m index db94f5ce..68c89ad8 100644 --- a/Source/SPWindowController.m +++ b/Source/SPWindowController.m @@ -53,7 +53,8 @@ enum { - (void)_updateProgressIndicatorForItem:(NSTabViewItem *)theItem; - (void)_createTitleBarLineHidingView; - (void)_updateLineHidingViewState; - +- (void)_switchOutSelectedTableDocument:(SPDatabaseDocument *)newDoc; +- (void)_selectedTableDocumentDeallocd:(NSNotification *)notification; @end @implementation SPWindowController @@ -63,7 +64,7 @@ enum { - (void)awakeFromNib { - selectedTableDocument = nil; + [self _switchOutSelectedTableDocument:nil]; [[self window] setCollectionBehavior:[[self window] collectionBehavior] | NSWindowCollectionBehaviorFullScreenPrimary]; @@ -141,7 +142,7 @@ enum { */ - (void)updateSelectedTableDocument { - selectedTableDocument = [[tabView selectedTabViewItem] identifier]; + [self _switchOutSelectedTableDocument:[[tabView selectedTabViewItem] identifier]]; [selectedTableDocument didBecomeActiveTabInWindow]; } @@ -388,7 +389,7 @@ enum { */ - (BOOL)respondsToSelector:(SEL)theSelector { - return ([super respondsToSelector:theSelector] || (selectedTableDocument && [selectedTableDocument respondsToSelector:theSelector])); + return ([super respondsToSelector:theSelector] || [selectedTableDocument respondsToSelector:theSelector]); } /** @@ -529,10 +530,35 @@ enum { } } + +- (void)_switchOutSelectedTableDocument:(SPDatabaseDocument *)newDoc +{ + NSAssert([NSThread isMainThread], @"Switching the selectedTableDocument via a background thread is not supported!"); + + // shortcut if there is nothing to do + if(selectedTableDocument == newDoc) return; + + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + if(selectedTableDocument) { + [nc removeObserver:self name:SPDocumentWillCloseNotification object:selectedTableDocument]; + selectedTableDocument = nil; + } + if(newDoc) { + [nc addObserver:self selector:@selector(_selectedTableDocumentDeallocd:) name:SPDocumentWillCloseNotification object:newDoc]; + selectedTableDocument = newDoc; + } +} + +- (void)_selectedTableDocumentDeallocd:(NSNotification *)notification +{ + [self _switchOutSelectedTableDocument:nil]; +} + #pragma mark - - (void)dealloc { + [self _switchOutSelectedTableDocument:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self]; [NSObject cancelPreviousPerformRequestsWithTarget:self]; |