diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/TableDocument.m | 21 | ||||
-rw-r--r-- | Source/TableSource.h | 3 | ||||
-rw-r--r-- | Source/TableSource.m | 25 |
3 files changed, 49 insertions, 0 deletions
diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 2d15e4e2..b8261a8e 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -3609,6 +3609,27 @@ } #pragma mark - +#pragma mark General sheet delegate methods + +- (NSRect)window:(NSWindow *)window willPositionSheet:(NSWindow *)sheet usingRect:(NSRect)rect { + + // Locate the sheet "Reset Auto Increment" just beneath the chosen index row + if([[sheet title] isEqualToString:@"Reset Auto Increment"]) { + + id it = [tableSourceInstance valueForKeyPath:@"indexView"]; + NSRect mwrect = [[NSApp mainWindow] frame]; + NSRect ltrect = [[tablesListInstance valueForKeyPath:@"tablesListView"] frame]; + NSRect rowrect = [it rectOfRow:[it selectedRow]]; + rowrect.size.width = mwrect.size.width - ltrect.size.width; + rowrect.origin.y -= [it rowHeight]/2.0f+2; + return [it convertRect:rowrect toView:nil]; + + } else + return rect; + +} + +#pragma mark - #pragma mark SplitView delegate methods /** diff --git a/Source/TableSource.h b/Source/TableSource.h index 10c82dae..e09dd16b 100644 --- a/Source/TableSource.h +++ b/Source/TableSource.h @@ -35,6 +35,8 @@ IBOutlet id tableWindow; IBOutlet id indexSheet; IBOutlet id keySheet; + IBOutlet id resetAutoIncrementSheet; + IBOutlet id resetAutoIncrementValue; IBOutlet id tableSourceView; IBOutlet id indexView; IBOutlet id addFieldButton; @@ -73,6 +75,7 @@ - (IBAction)copyField:(id)sender; - (IBAction)removeField:(id)sender; - (IBAction)removeIndex:(id)sender; +- (IBAction)resetAutoIncrement:(id)sender; // Index sheet methods - (IBAction)openIndexSheet:(id)sender; diff --git a/Source/TableSource.m b/Source/TableSource.m index 79a7f4ae..f704dcec 100644 --- a/Source/TableSource.m +++ b/Source/TableSource.m @@ -456,6 +456,20 @@ loads aTable, put it in an array, update the tableViewColumns and reload the tab [alert beginSheetModalForWindow:tableWindow modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:(hasForeignKey) ? @"removeIndexAndForeignKey" : @"removeIndex"]; } +- (IBAction)resetAutoIncrement:(id)sender +{ + + // Begin the sheet + [NSApp beginSheet:resetAutoIncrementSheet + modalForWindow:tableWindow + modalDelegate:self + didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) + contextInfo:@"resetAutoIncrement"]; + + [resetAutoIncrementValue setStringValue:@"1"]; + +} + #pragma mark - #pragma mark Index sheet methods @@ -925,6 +939,12 @@ fetches the result as an array with a dictionary for each row in it return ([indexView numberOfSelectedRows] == 1); } + // Reset AUTO_INCREMENT + if ([menuItem action] == @selector(resetAutoIncrement:)) { + return NO; + return ([indexView numberOfSelectedRows] == 1 ); + } + return YES; } @@ -988,6 +1008,11 @@ fetches the result as an array with a dictionary for each row in it else if ([contextInfo isEqualToString:@"cannotremovefield"]) { ; } + else if ([contextInfo isEqualToString:@"resetAutoIncrement"]) { + if (returnCode == NSAlertDefaultReturn) { + // ALTER TABLE tbl_name AUTO_INCREMENT = N + } + } else alertSheetOpened = NO; } |