From b1d29fac626ddbdcfda3bc034861c3b22e39b548 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Tue, 23 Feb 2010 11:34:58 +0000 Subject: =?UTF-8?q?=E2=80=A2=20Reset=20AUTO=5FINCREMENT=20in=20Table=20Inf?= =?UTF-8?q?o=20Pane=20uses=20inline=20entering=20of=20the=20new=20value=20?= =?UTF-8?q?(no=20sheet)=20=E2=80=A2=20"Delete=20all=20records"=20confirmat?= =?UTF-8?q?ion=20sheet=20shows=20a=20checkbox=20"Reset=20AUTO=5FINCREMENT?= =?UTF-8?q?=20after=20deletion"=20if=20PRI=20key=20is=20given=20for=20that?= =?UTF-8?q?=20table=20=E2=80=A2=20minimized=20table=20data=20querying=20fo?= =?UTF-8?q?r=20auto=5Finc=20=E2=80=A2=20optimized=20auto=5Finc=20change=20?= =?UTF-8?q?notification=20=E2=80=A2=20if=20user=20changes=20tabVIew=20to?= =?UTF-8?q?=20Table=20Info=20Pane=20update=20data=20in=20beforehand=20?= =?UTF-8?q?=E2=80=A2=20TRUNCATE=20query=20updates=20auto=5Finc=20value=20a?= =?UTF-8?q?s=20well=20in=20TABLE=20INFORMATION?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPExtendedTableInfo.h | 1 + Source/SPExtendedTableInfo.m | 35 +++++++++++++++++++++++++++++++---- Source/TableContent.h | 2 ++ Source/TableContent.m | 24 +++++++++++++++++++++--- Source/TableDocument.m | 7 +++++++ Source/TableSource.m | 9 +++++---- Source/TablesList.h | 1 + Source/TablesList.m | 3 +++ 8 files changed, 71 insertions(+), 11 deletions(-) (limited to 'Source') diff --git a/Source/SPExtendedTableInfo.h b/Source/SPExtendedTableInfo.h index 24f38d5d..4c9d1f07 100644 --- a/Source/SPExtendedTableInfo.h +++ b/Source/SPExtendedTableInfo.h @@ -69,6 +69,7 @@ - (IBAction)updateTableEncoding:(id)sender; - (IBAction)updateTableCollation:(id)sender; - (IBAction)resetAutoIncrement:(id)sender; +- (IBAction)resetAutoIncrementValueWasEdited:(id)sender; // Others - (void)loadTable:(NSString *)table; diff --git a/Source/SPExtendedTableInfo.m b/Source/SPExtendedTableInfo.m index f68dca18..00f1fc37 100644 --- a/Source/SPExtendedTableInfo.m +++ b/Source/SPExtendedTableInfo.m @@ -32,6 +32,7 @@ #import "TableDocument.h" #import "TablesList.h" #import "SPAlertSheets.h" +#import "TableSource.h" @interface SPExtendedTableInfo (PrivateAPI) @@ -174,7 +175,31 @@ - (IBAction)resetAutoIncrement:(id)sender { - [tableSourceInstance resetAutoIncrement:sender]; + + if([sender tag] == 1) { + [tableRowAutoIncrement setEditable:YES]; + [tableRowAutoIncrement selectText:nil]; + } else { + [tableRowAutoIncrement setEditable:NO]; + [tableSourceInstance resetAutoIncrement:sender]; + } +} + +- (IBAction)resetAutoIncrementValueWasEdited:(id)sender +{ + [tableRowAutoIncrement setEditable:NO]; + [tableSourceInstance setAutoIncrementTo:[[tableRowAutoIncrement stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]]; +} + +- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command +{ + + // Listen to ESC to abort editing of auto increment input field + if (command == @selector(cancelOperation:) && control == tableRowAutoIncrement) { + [tableRowAutoIncrement abortEditing]; + return YES; + } + return NO; } #pragma mark - @@ -235,7 +260,7 @@ [tableRowNumber setStringValue:@"Number of rows: "]; [tableRowFormat setStringValue:@"Row format: "]; [tableRowAvgLength setStringValue:@"Avg. row length: "]; - [tableRowAutoIncrement setStringValue:@"Auto increment: "]; + [tableRowAutoIncrement setStringValue:@""]; // Set size values [tableDataSize setStringValue:@"Data size: "]; @@ -493,8 +518,10 @@ } } } - - return [NSString stringWithFormat:@"%@: %@", label, ([value length] > 0) ? value : @"Not available"]; + if([key isEqualToString:@"Auto_increment"]) + return ([value length] > 0) ? value : @"Not available"; + else + return [NSString stringWithFormat:@"%@: %@", label, ([value length] > 0) ? value : @"Not available"]; } @end diff --git a/Source/TableContent.h b/Source/TableContent.h index 2e45ac59..b4941912 100644 --- a/Source/TableContent.h +++ b/Source/TableContent.h @@ -35,6 +35,8 @@ IBOutlet id tableDocumentInstance; IBOutlet id tablesListInstance; IBOutlet id tableDataInstance; + IBOutlet id tableSourceInstance; + IBOutlet SPTableInfo *tableInfoInstance; IBOutlet SPHistoryController *spHistoryControllerInstance; diff --git a/Source/TableContent.m b/Source/TableContent.m index 3a736a90..fc12dccf 100644 --- a/Source/TableContent.m +++ b/Source/TableContent.m @@ -29,6 +29,7 @@ #import "TableContent.h" #import "TableDocument.h" +#import "TableSource.h" #import "SPTableInfo.h" #import "TablesList.h" #import "CMImageView.h" @@ -49,7 +50,6 @@ #import "SPNotLoaded.h" #import "SPConstants.h" #import "SPDataStorage.h" -#import "TableDocument.h" #import "SPAlertSheets.h" @implementation TableContent @@ -1386,13 +1386,25 @@ [[buttons objectAtIndex:0] setKeyEquivalent:@"d"]; [[buttons objectAtIndex:0] setKeyEquivalentModifierMask:NSCommandKeyMask]; [[buttons objectAtIndex:1] setKeyEquivalent:@"\r"]; - + + [alert setShowsSuppressionButton:NO]; + [[alert suppressionButton] setState:NSOffState]; + NSString *contextInfo = @"removerow"; if (([tableContentView numberOfSelectedRows] == [tableContentView numberOfRows]) && !isFiltered && !isLimited && !isInterruptedLoad) { - + contextInfo = @"removeallrows"; + // If table has PRIMARY KEY ask for resetting the auto increment after deletion if given + if(![[tableDataInstance statusValueForKey:@"Auto_increment"] isKindOfClass:[NSNull class]]) { + [alert setShowsSuppressionButton:YES]; + [[alert suppressionButton] setState:NSOffState]; + [[[alert suppressionButton] cell] setControlSize:NSSmallControlSize]; + [[[alert suppressionButton] cell] setFont:[NSFont systemFontOfSize:11]]; + [[alert suppressionButton] setTitle:NSLocalizedString(@"Reset AUTO_INCREMENT after deletion?", @"reset auto_increment after deletion of all rows message")]; + } + [alert setMessageText:NSLocalizedString(@"Delete all rows?", @"delete all rows message")]; [alert setInformativeText:NSLocalizedString(@"Are you sure you want to delete all the rows from this table? This action cannot be undone.", @"delete all rows informative message")]; } @@ -2139,7 +2151,13 @@ if ( returnCode == NSAlertDefaultReturn ) { [mySQLConnection queryString:[NSString stringWithFormat:@"DELETE FROM %@", [selectedTable backtickQuotedString]]]; if ( [[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) { + + // Reset auto increment if suppression button was ticked + if([[sheet suppressionButton] state] == NSOnState) + [tableSourceInstance setAutoIncrementTo:@"1"]; + [self reloadTable:self]; + } else { [self performSelector:@selector(showErrorSheetWith:) withObject:[NSArray arrayWithObjects:NSLocalizedString(@"Error", @"error"), diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 25fa50a0..4d5c5a77 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -3059,6 +3059,13 @@ [tableTabView selectTabViewItemAtIndex:3]; [mainToolbar setSelectedItemIdentifier:SPMainToolbarTableInfo]; [spHistoryControllerInstance updateHistoryEntries]; + + // Refresh data + if([self table] && [[self table] length]) { + [tableDataInstance resetAllData]; + [extendedTableInfoInstance loadTable:[self table]]; + } + [tableWindow makeFirstResponder:[extendedTableInfoInstance valueForKeyPath:@"tableCreateSyntaxTextView"]]; [prefs setInteger:SPTableInfoViewMode forKey:SPLastViewMode]; diff --git a/Source/TableSource.m b/Source/TableSource.m index 6004a4ac..655dffc1 100644 --- a/Source/TableSource.m +++ b/Source/TableSource.m @@ -601,10 +601,11 @@ closes the keySheet [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]; + [tableDataInstance resetStatusData]; + if([[tableDocumentInstance valueForKeyPath:@"tableTabView"] indexOfTabViewItem:[[tableDocumentInstance valueForKeyPath:@"tableTabView"] selectedTabViewItem]] == 3) { + [tableDataInstance resetAllData]; + [extendedTableInfoInstance loadTable:selTable]; + } [tableInfoInstance tableChanged:nil]; } } diff --git a/Source/TablesList.h b/Source/TablesList.h index b64e0de0..a730fcf4 100644 --- a/Source/TablesList.h +++ b/Source/TablesList.h @@ -55,6 +55,7 @@ enum sp_table_types IBOutlet id tableDataInstance; IBOutlet id extendedTableInfoInstance; IBOutlet id databaseDataInstance; + IBOutlet id tableInfoInstance; IBOutlet SPHistoryController *spHistoryControllerInstance; IBOutlet id tableWindow; diff --git a/Source/TablesList.m b/Source/TablesList.m index b66af9fb..af7f6fdc 100644 --- a/Source/TablesList.m +++ b/Source/TablesList.m @@ -28,6 +28,7 @@ #import "TableSource.h" #import "TableContent.h" #import "SPTableData.h" +#import "SPTableInfo.h" #import "TableDump.h" #import "ImageAndTextCell.h" #import "SPStringAdditions.h" @@ -1881,6 +1882,8 @@ // Reload the table's content view to show that it has been truncated [tableContentInstance reloadTable:self]; + [tableDataInstance resetStatusData]; + } /** -- cgit v1.2.3