aboutsummaryrefslogtreecommitdiffstats
path: root/Source/TableDocument.m
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2009-04-09 19:42:43 +0000
committerstuconnolly <stuart02@gmail.com>2009-04-09 19:42:43 +0000
commitddc5add77f3984cae1601e96d564cf4ba7347202 (patch)
treeee4abe583c219dd26f3e9a1a98b5e6e03b2a53e1 /Source/TableDocument.m
parent723c6fe23c8d5f35c19ad858c51cf0577fb1ab5f (diff)
downloadsequelpro-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].
Diffstat (limited to 'Source/TableDocument.m')
-rw-r--r--Source/TableDocument.m377
1 files changed, 251 insertions, 126 deletions
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;