aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/SPAlertSheets.m1
-rw-r--r--Source/SPExtendedTableInfo.h4
-rw-r--r--Source/SPExtendedTableInfo.m18
-rw-r--r--Source/TableDocument.m7
-rw-r--r--Source/TableSource.h3
-rw-r--r--Source/TableSource.m72
6 files changed, 79 insertions, 26 deletions
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