aboutsummaryrefslogtreecommitdiffstats
path: root/TableDocument.m
diff options
context:
space:
mode:
authormltownsend <mltownsend@gmail.com>2008-11-04 05:20:06 +0000
committermltownsend <mltownsend@gmail.com>2008-11-04 05:20:06 +0000
commit3e703c2a782dc56a03e080b5422b317d150bf482 (patch)
tree2cd0845e98c1394f177c5809da24c7b273ec30af /TableDocument.m
parent02d6b66ebe7d725faf932b62762db315ce89d448 (diff)
downloadsequelpro-3e703c2a782dc56a03e080b5422b317d150bf482.tar.gz
sequelpro-3e703c2a782dc56a03e080b5422b317d150bf482.tar.bz2
sequelpro-3e703c2a782dc56a03e080b5422b317d150bf482.zip
Fix for Issue 66
Diffstat (limited to 'TableDocument.m')
-rw-r--r--TableDocument.m159
1 files changed, 90 insertions, 69 deletions
diff --git a/TableDocument.m b/TableDocument.m
index 5ecc75b2..5c93c09f 100644
--- a/TableDocument.m
+++ b/TableDocument.m
@@ -99,8 +99,6 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa
*/
- (IBAction)connectToDB:(id)sender
{
- CMMCPResult *theResult;
- id version;
// load the details of the curretnly selected favorite into the text boxes in connect sheet
[self chooseFavorite:self];
@@ -109,12 +107,74 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa
[NSApp beginSheet:connectSheet
modalForWindow:tableWindow
modalDelegate:self
- didEndSelector:nil
+ didEndSelector:@selector(connectSheetDidEnd:returnCode:contextInfo:)
contextInfo:nil];
- int code = [NSApp runModalForWindow:connectSheet];
+}
- [NSApp endSheet:connectSheet];
+
+/*
+invoked when user hits the connect-button of the connectSheet
+stops modal session with code:
+1 when connected with success
+2 when no connection to host
+3 when no connection to db
+4 when hostField and socketField are empty
+*/
+- (IBAction)connect:(id)sender
+{
+ int code;
+
+ [connectProgressBar startAnimation:self];
+ [connectProgressStatusText setHidden:NO];
+ [connectProgressStatusText display];
+
+ [selectedDatabase autorelease];
+ selectedDatabase = nil;
+
+ code = 0;
+ if ( [[hostField stringValue] isEqualToString:@""] && [[socketField stringValue] isEqualToString:@""] ) {
+ code = 4;
+ } else {
+ if ( ![[socketField stringValue] isEqualToString:@""] ) {
+ //connect to socket
+ mySQLConnection = [[CMMCPConnection alloc] initToSocket:[socketField stringValue]
+ withLogin:[userField stringValue]
+ password:[passwordField stringValue]];
+ [hostField setStringValue:@"localhost"];
+ } else {
+ //connect to host
+ mySQLConnection = [[CMMCPConnection alloc] initToHost:[hostField stringValue]
+ withLogin:[userField stringValue]
+ password:[passwordField stringValue]
+ usingPort:[portField intValue]];
+ }
+ if ( ![mySQLConnection isConnected] )
+ code = 2;
+ if ( !code && ![[databaseField stringValue] isEqualToString:@""] ) {
+ if ([mySQLConnection selectDB:[databaseField stringValue]]) {
+ selectedDatabase = [[databaseField stringValue] retain];
+ } else {
+ code = 3;
+ }
+ }
+ if ( !code )
+ code = 1;
+ }
+
+ // close sheet
[connectSheet orderOut:nil];
+ [NSApp endSheet:connectSheet returnCode:code];
+// [NSApp stopModalWithCode:code];
+ [connectProgressBar stopAnimation:self];
+ [connectProgressStatusText setHidden:YES];
+}
+
+-(void)connectSheetDidEnd:(NSWindow*)sheet returnCode:(int)code contextInfo:(void*)contextInfo
+{
+ [sheet orderOut:self];
+
+ CMMCPResult *theResult;
+ id version;
if ( code == 1) {
//connected with success
@@ -145,9 +205,9 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa
[tableDumpInstance setConnection:mySQLConnection];
[tableStatusInstance setConnection:mySQLConnection];
[self setFileName:[NSString stringWithFormat:@"(MySQL %@) %@@%@ %@", mySQLVersion, [userField stringValue],
- [hostField stringValue], [databaseField stringValue]]];
+ [hostField stringValue], [databaseField stringValue]]];
[tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@@%@/%@", mySQLVersion, [userField stringValue],
- [hostField stringValue], [databaseField stringValue]]];
+ [hostField stringValue], [databaseField stringValue]]];
// Connected Growl Notification
[GrowlApplicationBridge notifyWithTitle:@"Connected"
@@ -163,81 +223,32 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa
} else if (code == 2) {
//can't connect to host
NSBeginAlertSheet(NSLocalizedString(@"Connection failed!", @"connection failed"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil,
- @selector(sheetDidEnd:returnCode:contextInfo:), @"connect",
- [NSString stringWithFormat:NSLocalizedString(@"Unable to connect to host %@.\nBe sure that the address is correct and that you have the necessary privileges.\nMySQL said: %@", @"message of panel when connection to host failed"), [hostField stringValue], [mySQLConnection getLastErrorMessage]]);
+ @selector(sheetDidEnd:returnCode:contextInfo:), @"connect",
+ [NSString stringWithFormat:NSLocalizedString(@"Unable to connect to host %@.\nBe sure that the address is correct and that you have the necessary privileges.\nMySQL said: %@", @"message of panel when connection to host failed"), [hostField stringValue], [mySQLConnection getLastErrorMessage]]);
} else if (code == 3) {
//can't connect to db
NSBeginAlertSheet(NSLocalizedString(@"Connection failed!", @"connection failed"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil,
- @selector(sheetDidEnd:returnCode:contextInfo:), @"connect",
- [NSString stringWithFormat:NSLocalizedString(@"Unable to connect to database %@.\nBe sure that the database exists and that you have the necessary privileges.\nMySQL said: %@", @"message of panel when connection to db failed"), [databaseField stringValue], [mySQLConnection getLastErrorMessage]]);
+ @selector(sheetDidEnd:returnCode:contextInfo:), @"connect",
+ [NSString stringWithFormat:NSLocalizedString(@"Unable to connect to database %@.\nBe sure that the database exists and that you have the necessary privileges.\nMySQL said: %@", @"message of panel when connection to db failed"), [databaseField stringValue], [mySQLConnection getLastErrorMessage]]);
} else if (code == 4) {
//no host is given
NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil,
- @selector(sheetDidEnd:returnCode:contextInfo:), @"connect", NSLocalizedString(@"Please enter at least a host or socket.", @"message of panel when host/socket are missing"));
+ @selector(sheetDidEnd:returnCode:contextInfo:), @"connect", NSLocalizedString(@"Please enter at least a host or socket.", @"message of panel when host/socket are missing"));
} else {
//cancel button was pressed
//since the window is getting ready to be toast ignore events for awhile
//so as not to crash, this happens to me when hitten esc key instead of
//cancel button, but with this code it does not crash
- [[NSApplication sharedApplication] discardEventsMatchingMask:NSAnyEventMask
- beforeEvent:[[NSApplication sharedApplication] nextEventMatchingMask:NSLeftMouseDownMask | NSLeftMouseUpMask |NSRightMouseDownMask | NSRightMouseUpMask | NSFlagsChangedMask | NSKeyDownMask | NSKeyUpMask untilDate:[NSDate distantPast] inMode:NSEventTrackingRunLoopMode dequeue:YES]];
- [tableWindow close];
+ // [[NSApplication sharedApplication] discardEventsMatchingMask:NSAnyEventMask
+ // beforeEvent:[[NSApplication sharedApplication] nextEventMatchingMask:NSLeftMouseDownMask | NSLeftMouseUpMask |NSRightMouseDownMask | NSRightMouseUpMask | NSFlagsChangedMask | NSKeyDownMask | NSKeyUpMask untilDate:[NSDate distantPast] inMode:NSEventTrackingRunLoopMode dequeue:YES]];
+ // [tableWindow close];
}
+
}
-/*
-invoked when user hits the connect-button of the connectSheet
-stops modal session with code:
-1 when connected with success
-2 when no connection to host
-3 when no connection to db
-4 when hostField and socketField are empty
-*/
-- (IBAction)connect:(id)sender
+- (IBAction)cancelConnectSheet:(id)sender
{
- int code;
-
- [connectProgressBar startAnimation:self];
- [connectProgressStatusText setHidden:NO];
- [connectProgressStatusText display];
-
- [selectedDatabase autorelease];
- selectedDatabase = nil;
-
- code = 0;
- if ( [[hostField stringValue] isEqualToString:@""] && [[socketField stringValue] isEqualToString:@""] ) {
- code = 4;
- } else {
- if ( ![[socketField stringValue] isEqualToString:@""] ) {
- //connect to socket
- mySQLConnection = [[CMMCPConnection alloc] initToSocket:[socketField stringValue]
- withLogin:[userField stringValue]
- password:[passwordField stringValue]];
- [hostField setStringValue:@"localhost"];
- } else {
- //connect to host
- mySQLConnection = [[CMMCPConnection alloc] initToHost:[hostField stringValue]
- withLogin:[userField stringValue]
- password:[passwordField stringValue]
- usingPort:[portField intValue]];
- }
- if ( ![mySQLConnection isConnected] )
- code = 2;
- if ( !code && ![[databaseField stringValue] isEqualToString:@""] ) {
- if ([mySQLConnection selectDB:[databaseField stringValue]]) {
- selectedDatabase = [[databaseField stringValue] retain];
- } else {
- code = 3;
- }
- }
- if ( !code )
- code = 1;
- }
-
- // close sheet
- [NSApp stopModalWithCode:code];
- [connectProgressBar stopAnimation:self];
- [connectProgressStatusText setHidden:YES];
+ [NSApp endSheet:connectSheet];
}
- (IBAction)closeSheet:(id)sender
@@ -247,7 +258,10 @@ stops modal session with code 0
reused when user hits the close button of the variablseSheet or of the createTableSyntaxSheet
*/
{
- [NSApp stopModalWithCode:0];
+ if (sender != nil) {
+ [NSApp endSheet:[sender window] returnCode:0];
+ }
+
}
/**
@@ -1434,7 +1448,8 @@ sets upt the interface (small fonts)
//set up toolbar
[self setupToolbar];
- [self connectToDB:nil];
+// [self connectToDB:nil];
+ [self performSelector:@selector(connectToDB:) withObject:tableWindow afterDelay:0.0f];
}
- (void)windowWillClose:(NSNotification *)aNotification
@@ -1566,6 +1581,12 @@ invoked when query gave an error
return theValue;
}
+- (IBAction)terminate:(id)sender
+{
+ [[NSApp orderedDocuments] makeObjectsPerformSelector:@selector(cancelConnectSheet:) withObject:nil];
+ [NSApp terminate:sender];
+}
+
- (void)dealloc
{
[chooseDatabaseButton release];