From 3e703c2a782dc56a03e080b5422b317d150bf482 Mon Sep 17 00:00:00 2001 From: mltownsend Date: Tue, 4 Nov 2008 05:20:06 +0000 Subject: Fix for Issue 66 --- English.lproj/DBView.xib | 60 ++++++++++------- English.lproj/MainMenu.xib | 30 ++++----- TableDocument.h | 1 + TableDocument.m | 159 +++++++++++++++++++++++++-------------------- 4 files changed, 141 insertions(+), 109 deletions(-) diff --git a/English.lproj/DBView.xib b/English.lproj/DBView.xib index 63c2f912..161501a0 100644 --- a/English.lproj/DBView.xib +++ b/English.lproj/DBView.xib @@ -3,13 +3,13 @@ 1050 9F33 - 670 + 672 949.34 352.00 YES - - + + YES @@ -8785,14 +8785,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 117 - - - closeSheet: - - - - 118 - dataSource @@ -10717,6 +10709,22 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 4525 + + + cancelConnectSheet: + + + + 4526 + + + + delegate + + + + 4528 + @@ -16279,7 +16287,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {{387, 725}, {432, 282}} {{387, 725}, {432, 282}} - + {3.40282e+38, 3.40282e+38} {350, 250} @@ -16691,7 +16699,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin - + {3.40282e+38, 3.40282e+38} {213, 107} @@ -16775,7 +16783,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {{99, 63}, {519, 335}} {{136, 447}, {519, 335}} - + {3.40282e+38, 3.40282e+38} {256, 191} @@ -16859,7 +16867,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {{115, 214}, {588, 350}} {{115, 214}, {588, 350}} - + {3.40282e+38, 3.40282e+38} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -16880,7 +16888,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - + {3.40282e+38, 3.40282e+38} {213, 107} @@ -16957,7 +16965,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {{62, 352}, {845, 504}} - + {3.40282e+38, 3.40282e+38} {780, 480} @@ -16967,7 +16975,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin - + {3.40282e+38, 3.40282e+38} {213, 107} @@ -17015,7 +17023,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin - + {3.40282e+38, 3.40282e+38} {350, 200} @@ -17068,7 +17076,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {{321, 837}, {381, 247}} {{321, 837}, {381, 247}} - + {3.40282e+38, 3.40282e+38} {213, 107} @@ -17078,7 +17086,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin - + {3.40282e+38, 3.40282e+38} {213, 107} @@ -17211,7 +17219,7 @@ Y2hhbmdlIHRoZSBvcmRlcg {{321, 508}, {411, 341}} {{321, 508}, {411, 341}} - + {3.40282e+38, 3.40282e+38} {300, 200} @@ -17309,7 +17317,7 @@ Y2hhbmdlIHRoZSBvcmRlcg com.apple.InterfaceBuilder.CocoaPlugin - + {3.40282e+38, 3.40282e+38} {213, 107} @@ -17325,7 +17333,7 @@ Y2hhbmdlIHRoZSBvcmRlcg com.apple.InterfaceBuilder.CocoaPlugin - + {3.40282e+38, 3.40282e+38} {213, 50} @@ -17407,7 +17415,7 @@ Y2hhbmdlIHRoZSBvcmRlcg - 4525 + 4528 @@ -17712,6 +17720,7 @@ Y2hhbmdlIHRoZSBvcmRlcg YES addDatabase: analyzeTable: + cancelConnectSheet: checkTable: checksumTable: chooseDatabase: @@ -17777,6 +17786,7 @@ Y2hhbmdlIHRoZSBvcmRlcg id id id + id diff --git a/English.lproj/MainMenu.xib b/English.lproj/MainMenu.xib index 4d343708..7dc4e9d7 100644 --- a/English.lproj/MainMenu.xib +++ b/English.lproj/MainMenu.xib @@ -3,12 +3,12 @@ 1050 9F33 - 670 + 672 949.34 352.00 YES - + YES @@ -2881,14 +2881,6 @@ 122 - - - terminate: - - - - 139 - orderFrontStandardAboutPanel: @@ -3825,6 +3817,14 @@ 809 + + + terminate: + + + + 810 + @@ -6407,7 +6407,7 @@ {{59, 583}, {710, 292}} {{59, 583}, {710, 292}} - + {3.40282e+38, 3.40282e+38} {213, 107} @@ -6504,7 +6504,7 @@ Y2hhbmdlIHRoZSBvcmRlcg {{828, 556}, {278, 365}} {{828, 556}, {278, 365}} - + {3.40282e+38, 3.40282e+38} {213, 107} @@ -6568,7 +6568,7 @@ Y2hhbmdlIHRoZSBvcmRlcg com.apple.InterfaceBuilder.CocoaPlugin - {{131, 483}, {511, 20}} + {{123, 602}, {511, 20}} com.apple.InterfaceBuilder.CocoaPlugin {{506, 836}, {511, 20}} @@ -6763,7 +6763,7 @@ Y2hhbmdlIHRoZSBvcmRlcg com.apple.InterfaceBuilder.CocoaPlugin - {{122, 334}, {218, 253}} + {{135, 349}, {218, 253}} com.apple.InterfaceBuilder.CocoaPlugin {{518, 583}, {218, 253}} @@ -6924,7 +6924,7 @@ Y2hhbmdlIHRoZSBvcmRlcg - 809 + 810 diff --git a/TableDocument.h b/TableDocument.h index 5ade5ec1..aed99756 100644 --- a/TableDocument.h +++ b/TableDocument.h @@ -96,6 +96,7 @@ //start sheet - (IBAction)connectToDB:(id)sender; - (IBAction)connect:(id)sender; +- (IBAction)cancelConnectSheet:(id)sender; - (IBAction)closeSheet:(id)sender; - (IBAction)chooseFavorite:(id)sender; - (id)selectedFavorite; 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]; -- cgit v1.2.3