diff options
author | stuconnolly <stuart02@gmail.com> | 2009-04-09 19:42:43 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2009-04-09 19:42:43 +0000 |
commit | ddc5add77f3984cae1601e96d564cf4ba7347202 (patch) | |
tree | ee4abe583c219dd26f3e9a1a98b5e6e03b2a53e1 | |
parent | 723c6fe23c8d5f35c19ad858c51cf0577fb1ab5f (diff) | |
download | sequelpro-ddc5add77f3984cae1601e96d564cf4ba7347202.tar.gz sequelpro-ddc5add77f3984cae1601e96d564cf4ba7347202.tar.bz2 sequelpro-ddc5add77f3984cae1601e96d564cf4ba7347202.zip |
Make table operation messages more user friendly (issue #192) and display them in sheets instead of modal dialogs. Also performed a general tidy up of TableDocument.[hm].
-rw-r--r-- | Interfaces/English.lproj/MainMenu.xib | 170 | ||||
-rw-r--r-- | Source/TableDocument.h | 24 | ||||
-rw-r--r-- | Source/TableDocument.m | 377 |
3 files changed, 345 insertions, 226 deletions
diff --git a/Interfaces/English.lproj/MainMenu.xib b/Interfaces/English.lproj/MainMenu.xib index ceec55a8..ed5a59d3 100644 --- a/Interfaces/English.lproj/MainMenu.xib +++ b/Interfaces/English.lproj/MainMenu.xib @@ -2,13 +2,13 @@ <archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.03"> <data> <int key="IBDocument.SystemTarget">1050</int> - <string key="IBDocument.SystemVersion">9G2141</string> + <string key="IBDocument.SystemVersion">9G55</string> <string key="IBDocument.InterfaceBuilderVersion">677</string> <string key="IBDocument.AppKitVersion">949.43</string> <string key="IBDocument.HIToolboxVersion">353.00</string> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> - <integer value="846"/> + <integer value="758"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -1388,27 +1388,37 @@ <reference key="NSOnImage" ref="625762401"/> <reference key="NSMixedImage" ref="315854375"/> </object> - <object class="NSMenuItem" id="587676764"> + <object class="NSMenuItem" id="149240322"> <reference key="NSMenu" ref="1056168652"/> - <string key="NSTitle">Analyze Table</string> + <string key="NSTitle">Repair Table</string> <string key="NSKeyEquiv"/> <int key="NSKeyEquivModMask">1048576</int> <int key="NSMnemonicLoc">2147483647</int> <reference key="NSOnImage" ref="625762401"/> <reference key="NSMixedImage" ref="315854375"/> </object> - <object class="NSMenuItem" id="384546710"> + <object class="NSMenuItem" id="922984138"> <reference key="NSMenu" ref="1056168652"/> - <string key="NSTitle">Optimize Table</string> + <bool key="NSIsDisabled">YES</bool> + <bool key="NSIsSeparator">YES</bool> + <string key="NSTitle"/> + <string key="NSKeyEquiv"/> + <int key="NSMnemonicLoc">2147483647</int> + <reference key="NSOnImage" ref="625762401"/> + <reference key="NSMixedImage" ref="315854375"/> + </object> + <object class="NSMenuItem" id="587676764"> + <reference key="NSMenu" ref="1056168652"/> + <string key="NSTitle">Analyze Table</string> <string key="NSKeyEquiv"/> <int key="NSKeyEquivModMask">1048576</int> <int key="NSMnemonicLoc">2147483647</int> <reference key="NSOnImage" ref="625762401"/> <reference key="NSMixedImage" ref="315854375"/> </object> - <object class="NSMenuItem" id="149240322"> + <object class="NSMenuItem" id="384546710"> <reference key="NSMenu" ref="1056168652"/> - <string key="NSTitle">Repair Table</string> + <string key="NSTitle">Optimize Table</string> <string key="NSKeyEquiv"/> <int key="NSKeyEquivModMask">1048576</int> <int key="NSMnemonicLoc">2147483647</int> @@ -5838,63 +5848,6 @@ ARcABAAAAAEAAAACARwAAwAAAAEAAQAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA</bytes> <reference key="parent" ref="171386461"/> </object> <object class="IBObjectRecord"> - <int key="objectID">758</int> - <reference key="object" ref="1056168652"/> - <object class="NSMutableArray" key="children"> - <bool key="EncodedWithXMLCoder">YES</bool> - <reference ref="449401330"/> - <reference ref="785987636"/> - <reference ref="587676764"/> - <reference ref="384546710"/> - <reference ref="149240322"/> - <reference ref="309258449"/> - <reference ref="336993056"/> - <reference ref="638185532"/> - <reference ref="712078058"/> - </object> - <reference key="parent" ref="228261277"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">759</int> - <reference key="object" ref="449401330"/> - <reference key="parent" ref="1056168652"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">760</int> - <reference key="object" ref="785987636"/> - <reference key="parent" ref="1056168652"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">761</int> - <reference key="object" ref="587676764"/> - <reference key="parent" ref="1056168652"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">762</int> - <reference key="object" ref="384546710"/> - <reference key="parent" ref="1056168652"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">763</int> - <reference key="object" ref="149240322"/> - <reference key="parent" ref="1056168652"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">764</int> - <reference key="object" ref="309258449"/> - <reference key="parent" ref="1056168652"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">765</int> - <reference key="object" ref="336993056"/> - <reference key="parent" ref="1056168652"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">778</int> - <reference key="object" ref="638185532"/> - <reference key="parent" ref="1056168652"/> - </object> - <object class="IBObjectRecord"> <int key="objectID">782</int> <reference key="object" ref="822553772"/> <reference key="parent" ref="172963563"/> @@ -5935,11 +5888,6 @@ ARcABAAAAAEAAAACARwAAwAAAAEAAQAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA</bytes> <reference key="parent" ref="201414690"/> </object> <object class="IBObjectRecord"> - <int key="objectID">797</int> - <reference key="object" ref="712078058"/> - <reference key="parent" ref="1056168652"/> - </object> - <object class="IBObjectRecord"> <int key="objectID">805</int> <reference key="object" ref="761247690"/> <reference key="parent" ref="466354362"/> @@ -6326,6 +6274,74 @@ ARcABAAAAAEAAAACARwAAwAAAAEAAQAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA</bytes> <reference key="object" ref="465877627"/> <reference key="parent" ref="71086556"/> </object> + <object class="IBObjectRecord"> + <int key="objectID">758</int> + <reference key="object" ref="1056168652"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="149240322"/> + <reference ref="922984138"/> + <reference ref="712078058"/> + <reference ref="638185532"/> + <reference ref="336993056"/> + <reference ref="309258449"/> + <reference ref="384546710"/> + <reference ref="587676764"/> + <reference ref="785987636"/> + <reference ref="449401330"/> + </object> + <reference key="parent" ref="228261277"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">763</int> + <reference key="object" ref="149240322"/> + <reference key="parent" ref="1056168652"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">906</int> + <reference key="object" ref="922984138"/> + <reference key="parent" ref="1056168652"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">797</int> + <reference key="object" ref="712078058"/> + <reference key="parent" ref="1056168652"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">778</int> + <reference key="object" ref="638185532"/> + <reference key="parent" ref="1056168652"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">765</int> + <reference key="object" ref="336993056"/> + <reference key="parent" ref="1056168652"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">764</int> + <reference key="object" ref="309258449"/> + <reference key="parent" ref="1056168652"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">762</int> + <reference key="object" ref="384546710"/> + <reference key="parent" ref="1056168652"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">761</int> + <reference key="object" ref="587676764"/> + <reference key="parent" ref="1056168652"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">760</int> + <reference key="object" ref="785987636"/> + <reference key="parent" ref="1056168652"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">759</int> + <reference key="object" ref="449401330"/> + <reference key="parent" ref="1056168652"/> + </object> </object> </object> <object class="NSMutableDictionary" key="flattenedProperties"> @@ -6910,6 +6926,7 @@ ARcABAAAAAEAAAACARwAAwAAAAEAAQAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA</bytes> <string>863.IBPluginDependency</string> <string>864.IBPluginDependency</string> <string>865.IBPluginDependency</string> + <string>906.IBPluginDependency</string> <string>92.IBPluginDependency</string> <string>92.ImportedFromIB2</string> </object> @@ -6972,7 +6989,7 @@ ARcABAAAAAEAAAACARwAAwAAAAEAAQAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA</bytes> <reference ref="9"/> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <reference ref="9"/> - <string>{{764, 298}, {146, 213}}</string> + <string>{{677, 298}, {146, 213}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <reference ref="9"/> <string>{{654, 613}, {157, 223}}</string> @@ -7182,7 +7199,7 @@ Y2hhbmdlIHRoZSBvcmRlcg</string> </object> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <reference ref="9"/> - <string>{{616, 511}, {511, 20}}</string> + <string>{{202, 280}, {511, 20}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <reference ref="9"/> <string>{{506, 836}, {511, 20}}</string> @@ -7396,7 +7413,7 @@ Y2hhbmdlIHRoZSBvcmRlcg</string> <reference ref="9"/> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <reference ref="9"/> - <string>{{791, 404}, {231, 153}}</string> + <string>{{444, 127}, {231, 153}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <reference ref="9"/> <string>{{312, 683}, {231, 153}}</string> @@ -7515,7 +7532,7 @@ Y2hhbmdlIHRoZSBvcmRlcg</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <reference ref="9"/> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{872, 384}, {268, 173}}</string> + <string>{{525, 97}, {268, 183}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>{{829, 663}, {268, 173}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> @@ -7570,7 +7587,7 @@ Y2hhbmdlIHRoZSBvcmRlcg</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{910, 228}, {213, 143}}</string> + <string>{{823, 228}, {213, 143}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <object class="NSMutableDictionary"> <string key="NS.key.0">ToolTip</string> @@ -7643,6 +7660,7 @@ w6gg4oaSIGZhY2FkZV0</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <reference ref="9"/> </object> </object> @@ -7666,7 +7684,7 @@ w6gg4oaSIGZhY2FkZV0</string> </object> </object> <nil key="sourceID"/> - <int key="maxID">905</int> + <int key="maxID">907</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> diff --git a/Source/TableDocument.h b/Source/TableDocument.h index 5bb29a9f..299e5430 100644 --- a/Source/TableDocument.h +++ b/Source/TableDocument.h @@ -187,34 +187,10 @@ - (BOOL)validateToolbarItem:(NSToolbarItem *)toolbarItem; - (void)updateChooseDatabaseToolbarItemWidth; -//NSDocument methods -- (NSString *)windowNibName; -- (void)windowControllerDidLoadNib:(NSWindowController *)aController; -- (void)windowWillClose:(NSNotification *)aNotification; - -//NSWindow delegate methods -- (BOOL)windowShouldClose:(id)sender; - //SMySQL delegate methods - (void)willQueryString:(NSString *)query; - (void)queryGaveError:(NSString *)error; -// Connection sheet delegate methods -- (void) controlTextDidChange:(NSNotification *)aNotification; - -//splitView delegate methods -- (BOOL)splitView:(NSSplitView *)sender canCollapseSubview:(NSView *)subview; -- (float)splitView:(NSSplitView *)sender constrainMaxCoordinate:(float)proposedMax ofSubviewAt:(int)offset; -- (float)splitView:(NSSplitView *)sender constrainMinCoordinate:(float)proposedMin ofSubviewAt:(int)offset; -- (NSRect)splitView:(NSSplitView *)splitView additionalEffectiveRectOfDividerAtIndex:(int)dividerIndex; - - -//tableView datasource methods -- (int)numberOfRowsInTableView:(NSTableView *)aTableView; -- (id)tableView:(NSTableView *)aTableView - objectValueForTableColumn:(NSTableColumn *)aTableColumn - row:(int)rowIndex; - @end extern NSString *TableDocumentFavoritesControllerSelectionIndexDidChange; diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 15bc444b..269af5e1 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -42,18 +42,17 @@ #import "CMMCPResult.h" NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocumentFavoritesControllerSelectionIndexDidChange"; -NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFavoritesControllerFavoritesDidChange"; +NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFavoritesControllerFavoritesDidChange"; @implementation TableDocument - (id)init { - if (![super init]) - return nil; - - _encoding = [@"utf8" retain]; - chooseDatabaseButton = nil; - chooseDatabaseToolbarItem = nil; + if ((self = [super init])) { + _encoding = [@"utf8" retain]; + chooseDatabaseButton = nil; + chooseDatabaseToolbarItem = nil; + } return self; } @@ -106,7 +105,6 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa return mySQLConnection; } - //start sheet /** @@ -259,12 +257,12 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa [tableWindow close]; } -- (IBAction)closeSheet:(id)sender -/* - invoked when user hits the cancel button of the connectSheet - stops modal session with code 0 - reused when user hits the close button of the variablseSheet or of the createTableSyntaxSheet +/** + * Invoked when user hits the cancel button of the connectSheet + * stops modal session with code 0 + * reused when user hits the close button of the variablseSheet or of the createTableSyntaxSheet */ +- (IBAction)closeSheet:(id)sender { [NSApp stopModalWithCode:0]; } @@ -819,9 +817,11 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa return _supportsEncoding; } - #pragma mark Table Methods +/** + * Displays the CREATE TABLE syntax of the selected table to the user via a HUD panel. + */ - (IBAction)showCreateTableSyntax:(id)sender { //Create the query and get results @@ -845,6 +845,9 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa [createTableSyntaxWindow makeKeyAndOrderFront:self]; } +/** + * Copies the CREATE TABLE syntax of the selected table to the pasteboard. + */ - (IBAction)copyCreateTableSyntax:(id)sender { // Create the query and get results @@ -875,146 +878,264 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa notificationName:@"Table Syntax Copied"]; } +/** + * Performs a MySQL check table on the selected table and presents the result to the user via an alert sheet. + */ - (IBAction)checkTable:(id)sender -{ - NSString *query; - CMMCPResult *theResult; - NSDictionary *theRow; - - //Create the query and get results - query = [NSString stringWithFormat:@"CHECK TABLE %@", [[self table] backtickQuotedString]]; - theResult = [mySQLConnection queryString:query]; +{ + CMMCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"CHECK TABLE %@", [[self table] backtickQuotedString]]]; // Check for errors, only displaying if the connection hasn't been terminated if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) { if ([mySQLConnection isConnected]) { - NSRunAlertPanel(@"Error", [NSString stringWithFormat:@"An error occured while checking table.\n\n: %@",[mySQLConnection getLastErrorMessage]], @"OK", nil, nil); + + [[NSAlert alertWithMessageText:@"Unable to check table" + defaultButton:@"OK" + alternateButton:nil + otherButton:nil + informativeTextWithFormat:[NSString stringWithFormat:@"An error occurred while trying to check the table '%@'. Please try again.\n\n%@", [self table], [mySQLConnection getLastErrorMessage]]] + beginSheetModalForWindow:tableWindow + modalDelegate:self + didEndSelector:NULL + contextInfo:NULL]; } + return; } // Process result - theRow = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject]; - NSRunInformationalAlertPanel([NSString stringWithFormat:@"Check '%@' table", [self table]], [NSString stringWithFormat:@"Check: %@", [theRow objectForKey:@"Msg_text"]], @"OK", nil, nil); + NSDictionary *result = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject]; + + NSString *message = @""; + + message = ([[result objectForKey:@"Msg_type"] isEqualToString:@"status"]) ? @"Check table successfully passed." : @"Check table failed."; + + message = [NSString stringWithFormat:@"%@\n\nMySQL said: %@", message, [result objectForKey:@"Msg_text"]]; + + [[NSAlert alertWithMessageText:[NSString stringWithFormat:@"Check table '%@'", [self table]] + defaultButton:@"OK" + alternateButton:nil + otherButton:nil + informativeTextWithFormat:message] + beginSheetModalForWindow:tableWindow + modalDelegate:self + didEndSelector:NULL + contextInfo:NULL]; } +/** + * Analyzes the selected table and presents the result to the user via an alert sheet. + */ - (IBAction)analyzeTable:(id)sender { - NSString *query; - CMMCPResult *theResult; - NSDictionary *theRow; - - //Create the query and get results - query = [NSString stringWithFormat:@"ANALYZE TABLE %@", [[self table] backtickQuotedString]]; - theResult = [mySQLConnection queryString:query]; + CMMCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"ANALYZE TABLE %@", [[self table] backtickQuotedString]]]; // Check for errors, only displaying if the connection hasn't been terminated if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) { if ([mySQLConnection isConnected]) { - NSRunAlertPanel(@"Error", [NSString stringWithFormat:@"An error occured while analyzing table.\n\n: %@",[mySQLConnection getLastErrorMessage]], @"OK", nil, nil); + + [[NSAlert alertWithMessageText:@"Unable to analyze table" + defaultButton:@"OK" + alternateButton:nil + otherButton:nil + informativeTextWithFormat:[NSString stringWithFormat:@"An error occurred while trying to analyze the table '%@'. Please try again.\n\n%@", [self table], [mySQLConnection getLastErrorMessage]]] + beginSheetModalForWindow:tableWindow + modalDelegate:self + didEndSelector:NULL + contextInfo:NULL]; } + return; } // Process result - theRow = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject]; - NSRunInformationalAlertPanel([NSString stringWithFormat:@"Analyze '%@' table", [self table]], [NSString stringWithFormat:@"Analyze: %@", [theRow objectForKey:@"Msg_text"]], @"OK", nil, nil); + NSDictionary *result = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject]; + + NSString *message = @""; + + message = ([[result objectForKey:@"Msg_type"] isEqualToString:@"status"]) ? @"Successfully analyzed table" : @"Analyze table failed."; + + message = [NSString stringWithFormat:@"%@\n\nMySQL said: %@", message, [result objectForKey:@"Msg_text"]]; + + [[NSAlert alertWithMessageText:[NSString stringWithFormat:@"Analyze table '%@'", [self table]] + defaultButton:@"OK" + alternateButton:nil + otherButton:nil + informativeTextWithFormat:message] + beginSheetModalForWindow:tableWindow + modalDelegate:self + didEndSelector:NULL + contextInfo:NULL]; } +/** + * Optimizes the selected table and presents the result to the user via an alert sheet. + */ - (IBAction)optimizeTable:(id)sender { - NSString *query; - CMMCPResult *theResult; - NSDictionary *theRow; - - //Create the query and get results - query = [NSString stringWithFormat:@"OPTIMIZE TABLE %@", [[self table] backtickQuotedString]]; - theResult = [mySQLConnection queryString:query]; + CMMCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"OPTIMIZE TABLE %@", [[self table] backtickQuotedString]]]; // Check for errors, only displaying if the connection hasn't been terminated - if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) { + if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) { if ([mySQLConnection isConnected]) { - NSRunAlertPanel(@"Error", [NSString stringWithFormat:@"An error occured while optimizing table.\n\n: %@",[mySQLConnection getLastErrorMessage]], @"OK", nil, nil); + + [[NSAlert alertWithMessageText:@"Unable to optimize table" + defaultButton:@"OK" + alternateButton:nil + otherButton:nil + informativeTextWithFormat:[NSString stringWithFormat:@"An error occurred while trying to optimize the table '%@'. Please try again.\n\n%@", [self table], [mySQLConnection getLastErrorMessage]]] + beginSheetModalForWindow:tableWindow + modalDelegate:self + didEndSelector:NULL + contextInfo:NULL]; } + return; } // Process result - theRow = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject]; - NSRunInformationalAlertPanel([NSString stringWithFormat:@"Optimize '%@' table", [self table]], [NSString stringWithFormat:@"Optimize: %@", [theRow objectForKey:@"Msg_text"]], @"OK", nil, nil); + NSDictionary *result = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject]; + + NSString *message = @""; + + message = ([[result objectForKey:@"Msg_type"] isEqualToString:@"status"]) ? @"Successfully optimized table" : @"Optimize table failed."; + + message = [NSString stringWithFormat:@"%@\n\nMySQL said: %@", message, [result objectForKey:@"Msg_text"]]; + + [[NSAlert alertWithMessageText:[NSString stringWithFormat:@"Optimize table '%@'", [self table]] + defaultButton:@"OK" + alternateButton:nil + otherButton:nil + informativeTextWithFormat:message] + beginSheetModalForWindow:tableWindow + modalDelegate:self + didEndSelector:NULL + contextInfo:NULL]; } +/** + * Repairs the selected table and presents the result to the user via an alert sheet. + */ - (IBAction)repairTable:(id)sender { - NSString *query; - CMMCPResult *theResult; - NSDictionary *theRow; - - //Create the query and get results - query = [NSString stringWithFormat:@"REPAIR TABLE %@", [[self table] backtickQuotedString]]; - theResult = [mySQLConnection queryString:query]; + CMMCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"REPAIR TABLE %@", [[self table] backtickQuotedString]]]; // Check for errors, only displaying if the connection hasn't been terminated if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) { if ([mySQLConnection isConnected]) { - NSRunAlertPanel(@"Error", [NSString stringWithFormat:@"An error occured while repairing table.\n\n: %@",[mySQLConnection getLastErrorMessage]], @"OK", nil, nil); + + [[NSAlert alertWithMessageText:@"Unable to repair table" + defaultButton:@"OK" + alternateButton:nil + otherButton:nil + informativeTextWithFormat:[NSString stringWithFormat:@"An error occurred while trying to repair the table '%@'. Please try again.\n\n%@", [self table], [mySQLConnection getLastErrorMessage]]] + beginSheetModalForWindow:tableWindow + modalDelegate:self + didEndSelector:NULL + contextInfo:NULL]; } + return; } // Process result - theRow = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject]; - NSRunInformationalAlertPanel([NSString stringWithFormat:@"Repair '%@' table", [self table]], [NSString stringWithFormat:@"Repair: %@", [theRow objectForKey:@"Msg_text"]], @"OK", nil, nil); + NSDictionary *result = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject]; + + NSString *message = @""; + + message = ([[result objectForKey:@"Msg_type"] isEqualToString:@"status"]) ? @"Successfully repaired table" : @"Repair table failed."; + + message = [NSString stringWithFormat:@"%@\n\nMySQL said: %@", message, [result objectForKey:@"Msg_text"]]; + + [[NSAlert alertWithMessageText:[NSString stringWithFormat:@"Repair table '%@'", [self table]] + defaultButton:@"OK" + alternateButton:nil + otherButton:nil + informativeTextWithFormat:message] + beginSheetModalForWindow:tableWindow + modalDelegate:self + didEndSelector:NULL + contextInfo:NULL]; } +/** + * Flush the selected table and inform the user via a dialog sheet. + */ - (IBAction)flushTable:(id)sender { - NSString *query; - CMMCPResult *theResult; - - //Create the query and get results - query = [NSString stringWithFormat:@"FLUSH TABLE %@", [[self table] backtickQuotedString]]; - theResult = [mySQLConnection queryString:query]; + [mySQLConnection queryString:[NSString stringWithFormat:@"FLUSH TABLE %@", [[self table] backtickQuotedString]]]; // Check for errors, only displaying if the connection hasn't been terminated if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) { if ([mySQLConnection isConnected]) { - NSRunAlertPanel(@"Error", [NSString stringWithFormat:@"An error occured while flushing table.\n\n: %@",[mySQLConnection getLastErrorMessage]], @"OK", nil, nil); + + [[NSAlert alertWithMessageText:@"Unable to flush table" + defaultButton:@"OK" + alternateButton:nil + otherButton:nil + informativeTextWithFormat:[NSString stringWithFormat:@"An error occurred while trying to flush the table '%@'. Please try again.\n\n%@", [self table], [mySQLConnection getLastErrorMessage]]] + beginSheetModalForWindow:tableWindow + modalDelegate:self + didEndSelector:NULL + contextInfo:NULL]; } + return; } - - // Process result - NSRunInformationalAlertPanel([NSString stringWithFormat:@"Flush '%@' table", [self table]], @"Flushed", @"OK", nil, nil); + + [[NSAlert alertWithMessageText:[NSString stringWithFormat:@"Flush table '%@'", [self table]] + defaultButton:@"OK" + alternateButton:nil + otherButton:nil + informativeTextWithFormat:@"Table was successfully flushed"] + beginSheetModalForWindow:tableWindow + modalDelegate:self + didEndSelector:NULL + contextInfo:NULL]; } +/** + * Runs a MySQL checksum on the selected table and present the result to the user via an alert sheet. + */ - (IBAction)checksumTable:(id)sender -{ - NSString *query; - CMMCPResult *theResult; - NSDictionary *theRow; - - //Create the query and get results - query = [NSString stringWithFormat:@"CHECKSUM TABLE %@", [[self table] backtickQuotedString]]; - theResult = [mySQLConnection queryString:query]; +{ + CMMCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"CHECKSUM TABLE %@", [[self table] backtickQuotedString]]]; // Check for errors, only displaying if the connection hasn't been terminated if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) { if ([mySQLConnection isConnected]) { - NSRunAlertPanel(@"Error", [NSString stringWithFormat:@"An error occured while performming checksum on table.\n\n: %@",[mySQLConnection getLastErrorMessage]], @"OK", nil, nil); + + [[NSAlert alertWithMessageText:@"Unable to perform checksum" + defaultButton:@"OK" + alternateButton:nil + otherButton:nil + informativeTextWithFormat:[NSString stringWithFormat:@"An error occurred while performing the checksum on table '%@'. Please try again.\n\n%@", [self table], [mySQLConnection getLastErrorMessage]]] + beginSheetModalForWindow:tableWindow + modalDelegate:self + didEndSelector:NULL + contextInfo:NULL]; } return; } // Process result - theRow = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject]; - NSRunInformationalAlertPanel([NSString stringWithFormat:@"Checksum '%@' table", [self table]], [NSString stringWithFormat:@"Checksum: %@", [theRow objectForKey:@"Checksum"]], @"OK", nil, nil); + NSString *result = [[[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject] objectForKey:@"Checksum"]; + + [[NSAlert alertWithMessageText:[NSString stringWithFormat:@"Checksum table '%@'", [self table]] + defaultButton:@"OK" + alternateButton:nil + otherButton:nil + informativeTextWithFormat:[NSString stringWithFormat:@"Table checksum: %@", result]] + beginSheetModalForWindow:tableWindow + modalDelegate:self + didEndSelector:NULL + contextInfo:NULL]; } - #pragma mark Other Methods + /** - * returns the host + * Returns the host */ - (NSString *)host { @@ -1022,7 +1143,7 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa } /** - * passes query to tablesListInstance + * Passes query to tablesListInstance */ - (void)doPerformQueryService:(NSString *)query { @@ -1031,7 +1152,7 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa } /** - * flushes the mysql privileges + * Flushes the mysql privileges */ - (void)flushPrivileges:(id)sender { @@ -1047,10 +1168,10 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa } } -- (void)showVariables:(id)sender -/* - shows the mysql variables +/** + * Shows the MySQL server variables */ +- (void)showVariables:(id)sender { CMMCPResult *theResult; NSMutableArray *tempResult = [NSMutableArray array]; @@ -1088,48 +1209,48 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa notificationName:@"Disconnected"]; } +// Getter methods -//getter methods -- (NSString *)database -/* - returns the currently selected database +/** + * Returns the currently selected database */ +- (NSString *)database { return selectedDatabase; } -- (NSString *)table -/* - returns the currently selected table (passing the request to TablesList) +/** + * Returns the currently selected table (passing the request to TablesList) */ +- (NSString *)table { return [tablesListInstance tableName]; } -- (NSString *)mySQLVersion -/* - returns the mysql version +/** + * Returns the MySQL version */ +- (NSString *)mySQLVersion { return mySQLVersion; } -- (NSString *)user -/* - returns the mysql version +/** + * Returns the current user */ +- (NSString *)user { return [userField stringValue]; } +// Notification center methods -//notification center methods -- (void)willPerformQuery:(NSNotification *)notification -/* - invoked before a query is performed +/** + * Invoked before a query is performed */ +- (void)willPerformQuery:(NSNotification *)notification { - // Only start the progress indicator is this document window is key. + // Only start the progress indicator if this document window is key. // Because we are starting the progress indicator based on the notification // of a query being started, we have to prevent other windows from // starting theirs. The same is also true for the below hasPerformedQuery: @@ -1142,44 +1263,45 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa } } -- (void)hasPerformedQuery:(NSNotification *)notification -/* - invoked after a query has been performed +/** + * Invoked after a query has been performed */ +- (void)hasPerformedQuery:(NSNotification *)notification { if ([tableWindow isKeyWindow]) { [queryProgressBar stopAnimation:self]; } } -- (void)applicationWillTerminate:(NSNotification *)notification -/* - invoked when the application will terminate +/** + * Invoked when the application will terminate */ +- (void)applicationWillTerminate:(NSNotification *)notification { [tablesListInstance selectionShouldChangeInTableView:nil]; } -- (void)tunnelStatusChanged:(NSNotification *)notification -/* - the status of the tunnel has changed +/** + * The status of the tunnel has changed */ +- (void)tunnelStatusChanged:(NSNotification *)notification { } -//menu methods -- (IBAction)import:(id)sender -/* - passes the request to the tableDump object +// Menu methods + +/** + * Passes the request to the tableDump object */ +- (IBAction)import:(id)sender { [tableDumpInstance importFile]; } -- (IBAction)export:(id)sender -/* - passes the request to the tableDump object +/** + * Passes the request to the tableDump object */ +- (IBAction)export:(id)sender { [tableDumpInstance exportFile:[sender tag]]; } @@ -1563,6 +1685,11 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa } } +// NSWindow delegate methods + +/** + * Invoked when the document window is about to close + */ - (void)windowWillClose:(NSNotification *)aNotification { //reset print settings, so we're not prompted about saving them @@ -1573,11 +1700,10 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa [[NSNotificationCenter defaultCenter] removeObserver:self]; } -//NSWindow delegate methods -- (BOOL)windowShouldClose:(id)sender -/* - invoked when the document window should close +/** + * Invoked when the document window should close */ +- (BOOL)windowShouldClose:(id)sender { if ( ![tablesListInstance selectionShouldChangeInTableView:nil] ) { return NO; @@ -1688,15 +1814,14 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa } -//tableView datasource methods +// TableView datasource methods + - (int)numberOfRowsInTableView:(NSTableView *)aTableView { return [variables count]; } -- (id)tableView:(NSTableView *)aTableView -objectValueForTableColumn:(NSTableColumn *)aTableColumn - row:(int)rowIndex +- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex { id theValue; |