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/SPAlertSheets.m | 1 + Source/SPExtendedTableInfo.h | 4 +++ Source/SPExtendedTableInfo.m | 18 +++++++++-- Source/TableDocument.m | 7 +++-- Source/TableSource.h | 3 ++ Source/TableSource.m | 72 +++++++++++++++++++++++++++++++------------- 6 files changed, 79 insertions(+), 26 deletions(-) (limited to 'Source') diff --git a/Source/SPAlertSheets.m b/Source/SPAlertSheets.m index 581dfc37..2505fb61 100644 --- a/Source/SPAlertSheets.m +++ b/Source/SPAlertSheets.m @@ -52,4 +52,5 @@ void SPBeginAlertSheet( contextInfo, [msg stringByReplacingOccurrencesOfString:@"%" withString:@"%%"] ); + [docWindow makeKeyWindow]; } diff --git a/Source/SPExtendedTableInfo.h b/Source/SPExtendedTableInfo.h index a3f12c62..24f38d5d 100644 --- a/Source/SPExtendedTableInfo.h +++ b/Source/SPExtendedTableInfo.h @@ -34,6 +34,9 @@ IBOutlet TablesList *tablesListInstance; IBOutlet SPTableData *tableDataInstance; IBOutlet SPDatabaseData *databaseDataInstance; + IBOutlet id tableSourceInstance; + + IBOutlet id resetAutoIncrementResetButton; IBOutlet NSTextField *tableRowNumber; IBOutlet NSTextField *tableRowFormat; @@ -65,6 +68,7 @@ - (IBAction)updateTableType:(id)sender; - (IBAction)updateTableEncoding:(id)sender; - (IBAction)updateTableCollation:(id)sender; +- (IBAction)resetAutoIncrement:(id)sender; // Others - (void)loadTable:(NSString *)table; diff --git a/Source/SPExtendedTableInfo.m b/Source/SPExtendedTableInfo.m index 1ddcc90d..f68dca18 100644 --- a/Source/SPExtendedTableInfo.m +++ b/Source/SPExtendedTableInfo.m @@ -172,6 +172,11 @@ } } +- (IBAction)resetAutoIncrement:(id)sender +{ + [tableSourceInstance resetAutoIncrement:sender]; +} + #pragma mark - #pragma mark Other @@ -185,6 +190,8 @@ { BOOL enableInteraction = ![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableInfo] || ![tableDocumentInstance isWorking]; + [resetAutoIncrementResetButton setEnabled:NO]; + // Store the table name away for future use selectedTable = table; @@ -196,7 +203,7 @@ [tableCollationPopUpButton removeAllItems]; // No table selected or view selected - if ([table isEqualToString:@""] || (!table) || [[statusFields objectForKey:@"Engine"] isEqualToString:@"View"]) { + if ((!table) || [table isEqualToString:@""] || [[statusFields objectForKey:@"Engine"] isEqualToString:@"View"]) { [tableTypePopUpButton setEnabled:NO]; [tableEncodingPopUpButton setEnabled:NO]; @@ -330,6 +337,11 @@ [tableCreateSyntaxTextView insertText:[tableDataInstance tableCreateSyntax]]; [tableCreateSyntaxTextView didChangeText]; [tableCreateSyntaxTextView setEditable:NO]; + + // Validate Reset AUTO_INCREMENT button + if([statusFields objectForKey:@"Auto_increment"] && ![[statusFields objectForKey:@"Auto_increment"] isKindOfClass:[NSNull class]]) + [resetAutoIncrementResetButton setEnabled:YES]; + } /** @@ -464,13 +476,13 @@ [dateFormatter setDateStyle:NSDateFormatterLongStyle]; [dateFormatter setTimeStyle:NSDateFormatterMediumStyle]; - value = [dateFormatter stringFromDate:[NSDate dateWithNaturalLanguageString:value]]; + value = [dateFormatter stringFromDate:[NSDate dateWithNaturalLanguageString:value]]; } // Format numbers else if ([key isEqualToString:@"Rows"] || [key isEqualToString:@"Avg_row_length"] || [key isEqualToString:@"Auto_increment"]) { - NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease]; + NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease]; [numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle]; value = [numberFormatter stringFromNumber:[NSNumber numberWithLongLong:[value longLongValue]]]; diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 1565a477..67d30f71 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -3059,7 +3059,8 @@ [tableTabView selectTabViewItemAtIndex:3]; [mainToolbar setSelectedItemIdentifier:SPMainToolbarTableInfo]; [spHistoryControllerInstance updateHistoryEntries]; - + [tableWindow makeFirstResponder:[extendedTableInfoInstance valueForKeyPath:@"tableCreateSyntaxTextView"]]; + [prefs setInteger:SPTableInfoViewMode forKey:SPLastViewMode]; } @@ -3614,7 +3615,9 @@ - (NSRect)window:(NSWindow *)window willPositionSheet:(NSWindow *)sheet usingRect:(NSRect)rect { // Locate the sheet "Reset Auto Increment" just centered beneath the chosen index row - if([[sheet title] isEqualToString:@"Reset Auto Increment"]) { + // if Structure Pane is active + if([tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 0 + && [[sheet title] isEqualToString:@"Reset Auto Increment"]) { id it = [tableSourceInstance valueForKeyPath:@"indexView"]; NSRect mwrect = [[NSApp mainWindow] frame]; diff --git a/Source/TableSource.h b/Source/TableSource.h index 6904b875..3650ec14 100644 --- a/Source/TableSource.h +++ b/Source/TableSource.h @@ -32,12 +32,14 @@ IBOutlet id tableDataInstance; IBOutlet id tableDocumentInstance; IBOutlet id tableInfoInstance; + IBOutlet id extendedTableInfoInstance; IBOutlet id tableWindow; IBOutlet id indexSheet; IBOutlet id keySheet; IBOutlet id resetAutoIncrementSheet; IBOutlet id resetAutoIncrementValue; + IBOutlet id resetAutoIncrementLine; IBOutlet id tableSourceView; IBOutlet id indexView; IBOutlet id addFieldButton; @@ -92,6 +94,7 @@ - (NSArray *)fetchResultAsArray:(MCPResult *)theResult; - (BOOL)saveRowOnDeselect; - (BOOL)addRowToDB; +- (void)setAutoIncrementTo:(NSString*)valueAsString; // Getter methods - (NSString *)defaultValueForField:(NSString *)field; 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