From c11169058366ca679789bc82cf1b3ca8ed496967 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 22 Feb 2010 23:36:15 +0000 Subject: =?UTF-8?q?=E2=80=A2=20implemented=20chance=20to=20reset=20AUTO=5F?= =?UTF-8?q?INCREMENT=20of=20the=20PRIMARY=20KEY=20field=20in=20Table=20Inf?= =?UTF-8?q?o=20Pane=20via=20Advanced=20popup=20button=20and=20sheet=20(not?= =?UTF-8?q?=20yet=20optimal=20GUI=20solution)=20=E2=80=A2=20SPAlertSheets?= =?UTF-8?q?=20-=20ensure=20that=20this=20sheet=20becomes=20the=20keyWindow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/TableSource.m | 72 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 21 deletions(-) (limited to 'Source/TableSource.m') diff --git a/Source/TableSource.m b/Source/TableSource.m index 6dd3f7fb..6004a4ac 100644 --- a/Source/TableSource.m +++ b/Source/TableSource.m @@ -460,14 +460,24 @@ loads aTable, put it in an array, update the tableViewColumns and reload the tab - (IBAction)resetAutoIncrement:(id)sender { - // Begin the sheet - [NSApp beginSheet:resetAutoIncrementSheet - modalForWindow:tableWindow - modalDelegate:self - didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) - contextInfo:@"resetAutoIncrement"]; + if([sender tag] == 1) { - [resetAutoIncrementValue setStringValue:@"1"]; + [resetAutoIncrementLine setHidden:YES]; + if([[tableDocumentInstance valueForKeyPath:@"tableTabView"] indexOfTabViewItem:[[tableDocumentInstance valueForKeyPath:@"tableTabView"] selectedTabViewItem]] == 0) + [resetAutoIncrementLine setHidden:NO]; + + // Begin the sheet + [NSApp beginSheet:resetAutoIncrementSheet + modalForWindow:tableWindow + modalDelegate:self + didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) + contextInfo:@"resetAutoIncrement"]; + + [resetAutoIncrementValue setStringValue:@"1"]; + } + else if([sender tag] == 2) { + [self setAutoIncrementTo:@"1"]; + } } @@ -566,6 +576,39 @@ closes the keySheet [tableSourceView registerForDraggedTypes:[NSArray arrayWithObjects:@"SequelProPasteboard", nil]]; } +- (void)setAutoIncrementTo:(NSString*)valueAsString +{ + + if(valueAsString == nil || ![valueAsString length]) return; + + NSString *selTable = nil; + + // if selectedTable is nil try to get the name from tablesList + if(selectedTable == nil || ![selectedTable length]) + selTable = [tablesListInstance tableName]; + else + selTable = [NSString stringWithString:selectedTable]; + + if(selTable == nil || ![selTable length]) + return; + + [mySQLConnection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ AUTO_INCREMENT = %@", [selTable backtickQuotedString], valueAsString]]; + + if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) { + SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), + NSLocalizedString(@"OK", @"OK button"), + nil, nil, [NSApp mainWindow], nil, nil, nil, nil, + [NSString stringWithFormat:NSLocalizedString(@"An error occurred while trying to reset AUTO_INCREMENT of table '%@'.\n\nMySQL said: %@", @"error resetting auto_increment informative message"), + selTable, [mySQLConnection getLastErrorMessage]]); + } else { + [tableDataInstance resetAllData]; + [tablesListInstance setStatusRequiresReload:YES]; + [self loadTable:selectedTable]; + [extendedTableInfoInstance loadTable:selTable]; + [tableInfoInstance tableChanged:nil]; + } +} + /* fetches the result as an array with a dictionary for each row in it */ @@ -1012,20 +1055,7 @@ fetches the result as an array with a dictionary for each row in it } else if ([contextInfo isEqualToString:@"resetAutoIncrement"]) { if (returnCode == NSAlertDefaultReturn) { - - [mySQLConnection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ AUTO_INCREMENT = %@", [selectedTable backtickQuotedString], [[resetAutoIncrementValue stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]]]; - - if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) { - SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), - NSLocalizedString(@"OK", @"OK button"), - nil, nil, [NSApp mainWindow], nil, nil, nil, nil, - [NSString stringWithFormat:NSLocalizedString(@"An error occurred while trying to reset AUTO_INCREMENT of table '%@'.\n\nMySQL said: %@", @"error resetting auto_increment informative message"), selectedTable, [mySQLConnection getLastErrorMessage]]); - } else { - [tableDataInstance resetAllData]; - [tablesListInstance setStatusRequiresReload:YES]; - [self loadTable:selectedTable]; - [tableInfoInstance tableChanged:nil]; - } + [self setAutoIncrementTo:[[resetAutoIncrementValue stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]]; } } else -- cgit v1.2.3