From 1fea80ee57ff01c32068415f1cb7561dad4fde98 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Mon, 9 Nov 2009 00:13:40 +0000 Subject: Don't run the add new index sheet modally, thus blocking the main thread. Part of issue #357. Also some refactoring. --- Interfaces/English.lproj/DBView.xib | 81 ++++---- Source/TableSource.h | 7 +- Source/TableSource.m | 362 +++++++++++++++++++----------------- Source/TablesList.m | 2 +- 4 files changed, 234 insertions(+), 218 deletions(-) diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib index 0412d077..fbc8ee83 100644 --- a/Interfaces/English.lproj/DBView.xib +++ b/Interfaces/English.lproj/DBView.xib @@ -281,6 +281,7 @@ {212, 26} + 6 @@ -313,6 +314,7 @@ {212, 26} + 0 @@ -410,6 +412,7 @@ {212, 354} + 4 @@ -436,6 +439,7 @@ {212, 354} + 528 @@ -571,6 +575,7 @@ {212, 145} + 6 @@ -597,6 +602,7 @@ {212, 145} + 512 @@ -1383,6 +1389,7 @@ {{1, 17}, {688, 289}} + 4 @@ -1415,6 +1422,7 @@ {{1, 0}, {688, 17}} + 4 @@ -1423,6 +1431,7 @@ {{-1, 22}, {690, 307}} + 562 @@ -1968,6 +1977,7 @@ {{1, 17}, {688, 142}} + 4 @@ -2000,6 +2010,7 @@ {{1, 0}, {688, 17}} + 4 @@ -2008,6 +2019,7 @@ {{-1, 22}, {690, 160}} + 562 @@ -5793,7 +5805,7 @@ {600, 127} {260, 127} - + 256 YES @@ -5802,7 +5814,6 @@ 266 {{17, 93}, {226, 14}} - YES 67239488 @@ -5819,7 +5830,6 @@ 258 {{20, 67}, {220, 18}} - YES -1804468671 @@ -5837,7 +5847,6 @@ 292 {{19, 43}, {189, 18}} - YES 67239424 @@ -5859,7 +5868,6 @@ 289 {{158, 13}, {87, 28}} - 1 YES @@ -5883,7 +5891,6 @@ 289 {{80, 13}, {80, 28}} - YES 67239424 @@ -5902,8 +5909,6 @@ {260, 127} - - {{0, 0}, {1440, 878}} {260, 149} @@ -6257,6 +6262,7 @@ 256 {{172, 13}, {80, 28}} + 1 YES 67239424 @@ -6315,7 +6321,7 @@ {3.40282e+38, 3.40282e+38} {213, 107} - + 256 YES @@ -6324,7 +6330,6 @@ 256 {{17, 74}, {272, 28}} - YES 67239424 @@ -6342,7 +6347,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 256 {{74, 45}, {162, 22}} - YES -2076049856 @@ -6424,7 +6428,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 256 {{154, 17}, {84, 28}} - 1 YES @@ -6448,7 +6451,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 256 {{72, 17}, {84, 28}} - YES 67239424 @@ -6469,8 +6471,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {306, 122} - - {{0, 0}, {1440, 878}} {213, 129} @@ -7909,7 +7909,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {3.40282e+38, 3.40282e+38} {213, 107} - + 256 YES @@ -7918,7 +7918,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 264 {{20, 233}, {140, 14}} - YES 67239424 @@ -7945,7 +7944,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 2322 {352, 14} - @@ -7995,7 +7993,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {{1, 1}, {352, 178}} - @@ -8007,7 +8004,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 256 {{353, 1}, {11, 178}} - 256 _doScroller: @@ -8018,7 +8014,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 -2147483392 {{-100, -100}, {87, 18}} - 257 _doScroller: @@ -8028,7 +8023,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {{20, 45}, {365, 180}} - 18 @@ -8040,7 +8034,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 257 {{314, 13}, {76, 28}} - YES 67239424 @@ -8059,8 +8052,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {405, 267} - - {{0, 0}, {1440, 878}} {213, 129} @@ -11628,22 +11619,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 339 - - - addIndex: - - - - 342 - - - - closeIndexSheet: - - - - 343 - indexTypeField @@ -15249,6 +15224,22 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 6640 + + + closeSheet: + + + + 6641 + + + + closeSheet: + + + + 6642 + @@ -23322,9 +23313,9 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin - {{427, 328}, {267, 139}} + {{769, 253}, {267, 139}} com.apple.InterfaceBuilder.CocoaPlugin - {{427, 328}, {267, 139}} + {{769, 253}, {267, 139}} @@ -24841,7 +24832,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 - 6640 + 6642 @@ -26110,8 +26101,8 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 addField: addIndex: chooseIndexType: - closeIndexSheet: closeKeySheet: + closeSheet: copyField: openIndexSheet: reloadTable: diff --git a/Source/TableSource.h b/Source/TableSource.h index c30a70bd..52030cdb 100644 --- a/Source/TableSource.h +++ b/Source/TableSource.h @@ -71,13 +71,12 @@ // Edit methods - (IBAction)addField:(id)sender; - (IBAction)copyField:(id)sender; -- (IBAction)addIndex:(id)sender; - (IBAction)removeField:(id)sender; - (IBAction)removeIndex:(id)sender; // Index sheet methods - (IBAction)openIndexSheet:(id)sender; -- (IBAction)closeIndexSheet:(id)sender; +- (IBAction)closeSheet:(id)sender; - (IBAction)chooseIndexType:(id)sender; - (void)closeAlertSheet; @@ -97,7 +96,7 @@ - (NSArray *)tableStructureForPrint; // Task interaction -- (void) startDocumentTaskForTab:(NSNotification *)aNotification; -- (void) endDocumentTaskForTab:(NSNotification *)aNotification; +- (void)startDocumentTaskForTab:(NSNotification *)aNotification; +- (void)endDocumentTaskForTab:(NSNotification *)aNotification; @end diff --git a/Source/TableSource.m b/Source/TableSource.m index d6e0af75..70f45100 100644 --- a/Source/TableSource.m +++ b/Source/TableSource.m @@ -32,6 +32,13 @@ #import "SPArrayAdditions.h" #import "SPConstants.h" +@interface TableSource (PrivateAPI) + +- (void)_addIndex; +- (void)_removeIndex; + +@end + @implementation TableSource /* @@ -313,58 +320,6 @@ reloads the table (performing a new mysql-query) [tableSourceView editColumn:0 row:[tableSourceView numberOfRows]-1 withEvent:nil select:YES]; } -/** - * adds the index to the mysql-db and stops modal session with code 1 when success, 0 when error and -1 when no columns specified - */ -- (IBAction)addIndex:(id)sender -{ - NSString *indexName; - NSArray *indexedColumns; - NSMutableArray *tempIndexedColumns = [NSMutableArray array]; - NSEnumerator *enumerator; - NSString *string; - - // Check whether a save of the current fields row is required. - if ( ![self saveRowOnDeselect] ) return; - - if ( [[indexedColumnsField stringValue] isEqualToString:@""] ) { - [NSApp stopModalWithCode:-1]; - } else { - if ( [[indexNameField stringValue] isEqualToString:@"PRIMARY"] ) { - indexName = @""; - } else { - if ( [[indexNameField stringValue] isEqualToString:@""] ) - { - indexName = @""; - } else { - indexName = [[indexNameField stringValue] backtickQuotedString]; - } - } - indexedColumns = [[indexedColumnsField stringValue] componentsSeparatedByString:@","]; - enumerator = [indexedColumns objectEnumerator]; - while ( (string = [enumerator nextObject]) ) { - if ( ([string characterAtIndex:0] == ' ') ) { - [tempIndexedColumns addObject:[string substringWithRange:NSMakeRange(1,([string length]-1))]]; - } else { - [tempIndexedColumns addObject:[NSString stringWithString:string]]; - } - } - - [mySQLConnection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ ADD %@ %@ (%@)", - [selectedTable backtickQuotedString], [indexTypeField titleOfSelectedItem], indexName, - [tempIndexedColumns componentsJoinedAndBacktickQuoted]]]; - - if ( [[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) { - [tableDataInstance resetAllData]; - [tablesListInstance setStatusRequiresReload:YES]; - [self loadTable:selectedTable]; - [NSApp stopModalWithCode:1]; - } else { - [NSApp stopModalWithCode:0]; - } - } -} - /** * Ask the user to confirm that they really want to remove the selected field. */ @@ -374,8 +329,7 @@ reloads the table (performing a new mysql-query) return; // Check whether a save of the current row is required. - if (![self saveRowOnDeselect]) - return; + if (![self saveRowOnDeselect]) return; // Check if the user tries to delete the last defined field in table if ([tableSourceView numberOfRows] < 2) { @@ -415,12 +369,10 @@ reloads the table (performing a new mysql-query) */ - (IBAction)removeIndex:(id)sender { - if (![indexView numberOfSelectedRows]) - return; + if (![indexView numberOfSelectedRows]) return; // Check whether a save of the current fields row is required. - if (![self saveRowOnDeselect]) - return; + if (![self saveRowOnDeselect]) return; NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Delete Index?", @"delete index message") defaultButton:NSLocalizedString(@"Cancel", @"cancel button") @@ -437,21 +389,24 @@ reloads the table (performing a new mysql-query) [[buttons objectAtIndex:0] setKeyEquivalent:@""]; [[buttons objectAtIndex:1] setKeyEquivalent:@"\r"]; - [alert beginSheetModalForWindow:tableWindow modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:@"removeindex"]; + [alert beginSheetModalForWindow:tableWindow + modalDelegate:self + didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) + contextInfo:@"removeIndex"]; } #pragma mark - #pragma mark Index sheet methods -/* -opens the indexSheet -*/ +/** + * Opens the add new index sheet. + */ - (IBAction)openIndexSheet:(id)sender { - int i, code = 0; + int i; // Check whether a save of the current field row is required. - if ( ![self saveRowOnDeselect] ) return; + if (![self saveRowOnDeselect]) return; // Set sheet defaults - key type PRIMARY, key name PRIMARY and disabled, and blank indexed columns [indexTypeField selectItemAtIndex:0]; @@ -461,7 +416,8 @@ opens the indexSheet [indexSheet makeFirstResponder:indexedColumnsField]; // Check to see whether a primary key already exists for the table, and if so select an INDEX instead - for (i = 0; i < [tableFields count]; i++) { + for (i = 0; i < [tableFields count]; i++) + { if ([[[tableFields objectAtIndex:i] objectForKey:@"Key"] isEqualToString:@"PRI"]) { [indexTypeField selectItemAtIndex:1]; [indexNameField setEnabled:YES]; @@ -473,31 +429,19 @@ opens the indexSheet // Begin the sheet [NSApp beginSheet:indexSheet - modalForWindow:tableWindow modalDelegate:self - didEndSelector:nil contextInfo:nil]; - code = [NSApp runModalForWindow:indexSheet]; - - [NSApp endSheet:indexSheet]; - [indexSheet orderOut:nil]; - - //code == -1 -> no columns specified - //code == 0 -> error while adding index - //code == 1 -> index added with succes OR sheet closed without adding index - if ( code == 0 ) { - NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, - nil, nil, [NSString stringWithFormat:NSLocalizedString(@"Couldn't add index.\nMySQL said: %@", @"message of panel when index cannot be created"), [mySQLConnection getLastErrorMessage]]); - } else if ( code == -1 ) { - NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, - @selector(closeAlertSheet), nil, NSLocalizedString(@"Please insert the columns you want to index.", @"message of panel when no columns are specified to be indexed")); - } + modalForWindow:tableWindow + modalDelegate:self + didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) + contextInfo:@"addIndex"]; } -/* -closes the indexSheet without adding the index (stops modal session with code 1) -*/ -- (IBAction)closeIndexSheet:(id)sender +/** + * Closes the current sheet and stops the modal session + */ +- (IBAction)closeSheet:(id)sender { - [NSApp stopModalWithCode:1]; + [NSApp endSheet:[sender window] returnCode:[sender tag]]; + [[sender window] orderOut:self]; } /* @@ -858,87 +802,6 @@ fetches the result as an array with a dictionary for each row in it } } -- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(NSString *)contextInfo -{ - /* - if contextInfo == addrow: remain in edit-mode if user hits OK, otherwise cancel editing - if contextInfo == removefield: removes row from mysql-db if user hits ok - if contextInfo == removeindex: removes index from mysql-db if user hits ok - if contextInfo == cannotremovefield: do nothing - */ - - if ( [contextInfo isEqualToString:@"addrow"] ) { - [sheet orderOut:self]; - - alertSheetOpened = NO; - if ( returnCode == NSAlertDefaultReturn ) { - //problem: reentering edit mode for first cell doesn't function - [tableSourceView editColumn:0 row:[tableSourceView selectedRow] withEvent:nil select:YES]; - } else { - if ( !isEditingNewRow ) { - [tableFields replaceObjectAtIndex:[tableSourceView selectedRow] - withObject:[NSMutableDictionary dictionaryWithDictionary:oldRow]]; - isEditingRow = NO; - } else { - [tableFields removeObjectAtIndex:[tableSourceView selectedRow]]; - isEditingRow = NO; - isEditingNewRow = NO; - } - currentlyEditingRow = -1; - } - [tableSourceView reloadData]; - } else if ( [contextInfo isEqualToString:@"removefield"] ) { - if ( returnCode == NSAlertDefaultReturn ) { - //remove row - [mySQLConnection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ DROP %@", - [selectedTable backtickQuotedString], [[[tableFields objectAtIndex:[tableSourceView selectedRow]] objectForKey:@"Field"] backtickQuotedString]]]; - - if ( [[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) { - [tableDataInstance resetAllData]; - [tablesListInstance setStatusRequiresReload:YES]; - [self loadTable:selectedTable]; - - // Mark the content table cache for refresh - [tablesListInstance setContentRequiresReload:YES]; - } else { - [self performSelector:@selector(showErrorSheetWith:) - withObject:[NSArray arrayWithObjects:NSLocalizedString(@"Error", @"error"), - [NSString stringWithFormat:NSLocalizedString(@"Couldn't remove field %@.\nMySQL said: %@", @"message of panel when field cannot be removed"), - [[tableFields objectAtIndex:[tableSourceView selectedRow]] objectForKey:@"Field"], - [mySQLConnection getLastErrorMessage]], - nil] - afterDelay:0.3]; - } - } - } else if ( [contextInfo isEqualToString:@"removeindex"] ) { - if ( returnCode == NSAlertAlternateReturn ) { - //remove index - if ( [[[indexes objectAtIndex:[indexView selectedRow]] objectForKey:@"Key_name"] isEqualToString:@"PRIMARY"] ) { - [mySQLConnection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ DROP PRIMARY KEY", [selectedTable backtickQuotedString]]]; - } else { - [mySQLConnection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ DROP INDEX %@", - [selectedTable backtickQuotedString], [[[indexes objectAtIndex:[indexView selectedRow]] objectForKey:@"Key_name"] backtickQuotedString]]]; - } - - if ( [[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) { - [tableDataInstance resetAllData]; - [tablesListInstance setStatusRequiresReload:YES]; - [self loadTable:selectedTable]; - } else { - [self performSelector:@selector(showErrorSheetWith:) - withObject:[NSArray arrayWithObjects:NSLocalizedString(@"Error", @"error"), - [NSString stringWithFormat:NSLocalizedString(@"Couldn't remove index.\nMySQL said: %@", @"message of panel when index cannot be removed"), - [mySQLConnection getLastErrorMessage]], - nil] - afterDelay:0.3]; - } - } - } else if ( [contextInfo isEqualToString:@"cannotremovefield"]) { - ; - } - -} - /* * Show Error sheet (can be called from inside of a endSheet selector) * via [self performSelector:@selector(showErrorSheetWithTitle:) withObject: afterDelay:] @@ -985,6 +848,84 @@ fetches the result as an array with a dictionary for each row in it return YES; } +#pragma mark - +#pragma mark Alert sheet methods + +/** + * Called whenever a sheet is dismissed. + * + * if contextInfo == addrow: remain in edit-mode if user hits OK, otherwise cancel editing + * if contextInfo == removefield: removes row from mysql-db if user hits ok + * if contextInfo == removeindex: removes index from mysql-db if user hits ok + * if contextInfo == addIndex: adds and index to the mysql-db if user hits ok + * if contextInfo == cannotremovefield: do nothing + */ +- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(NSString *)contextInfo +{ + // Order out current sheet to suppress overlapping of sheets + if ([sheet respondsToSelector:@selector(orderOut:)]) [sheet orderOut:nil]; + + if ([contextInfo isEqualToString:@"addrow"]) { + + alertSheetOpened = NO; + if ( returnCode == NSAlertDefaultReturn ) { + + // Problem: reentering edit mode for first cell doesn't function + [tableSourceView editColumn:0 row:[tableSourceView selectedRow] withEvent:nil select:YES]; + } else { + if ( !isEditingNewRow ) { + [tableFields replaceObjectAtIndex:[tableSourceView selectedRow] + withObject:[NSMutableDictionary dictionaryWithDictionary:oldRow]]; + isEditingRow = NO; + } else { + [tableFields removeObjectAtIndex:[tableSourceView selectedRow]]; + isEditingRow = NO; + isEditingNewRow = NO; + } + currentlyEditingRow = -1; + } + [tableSourceView reloadData]; + } + else if ([contextInfo isEqualToString:@"removefield"]) { + if (returnCode == NSAlertDefaultReturn) { + + // Remove row + [mySQLConnection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ DROP %@", + [selectedTable backtickQuotedString], [[[tableFields objectAtIndex:[tableSourceView selectedRow]] objectForKey:@"Field"] backtickQuotedString]]]; + + if ( [[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) { + [tableDataInstance resetAllData]; + [tablesListInstance setStatusRequiresReload:YES]; + [self loadTable:selectedTable]; + + // Mark the content table cache for refresh + [tablesListInstance setContentRequiresReload:YES]; + } else { + [self performSelector:@selector(showErrorSheetWith:) + withObject:[NSArray arrayWithObjects:NSLocalizedString(@"Error", @"error"), + [NSString stringWithFormat:NSLocalizedString(@"Couldn't remove field %@.\nMySQL said: %@", @"message of panel when field cannot be removed"), + [[tableFields objectAtIndex:[tableSourceView selectedRow]] objectForKey:@"Field"], + [mySQLConnection getLastErrorMessage]], + nil] + afterDelay:0.3]; + } + } + } + else if ([contextInfo isEqualToString:@"addIndex"]) { + if (returnCode == NSOKButton) { + [self _addIndex]; + } + } + else if ([contextInfo isEqualToString:@"removeIndex"]) { + if (returnCode == NSAlertAlternateReturn) { + [self _removeIndex]; + } + } + else if ([contextInfo isEqualToString:@"cannotremovefield"]) { + ; + } +} + #pragma mark - #pragma mark Getter methods @@ -1492,3 +1433,88 @@ would result in a position change. } @end + +@implementation TableSource (PrivateAPI) + +/** + * Adds an index to the current table. + */ +- (IBAction)_addIndex; +{ + NSString *indexName; + NSArray *indexedColumns; + NSMutableArray *tempIndexedColumns = [NSMutableArray array]; + NSString *string; + + // Check whether a save of the current fields row is required. + if (![self saveRowOnDeselect]) return; + + if (![[indexedColumnsField stringValue] isEqualToString:@""]) { + + if ([[indexNameField stringValue] isEqualToString:@"PRIMARY"]) { + indexName = @""; + } + else { + indexName = ([[indexNameField stringValue] isEqualToString:@""]) ? @"" : [[indexNameField stringValue] backtickQuotedString]; + } + + indexedColumns = [[indexedColumnsField stringValue] componentsSeparatedByString:@","]; + + NSEnumerator *enumerator = [indexedColumns objectEnumerator]; + + while ((string = [enumerator nextObject])) + { + if (([string characterAtIndex:0] == ' ')) { + [tempIndexedColumns addObject:[string substringWithRange:NSMakeRange(1, ([string length] - 1))]]; + } + else { + [tempIndexedColumns addObject:[NSString stringWithString:string]]; + } + } + + // Execute the query + [mySQLConnection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ ADD %@ %@ (%@)", + [selectedTable backtickQuotedString], [indexTypeField titleOfSelectedItem], indexName, + [tempIndexedColumns componentsJoinedAndBacktickQuoted]]]; + + // Check for errors + if ([[mySQLConnection getLastErrorMessage] isEqualToString:@""]) { + [tableDataInstance resetAllData]; + [tablesListInstance setStatusRequiresReload:YES]; + [self loadTable:selectedTable]; + } + else { + NSBeginAlertSheet(NSLocalizedString(@"Unable to add index", @"add index error message"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil, + [NSString stringWithFormat:NSLocalizedString(@"An error occured while trying to add the index.\n\nMySQL said: %@", @"add index error informative message"), [mySQLConnection getLastErrorMessage]]); + } + } +} + +/** + * Removes an index from the current table. + */ +- (void)_removeIndex +{ + if ([[[indexes objectAtIndex:[indexView selectedRow]] objectForKey:@"Key_name"] isEqualToString:@"PRIMARY"]) { + [mySQLConnection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ DROP PRIMARY KEY", [selectedTable backtickQuotedString]]]; + } + else { + [mySQLConnection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ DROP INDEX %@", + [selectedTable backtickQuotedString], [[[indexes objectAtIndex:[indexView selectedRow]] objectForKey:@"Key_name"] backtickQuotedString]]]; + } + + // Check for errors + if ([[mySQLConnection getLastErrorMessage] isEqualToString:@""]) { + [tableDataInstance resetAllData]; + [tablesListInstance setStatusRequiresReload:YES]; + [self loadTable:selectedTable]; + } + else { + [self performSelector:@selector(showErrorSheetWith:) + withObject:[NSArray arrayWithObjects:NSLocalizedString(@"Unable to remove index", @"error removing index message"), + [NSString stringWithFormat:NSLocalizedString(@"An error occured while trying to remove the index.\n\nMySQL said: %@", @"error removing index informative message"), [mySQLConnection getLastErrorMessage]], nil] + afterDelay:0.3]; + } +} + +@end diff --git a/Source/TablesList.m b/Source/TablesList.m index c5102121..e35b65e1 100644 --- a/Source/TablesList.m +++ b/Source/TablesList.m @@ -497,7 +497,7 @@ - (void)sheetDidEnd:(id)sheet returnCode:(int)returnCode contextInfo:(NSString *)contextInfo { // Order out current sheet to suppress overlapping of sheets - if([sheet respondsToSelector:@selector(orderOut:)]) + if ([sheet respondsToSelector:@selector(orderOut:)]) [sheet orderOut:nil]; if ([contextInfo isEqualToString:@"addRow"]) { -- cgit v1.2.3