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 --- Interfaces/English.lproj/DBView.xib | 411 +++++++++++++++++++++++++++++++----- Source/SPAlertSheets.m | 1 + Source/SPExtendedTableInfo.h | 4 + Source/SPExtendedTableInfo.m | 18 +- Source/TableDocument.m | 7 +- Source/TableSource.h | 3 + Source/TableSource.m | 72 +++++-- 7 files changed, 435 insertions(+), 81 deletions(-) diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib index 5079c841..8e168bb3 100644 --- a/Interfaces/English.lproj/DBView.xib +++ b/Interfaces/English.lproj/DBView.xib @@ -23,8 +23,7 @@ YES - - + YES @@ -874,7 +873,7 @@ source - + 256 YES @@ -2136,7 +2135,6 @@ {{10, 7}, {706, 544}} - Structure @@ -3808,7 +3806,7 @@ status - + 256 YES @@ -3835,6 +3833,29 @@ 2322 + + YES + + YES + Apple HTML pasteboard type + Apple PDF pasteboard type + Apple PICT pasteboard type + Apple PNG pasteboard type + Apple URL pasteboard type + CorePasteboardFlavorType 0x6D6F6F76 + NSColor pasteboard type + NSFilenamesPboardType + NSStringPboardType + NeXT Encapsulated PostScript v1.2 pasteboard type + NeXT RTFD pasteboard type + NeXT Rich Text Format v1.0 pasteboard type + NeXT TIFF v4.0 pasteboard type + NeXT font pasteboard type + NeXT ruler pasteboard type + WebURLsWithTitlesPboardType + public.url + + {542, 14} @@ -4104,7 +4125,7 @@ 268 - {{81, 499}, {34, 14}} + {{106, 499}, {34, 14}} YES @@ -4120,7 +4141,7 @@ 266 - {{305, 473}, {348, 14}} + {{327, 473}, {348, 14}} YES @@ -4136,7 +4157,7 @@ 266 - {{308, 498}, {345, 14}} + {{330, 498}, {345, 14}} YES @@ -4152,7 +4173,7 @@ 268 - {{58, 473}, {57, 14}} + {{83, 473}, {57, 14}} YES @@ -4168,7 +4189,7 @@ 268 - {{59, 448}, {57, 14}} + {{84, 448}, {57, 14}} YES @@ -4184,7 +4205,7 @@ 268 - {{117, 494}, {161, 22}} + {{142, 494}, {161, 22}} YES @@ -4216,7 +4237,7 @@ 268 - {{117, 469}, {161, 22}} + {{142, 469}, {161, 22}} YES @@ -4248,7 +4269,7 @@ 268 - {{117, 444}, {161, 22}} + {{142, 444}, {161, 22}} YES @@ -4324,7 +4345,7 @@ 270 - {{22, 398}, {258, 14}} + {{48, 398}, {251, 14}} YES @@ -4340,7 +4361,7 @@ 270 - {{46, 376}, {234, 14}} + {{72, 376}, {227, 14}} YES @@ -4356,7 +4377,7 @@ 270 - {{23, 354}, {257, 14}} + {{49, 354}, {250, 14}} YES @@ -4372,7 +4393,7 @@ 270 - {{25, 332}, {255, 14}} + {{51, 332}, {248, 14}} YES @@ -4388,7 +4409,7 @@ 270 - {{314, 398}, {363, 14}} + {{328, 398}, {347, 14}} YES @@ -4404,7 +4425,7 @@ 270 - {{290, 376}, {386, 14}} + {{304, 376}, {371, 14}} YES @@ -4420,7 +4441,7 @@ 266 - {{309, 354}, {368, 14}} + {{323, 354}, {352, 14}} YES @@ -4436,7 +4457,7 @@ 266 - {{289, 332}, {389, 14}} + {{303, 332}, {372, 14}} YES @@ -4449,8 +4470,82 @@ + + + 268 + {{25.5, 329.5}, {20, 20}} + + YES + + 71433792 + 134350848 + + + -2034089729 + 162 + + + 400 + 75 + + + YES + Item 1 + + 1048576 + 2147483647 + 1 + + NSImage + NSAdvanced + + + + _popUpItemAction: + + + YES + + OtherViews + + YES + + + + Reset AUTO_INCREMENT + + 1048576 + 2147483647 + + + _popUpItemAction: + 2 + + + + + Reset AUTO_INCREMENT to… + + 1048576 + 2147483647 + + + _popUpItemAction: + 1 + + + + + + YES + 1 + YES + YES + + {{10, 7}, {706, 544}} + Status @@ -5285,14 +5380,14 @@ - + 134217731 YES YES YES - + @@ -6269,7 +6364,7 @@ {600, 127} {260, 127} - + 256 YES @@ -6278,7 +6373,6 @@ 266 {{17, 93}, {226, 14}} - YES 67239488 @@ -6295,7 +6389,6 @@ 258 {{20, 67}, {220, 18}} - YES -1804468671 @@ -6313,7 +6406,6 @@ 292 {{19, 43}, {189, 18}} - YES 67239424 @@ -6335,7 +6427,6 @@ 289 {{158, 13}, {87, 28}} - 1 YES @@ -6359,7 +6450,6 @@ 289 {{80, 13}, {80, 28}} - YES 67239424 @@ -6378,8 +6468,6 @@ {260, 127} - - {{0, 0}, {1440, 878}} {260, 149} @@ -6856,7 +6944,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {3.40282e+38, 3.40282e+38} {255, 95} - + 301 YES @@ -7026,7 +7114,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {255, 95} - {{0, 0}, {1280, 1002}} {255, 117} @@ -11545,6 +11632,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 2147483647 + 1 @@ -15669,6 +15757,54 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 6853 + + + tableSourceInstance + + + + 6866 + + + + resetAutoIncrementResetButton + + + + 6867 + + + + resetAutoIncrement: + + + + 6872 + + + + resetAutoIncrement: + + + + 6873 + + + + extendedTableInfoInstance + + + + 6875 + + + + resetAutoIncrementLine + + + + 6876 + @@ -17673,6 +17809,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 + @@ -22077,6 +22214,50 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 + + 6856 + + + YES + + + + + + 6857 + + + YES + + + + + + 6858 + + + YES + + + + + + + + 6859 + + + + + 6860 + + + + + 6861 + + + 6852 @@ -22641,6 +22822,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 4795.IBPluginDependency 5.IBEditorWindowLastContentRect 5.IBPluginDependency + 5.IBViewEditorWindowController.showingBoundsRectangles 5.IBViewEditorWindowController.showingLayoutRectangles 5.IBWindowTemplateEditedContentRect 5.ImportedFromIB2 @@ -23430,6 +23612,15 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 6842.IBNumberFormatterLocalizesFormatMetadataKey 6842.IBPluginDependency 6852.IBPluginDependency + 6856.IBAttributePlaceholdersKey + 6856.IBPluginDependency + 6857.IBPluginDependency + 6858.IBEditorWindowLastContentRect + 6858.IBPluginDependency + 6859.IBPluginDependency + 6860.IBAttributePlaceholdersKey + 6860.IBPluginDependency + 6861.IBPluginDependency 69.ImportedFromIB2 711.IBPluginDependency 711.ImportedFromIB2 @@ -24240,10 +24431,11 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{386, 124}, {944, 550}} + {{118, 138}, {944, 550}} com.apple.InterfaceBuilder.CocoaPlugin + - {{386, 124}, {944, 550}} + {{118, 138}, {944, 550}} {{62, 352}, {845, 504}} @@ -24409,7 +24601,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{1592, 135}, {256, 445}} + {{110, 61}, {256, 445}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -24941,7 +25133,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{825, 570}, {233, 53}} + {{735, 570}, {233, 53}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin {{886, 867}, {231, 113}} @@ -25381,6 +25573,29 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + Reset AUTO_INCREMENT… + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + {{553, 340}, {227, 168}} + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + Reset AUTO_INCREMENT to the minimal possible value. + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -25525,7 +25740,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 - 6853 + 6876 @@ -26376,6 +26591,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 schemasTableView tabView treeController + userNameTextField YES @@ -26391,6 +26607,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 NSTableView NSTabView NSTreeController + NSTextField @@ -26554,6 +26771,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 saveConnectionSheet: saveCreateSyntax: setDatabases: + showConsole: showCreateTableSyntax: showMySQLHelp: showServerProcesses: @@ -26609,6 +26827,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 id id id + id @@ -26754,13 +26973,10 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 YES cancelProgressBar: changeFormat: - changeTable: - closeFieldMapperSheet: closeSheet: panelSelectionDidChange: reloadTables: selectTables: - stepRow: switchInput: switchTab: @@ -26774,9 +26990,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 id id id - id - id - id @@ -26812,11 +27025,9 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 exportTableList exportToolbar exportWindow - fieldMappingPopup - fieldMappingSheet - fieldMappingTableView importCSVBox importCSVView + importFieldMapperSheetWindow importFieldNamesSwitch importFieldsEnclosedField importFieldsEscapedField @@ -26825,9 +27036,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 importLinesTerminatedField multiCSVFullStreamingSwitch multiXMLFullStreamingSwitch - recordCountLabel - rowDownButton - rowUpButton singleProgressBar singleProgressSheet singleProgressText @@ -26878,8 +27086,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 id id id - id - id NSPopUpButton id id @@ -26895,9 +27101,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 id id id - id - id - id @@ -26929,6 +27132,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 reloadTable: removeField: removeIndex: + resetAutoIncrement: YES @@ -26941,6 +27145,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 id id id + id @@ -26962,9 +27167,12 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 reloadIndexesButton removeFieldButton removeIndexButton + resetAutoIncrementSheet + resetAutoIncrementValue structureGrabber tableDataInstance tableDocumentInstance + tableInfoInstance tableSourceView tableWindow tablesListInstance @@ -26992,6 +27200,9 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 id id id + id + id + id @@ -27137,6 +27348,84 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 YES + + SPExtendedTableInfo + NSObject + + YES + + YES + reloadTable: + resetAutoIncrement: + updateTableCollation: + updateTableEncoding: + updateTableType: + + + YES + id + id + id + id + id + + + + YES + + YES + databaseDataInstance + resetAutoIncrementResetButton + tableCollationPopUpButton + tableCommentsTextView + tableCreateSyntaxTextView + tableCreatedAt + tableDataInstance + tableDataSize + tableDocumentInstance + tableEncodingPopUpButton + tableIndexSize + tableMaxDataSize + tableRowAutoIncrement + tableRowAvgLength + tableRowFormat + tableRowNumber + tableSizeFree + tableSourceInstance + tableTypePopUpButton + tableUpdatedAt + tablesListInstance + + + YES + SPDatabaseData + id + NSPopUpButton + NSTextView + NSTextView + NSTextField + SPTableData + NSTextField + id + NSPopUpButton + NSTextField + NSTextField + NSTextField + NSTextField + NSTextField + NSTextField + NSTextField + id + NSPopUpButton + NSTextField + TablesList + + + + IBDocumentRelativeSource + ../../Source/SPExtendedTableInfo.h + + TableSource NSObject @@ -27178,6 +27467,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 chooseKeyButton copyFieldButton editTableButton + extendedTableInfoInstance indexNameField indexSheet indexTypeField @@ -27188,6 +27478,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 reloadIndexesButton removeFieldButton removeIndexButton + resetAutoIncrementLine resetAutoIncrementSheet resetAutoIncrementValue structureGrabber @@ -27224,6 +27515,8 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 id id id + id + id @@ -27547,6 +27840,14 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 NSMutableDictionary + + NSNumberFormatter + NSFormatter + + IBFrameworkSource + Foundation.framework/Headers/NSNumberFormatter.h + + NSObject 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