aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/SPAppController.m66
-rw-r--r--Source/SPWindowController.h2
-rw-r--r--Source/SPWindowController.m9
-rw-r--r--Source/SPWindowManagement.h6
-rw-r--r--Source/SPWindowManagement.m56
5 files changed, 73 insertions, 66 deletions
diff --git a/Source/SPAppController.m b/Source/SPAppController.m
index 85deca6e..87f8350a 100644
--- a/Source/SPAppController.m
+++ b/Source/SPAppController.m
@@ -165,15 +165,15 @@
// If no documents are open, open one
if (![self frontDocument]) {
- [self newWindow:self];
+ SPDatabaseDocument *newConnection = [self makeNewConnectionTabOrWindow];
if (spfDict) {
- [[self frontDocument] setState:spfDict];
+ [newConnection setState:spfDict];
}
// Set autoconnection if appropriate
if ([[NSUserDefaults standardUserDefaults] boolForKey:SPAutoConnectToDefault]) {
- [[self frontDocument] connect];
+ [newConnection connect];
}
}
}
@@ -181,30 +181,13 @@
- (void)externalApplicationWantsToOpenADatabaseConnection:(NSNotification *)notification
{
- SPWindowController *frontController = nil;
-
- for (NSWindow *aWindow in [NSApp orderedWindows]) {
- if ([[aWindow windowController] isMemberOfClass:[SPWindowController class]]) {
- frontController = [aWindow windowController];
- break;
- }
- }
-
- // If no window was found or the front most window has no tabs, create a new one
- if (!frontController || [[frontController valueForKeyPath:@"tabView"] numberOfTabViewItems] == 1) {
- [self newWindow:self];
- // Open the spf file in a new tab if the tab bar is visible
- } else if ([[frontController valueForKeyPath:@"tabView"] numberOfTabViewItems] != 1) {
- if ([[frontController window] isMiniaturized]) [[frontController window] deminiaturize:self];
- [frontController addNewConnection:self];
- }
-
NSDictionary *userInfo = [notification userInfo];
NSString *MAMP_SPFVersion = [userInfo objectForKey:@"dataVersion"];
if ([MAMP_SPFVersion isEqualToString:@"1"]) {
NSDictionary *spfStructure = [userInfo objectForKey:@"spfData"];
if (spfStructure) {
- [[self frontDocument] setState:spfStructure];
+ SPDatabaseDocument *frontDoc = [self makeNewConnectionTabOrWindow];
+ [frontDoc setState:spfStructure];
}
}
}
@@ -406,20 +389,21 @@
[[NSUserDefaults standardUserDefaults] setInteger:[[encodingPopUp selectedItem] tag] forKey:SPLastSQLFileEncoding];
}
+ SPDatabaseDocument *frontDocument = [self frontDocument];
// Check if at least one document exists. If not, open one.
- if (![self frontDocument]) {
- [self newWindow:self];
- [[self frontDocument] initQueryEditorWithString:sqlString];
+ if (!frontDocument) {
+ frontDocument = [self makeNewConnectionTabOrWindow];
+ [frontDocument initQueryEditorWithString:sqlString];
}
else {
// Pass query to the Query editor of the current document
- [[self frontDocument] doPerformLoadQueryService:sqlString];
+ [frontDocument doPerformLoadQueryService:sqlString];
}
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[NSURL fileURLWithPath:filePath]];
- [[self frontDocument] setSqlFileURL:[NSURL fileURLWithPath:filePath]];
- [[self frontDocument] setSqlFileEncoding:sqlEncoding];
+ [frontDocument setSqlFileURL:[NSURL fileURLWithPath:filePath]];
+ [frontDocument setSqlFileEncoding:sqlEncoding];
break; // open only the first SQL file
@@ -436,17 +420,9 @@
}
}
- // If no window was found or the front most window has no tabs, create a new one
- if (!frontController || [[frontController valueForKeyPath:@"tabView"] numberOfTabViewItems] == 1) {
- [self newWindow:self];
- // Open the spf file in a new tab if the tab bar is visible
- }
- else if ([[frontController valueForKeyPath:@"tabView"] numberOfTabViewItems] != 1) {
- if ([[frontController window] isMiniaturized]) [[frontController window] deminiaturize:self];
- [frontController addNewConnection:self];
- }
+ SPDatabaseDocument *frontDocument = [self makeNewConnectionTabOrWindow];
- [[self frontDocument] setStateFromConnectionFile:filePath];
+ [frontDocument setStateFromConnectionFile:filePath];
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[NSURL fileURLWithPath:filePath]];
}
@@ -861,7 +837,7 @@
return;
}
- NSString *activeProcessID = [[(SPWindowController *)[[self frontDocumentWindow] delegate] selectedTableDocument] processID];
+ NSString *activeProcessID = [[self frontDocument] processID];
SPDatabaseDocument *processDocument = nil;
@@ -869,7 +845,7 @@
// For speed check the front most first otherwise iterate through all
if(passedProcessID && [passedProcessID length]) {
if([activeProcessID isEqualToString:passedProcessID]) {
- processDocument = [(SPWindowController *)[[self frontDocumentWindow] delegate] selectedTableDocument];
+ processDocument = [self frontDocument];
} else {
for (NSWindow *aWindow in [NSApp orderedWindows]) {
if([[aWindow windowController] isMemberOfClass:[SPWindowController class]]) {
@@ -888,7 +864,7 @@
// if no processDoc found and no passedProcessID was passed execute
// command at front most doc
if(!processDocument && !passedProcessID)
- processDocument = [(SPWindowController *)[[self frontDocumentWindow] delegate] selectedTableDocument];
+ processDocument = [self frontDocument];
if(processDocument && command) {
if([command isEqualToString:@"passToDoc"]) {
@@ -1383,13 +1359,7 @@
*/
- (SPDatabaseDocument *) frontDocument
{
- for (NSWindow *aWindow in [NSApp orderedWindows]) {
- if ([[aWindow windowController] isMemberOfClass:[SPWindowController class]]) {
- return [[aWindow windowController] selectedTableDocument];
- }
- }
-
- return nil;
+ return [[self frontController] selectedTableDocument];
}
/**
diff --git a/Source/SPWindowController.h b/Source/SPWindowController.h
index a86a85f9..528c1c84 100644
--- a/Source/SPWindowController.h
+++ b/Source/SPWindowController.h
@@ -50,6 +50,8 @@
- (IBAction)addNewConnection:(id)sender;
- (IBAction)moveSelectedTabInNewWindow:(id)sender;
+- (SPDatabaseDocument *)addNewConnection;
+
/**
* @danger THIS IS NOT RETAINED!!!
*
diff --git a/Source/SPWindowController.m b/Source/SPWindowController.m
index 68c89ad8..963919d0 100644
--- a/Source/SPWindowController.m
+++ b/Source/SPWindowController.m
@@ -104,6 +104,11 @@ enum {
*/
- (IBAction)addNewConnection:(id)sender
{
+ [self addNewConnection];
+}
+
+- (SPDatabaseDocument *)addNewConnection
+{
// Create a new database connection view
SPDatabaseDocument *newTableDocument = [[SPDatabaseDocument alloc] init];
@@ -125,8 +130,8 @@ enum {
// Bind the tab bar's progress display to the document
[self _updateProgressIndicatorForItem:newItem];
-
- [newTableDocument release];
+
+ return [newTableDocument autorelease];
}
/**
diff --git a/Source/SPWindowManagement.h b/Source/SPWindowManagement.h
index 66f65b6d..4d32d6d4 100644
--- a/Source/SPWindowManagement.h
+++ b/Source/SPWindowManagement.h
@@ -30,6 +30,8 @@
#import "SPAppController.h"
+@class SPWindowController;
+
/**
* @category SPWindowManagement SPWindowManagement.h
*
@@ -43,6 +45,10 @@
- (IBAction)newTab:(id)sender;
- (IBAction)duplicateTab:(id)sender;
+- (SPWindowController *)newWindow;
+- (SPDatabaseDocument *)makeNewConnectionTabOrWindow;
+- (SPWindowController *)frontController;
+
- (NSWindow *)frontDocumentWindow;
- (void)tabDragStarted:(id)sender;
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,7 +149,7 @@
[frontState setObject:@YES forKey:@"auto_connect"];
// Set the connection on the new tab
- [[self frontDocument] setState:frontState];
+ [newConnection setState:frontState];
}
/**
@@ -138,12 +157,17 @@
*/
- (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;
}