From 5cd12392fa26ab93303b6b6b43de5a1a31a834f7 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 6 Nov 2015 00:26:12 +0100 Subject: * Change window creation to use a create-and-get model instead of create-then-get as that did cause problems on 10.11 in some cases (#2294) backport of ea1d72868aabba227aa608a2a89079aa12ac70a1 --- Source/SPWindowManagement.m | 56 ++++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 16 deletions(-) (limited to 'Source/SPWindowManagement.m') diff --git a/Source/SPWindowManagement.m b/Source/SPWindowManagement.m index c30a2826..6225c52f 100644 --- a/Source/SPWindowManagement.m +++ b/Source/SPWindowManagement.m @@ -32,10 +32,16 @@ @implementation SPAppController (SPWindowManagement) + +- (IBAction)newWindow:(id)sender +{ + [self newWindow]; +} + /** * Create a new window, containing a single tab. */ -- (IBAction)newWindow:(id)sender +- (SPWindowController *)newWindow { static NSPoint cascadeLocation = {.x = 0, .y = 0}; @@ -58,7 +64,7 @@ } // Add the connection view - [newWindowController addNewConnection:self]; + [newWindowController addNewConnection]; // Cascade according to the statically stored cascade location. cascadeLocation = [newWindow cascadeTopLeftFromPoint:cascadeLocation]; @@ -69,6 +75,8 @@ // Show the window, and perform frontmost tasks again once the window has drawn [newWindowController showWindow:self]; [[newWindowController selectedTableDocument] didBecomeActiveTabInWindow]; + + return newWindowController; } /** @@ -76,15 +84,7 @@ */ - (IBAction)newTab:(id)sender { - SPWindowController *frontController = nil; - - for (NSWindow *aWindow in [NSApp orderedWindows]) - { - if ([[aWindow windowController] isMemberOfClass:[SPWindowController class]]) { - frontController = [aWindow windowController]; - break; - } - } + SPWindowController *frontController = [self frontController]; // If no window was found, create a new one if (!frontController) { @@ -99,6 +99,25 @@ } } +- (SPDatabaseDocument *)makeNewConnectionTabOrWindow +{ + SPWindowController *frontController = [self frontController]; + + SPDatabaseDocument *frontDocument; + // If no window was found or the front most window has no tabs, create a new one + if (!frontController || [[frontController valueForKeyPath:@"tabView"] numberOfTabViewItems] == 1) { + frontController = [self newWindow]; + frontDocument = [frontController selectedTableDocument]; + } + // Open the spf file in a new tab if the tab bar is visible + else { + if ([[frontController window] isMiniaturized]) [[frontController window] deminiaturize:self]; + frontDocument = [frontController addNewConnection]; + } + + return frontDocument; +} + /** * Duplicate the current connection tab */ @@ -113,7 +132,7 @@ [[self frontDocumentWindow] deminiaturize:self]; } - [[[self frontDocumentWindow] windowController] addNewConnection:self]; + SPDatabaseDocument *newConnection = [[self frontController] addNewConnection]; // Get the state of the previously-frontmost document NSDictionary *allStateDetails = @{ @@ -130,20 +149,25 @@ [frontState setObject:@YES forKey:@"auto_connect"]; // Set the connection on the new tab - [[self frontDocument] setState:frontState]; + [newConnection setState:frontState]; } /** * Retrieve the frontmost document window; returns nil if not found. */ - (NSWindow *)frontDocumentWindow +{ + return [[self frontController] window]; +} + +- (SPWindowController *)frontController { for (NSWindow *aWindow in [NSApp orderedWindows]) { - if ([[aWindow windowController] isMemberOfClass:[SPWindowController class]]) { - return aWindow; + id ctr = [aWindow windowController]; + if ([ctr isMemberOfClass:[SPWindowController class]]) { + return ctr; } } - return nil; } -- cgit v1.2.3