diff options
author | avenjamin <avenjamin@gmail.com> | 2009-05-20 09:10:05 +0000 |
---|---|---|
committer | avenjamin <avenjamin@gmail.com> | 2009-05-20 09:10:05 +0000 |
commit | f0b3b6ac71d728c880616cc899b03265330fb06f (patch) | |
tree | 5f64fdcb57310617c9435ad0043c5e0d3915703d | |
parent | 9d186d35c19ab8eff4e2bc69c929dda2819ab0c5 (diff) | |
download | sequelpro-f0b3b6ac71d728c880616cc899b03265330fb06f.tar.gz sequelpro-f0b3b6ac71d728c880616cc899b03265330fb06f.tar.bz2 sequelpro-f0b3b6ac71d728c880616cc899b03265330fb06f.zip |
- Added ability to insert field/column in structure mode.
- Inserts a field after the current selection or at the end if there is no field selected.
- Resolves issue #30
-rw-r--r-- | Source/TableSource.m | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/Source/TableSource.m b/Source/TableSource.m index 7ac9212e..3cc31deb 100644 --- a/Source/TableSource.m +++ b/Source/TableSource.m @@ -236,16 +236,19 @@ reloads the table (performing a new mysql-query) // Check whether a save of the current row is required. if ( ![self saveRowOnDeselect] ) return; - [tableFields addObject:[NSMutableDictionary - dictionaryWithObjects:[NSArray arrayWithObjects:@"", @"int", @"", @"0", @"0", @"0", ([prefs boolForKey:@"NewFieldsAllowNulls"]) ? @"YES" : @"NO", @"", [prefs stringForKey:@"NullValue"], @"None", nil] - forKeys:[NSArray arrayWithObjects:@"Field", @"Type", @"Length", @"unsigned", @"zerofill", @"binary", @"Null", @"Key", @"Default", @"Extra", nil]]]; + int insertIndex = ([tableSourceView numberOfSelectedRows] == 0 ? [tableSourceView numberOfRows] : [tableSourceView selectedRow] + 1); + + [tableFields insertObject:[NSMutableDictionary + dictionaryWithObjects:[NSArray arrayWithObjects:@"", @"int", @"", @"0", @"0", @"0", ([prefs boolForKey:@"NewFieldsAllowNulls"]) ? @"YES" : @"NO", @"", [prefs stringForKey:@"NullValue"], @"None", nil] + forKeys:[NSArray arrayWithObjects:@"Field", @"Type", @"Length", @"unsigned", @"zerofill", @"binary", @"Null", @"Key", @"Default", @"Extra", nil]] + atIndex:insertIndex]; [tableSourceView reloadData]; - [tableSourceView selectRow:[tableSourceView numberOfRows]-1 byExtendingSelection:NO]; + [tableSourceView selectRow:insertIndex byExtendingSelection:NO]; isEditingRow = YES; isEditingNewRow = YES; currentlyEditingRow = [tableSourceView selectedRow]; - [tableSourceView editColumn:0 row:[tableSourceView numberOfRows]-1 withEvent:nil select:YES]; + [tableSourceView editColumn:0 row:insertIndex withEvent:nil select:YES]; } /** @@ -711,10 +714,14 @@ fetches the result as an array with a dictionary for each row in it if ( code ) { if ( [chooseKeyButton indexOfSelectedItem] == 0 ) { [queryString appendString:@" PRIMARY KEY"]; + [queryString appendString:[NSString stringWithFormat:@" AFTER %@", [[[tableFields objectAtIndex:(currentlyEditingRow -1)] objectForKey:@"Field"] backtickQuotedString]]]; } else { + [queryString appendString:[NSString stringWithFormat:@" AFTER %@", [[[tableFields objectAtIndex:(currentlyEditingRow -1)] objectForKey:@"Field"] backtickQuotedString]]]; [queryString appendString:[NSString stringWithFormat:@", ADD %@ (%@)", [chooseKeyButton titleOfSelectedItem], [[theRow objectForKey:@"Field"] backtickQuotedString]]]; } } + } else { + [queryString appendString:[NSString stringWithFormat:@" AFTER %@", [[[tableFields objectAtIndex:(currentlyEditingRow -1)] objectForKey:@"Field"] backtickQuotedString]]]; } [mySQLConnection queryString:queryString]; |