diff options
-rw-r--r-- | Interfaces/English.lproj/DBView.xib | 69 | ||||
-rw-r--r-- | Source/SPTableStructure.h | 4 | ||||
-rw-r--r-- | Source/SPTableStructure.m | 107 | ||||
-rw-r--r-- | Source/SPTableStructureDelegate.m | 14 |
4 files changed, 94 insertions, 100 deletions
diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib index a17ee340..3a32ac16 100644 --- a/Interfaces/English.lproj/DBView.xib +++ b/Interfaces/English.lproj/DBView.xib @@ -23,8 +23,6 @@ </object> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> - <integer value="6735"/> - <integer value="1309"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -48,7 +46,7 @@ <string key="NSClassName">NSApplication</string> </object> <object class="NSCustomView" id="632807581"> - <reference key="NSNextResponder"/> + <nil key="NSNextResponder"/> <int key="NSvFlags">274</int> <object class="NSMutableArray" key="NSSubviews"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -268,7 +266,6 @@ </object> <string key="NSFrame">{{1, 1}, {218, 38}}</string> <reference key="NSSuperview" ref="607475905"/> - <reference key="NSNextKeyView" ref="970881282"/> <reference key="NSDocView" ref="970881282"/> <object class="NSColor" key="NSBGColor" id="1024678221"> <int key="NSColorSpace">6</int> @@ -300,7 +297,6 @@ </object> <string key="NSFrame">{{-1, -13}, {220, 40}}</string> <reference key="NSSuperview" ref="801427893"/> - <reference key="NSNextKeyView" ref="494991824"/> <int key="NSsFlags">2</int> <reference key="NSVScroller" ref="196112633"/> <reference key="NSHScroller" ref="142487484"/> @@ -398,7 +394,6 @@ </object> <string key="NSFrameSize">{214, 354}</string> <reference key="NSSuperview" ref="233472824"/> - <reference key="NSNextKeyView" ref="251040077"/> <reference key="NSDocView" ref="251040077"/> <reference key="NSBGColor" ref="1024678221"/> <int key="NScvFlags">4</int> @@ -426,7 +421,6 @@ </object> <string key="NSFrameSize">{214, 354}</string> <reference key="NSSuperview" ref="1017775084"/> - <reference key="NSNextKeyView" ref="73685676"/> <int key="NSsFlags">528</int> <reference key="NSVScroller" ref="693168867"/> <reference key="NSHScroller" ref="656188692"/> @@ -562,7 +556,6 @@ </object> <string key="NSFrameSize">{214, 145}</string> <reference key="NSSuperview" ref="298226231"/> - <reference key="NSNextKeyView" ref="347093764"/> <reference key="NSDocView" ref="347093764"/> <reference key="NSBGColor" ref="1024678221"/> <int key="NScvFlags">6</int> @@ -590,7 +583,6 @@ </object> <string key="NSFrameSize">{214, 145}</string> <reference key="NSSuperview" ref="192579410"/> - <reference key="NSNextKeyView" ref="685057119"/> <int key="NSsFlags">512</int> <reference key="NSVScroller" ref="245346414"/> <reference key="NSHScroller" ref="353686052"/> @@ -1477,7 +1469,7 @@ <object class="NSComboTableView" key="NSTableView" id="1025423991"> <reference key="NSNextResponder"/> <int key="NSvFlags">274</int> - <string key="NSFrameSize">{13, 72}</string> + <string key="NSFrameSize">{15, 0}</string> <reference key="NSSuperview"/> <reference key="NSWindow"/> <bool key="NSEnabled">YES</bool> @@ -1485,7 +1477,7 @@ <bool key="EncodedWithXMLCoder">YES</bool> <object class="NSTableColumn"> <integer value="0" key="NSIdentifier"/> - <double key="NSWidth">10</double> + <double key="NSWidth">12</double> <double key="NSMinWidth">10</double> <double key="NSMaxWidth">1000</double> <object class="NSTableHeaderCell" key="NSHeaderCell"> @@ -1516,7 +1508,7 @@ <reference key="NSGridColor" ref="864903678"/> <double key="NSRowHeight">16</double> <string key="NSAction">tableViewAction:</string> - <int key="NSTvFlags">-228556800</int> + <int key="NSTvFlags">-230653952</int> <reference key="NSDelegate" ref="462958080"/> <reference key="NSDataSource" ref="462958080"/> <reference key="NSTarget" ref="462958080"/> @@ -1667,7 +1659,6 @@ </object> <string key="NSFrame">{{1, 17}, {694, 289}}</string> <reference key="NSSuperview" ref="22340145"/> - <reference key="NSNextKeyView" ref="715508012"/> <reference key="NSDocView" ref="715508012"/> <reference key="NSBGColor" ref="1024678221"/> <int key="NScvFlags">4</int> @@ -1701,7 +1692,6 @@ </object> <string key="NSFrame">{{1, 0}, {694, 17}}</string> <reference key="NSSuperview" ref="22340145"/> - <reference key="NSNextKeyView" ref="926883367"/> <reference key="NSDocView" ref="926883367"/> <reference key="NSBGColor" ref="1024678221"/> <int key="NScvFlags">4</int> @@ -1710,7 +1700,6 @@ </object> <string key="NSFrame">{{-1, 22}, {696, 307}}</string> <reference key="NSSuperview" ref="220777809"/> - <reference key="NSNextKeyView" ref="16936123"/> <int key="NSsFlags">562</int> <reference key="NSVScroller" ref="943144555"/> <reference key="NSHScroller" ref="456666876"/> @@ -2257,7 +2246,6 @@ </object> <string key="NSFrame">{{1, 17}, {694, 140}}</string> <reference key="NSSuperview" ref="376224367"/> - <reference key="NSNextKeyView" ref="584834515"/> <reference key="NSDocView" ref="584834515"/> <reference key="NSBGColor" ref="1024678221"/> <int key="NScvFlags">4</int> @@ -2290,7 +2278,6 @@ </object> <string key="NSFrame">{{1, 0}, {694, 17}}</string> <reference key="NSSuperview" ref="376224367"/> - <reference key="NSNextKeyView" ref="459548655"/> <reference key="NSDocView" ref="459548655"/> <reference key="NSBGColor" ref="1024678221"/> <int key="NScvFlags">4</int> @@ -2299,7 +2286,6 @@ </object> <string key="NSFrame">{{-1, 23}, {696, 158}}</string> <reference key="NSSuperview" ref="1063281455"/> - <reference key="NSNextKeyView" ref="794929378"/> <int key="NSsFlags">562</int> <reference key="NSVScroller" ref="1019209947"/> <reference key="NSHScroller" ref="328951385"/> @@ -6184,7 +6170,6 @@ </object> </object> <string key="NSFrameSize">{943, 549}</string> - <reference key="NSSuperview"/> <string key="NSClassName">NSView</string> </object> <object class="NSWindowTemplate" id="554105051"> @@ -6910,7 +6895,7 @@ <string key="NSWindowContentMaxSize">{3.40282e+38, 3.40282e+38}</string> <string key="NSWindowContentMinSize">{213, 107}</string> <object class="NSView" key="NSWindowView" id="234287744"> - <nil key="NSNextResponder"/> + <reference key="NSNextResponder"/> <int key="NSvFlags">256</int> <object class="NSMutableArray" key="NSSubviews"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -6919,6 +6904,7 @@ <int key="NSvFlags">256</int> <string key="NSFrame">{{17, 74}, {272, 28}}</string> <reference key="NSSuperview" ref="234287744"/> + <reference key="NSWindow"/> <bool key="NSEnabled">YES</bool> <object class="NSTextFieldCell" key="NSCell" id="420541191"> <int key="NSCellFlags">67239424</int> @@ -6936,6 +6922,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> <int key="NSvFlags">256</int> <string key="NSFrame">{{74, 45}, {162, 22}}</string> <reference key="NSSuperview" ref="234287744"/> + <reference key="NSWindow"/> <bool key="NSEnabled">YES</bool> <object class="NSPopUpButtonCell" key="NSCell" id="1007861376"> <int key="NSCellFlags">-2076049856</int> @@ -7017,6 +7004,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> <int key="NSvFlags">256</int> <string key="NSFrame">{{154, 17}, {84, 28}}</string> <reference key="NSSuperview" ref="234287744"/> + <reference key="NSWindow"/> <int key="NSTag">1</int> <bool key="NSEnabled">YES</bool> <object class="NSButtonCell" key="NSCell" id="827163428"> @@ -7040,6 +7028,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> <int key="NSvFlags">256</int> <string key="NSFrame">{{72, 17}, {84, 28}}</string> <reference key="NSSuperview" ref="234287744"/> + <reference key="NSWindow"/> <bool key="NSEnabled">YES</bool> <object class="NSButtonCell" key="NSCell" id="125727271"> <int key="NSCellFlags">67239424</int> @@ -7051,15 +7040,15 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> <int key="NSButtonFlags2">1</int> <reference key="NSAlternateImage" ref="932958253"/> <string key="NSAlternateContents"/> - <object class="NSMutableString" key="NSKeyEquivalent"> - <characters key="NS.bytes"/> - </object> + <string type="base64-UTF8" key="NSKeyEquivalent">Gw</string> <int key="NSPeriodicDelay">200</int> <int key="NSPeriodicInterval">25</int> </object> </object> </object> <string key="NSFrameSize">{306, 122}</string> + <reference key="NSSuperview"/> + <reference key="NSWindow"/> </object> <string key="NSScreenRect">{{0, 0}, {1440, 878}}</string> <string key="NSMinSize">{213, 129}</string> @@ -11752,22 +11741,6 @@ bGQgTmFtZQkgID0gQAoJCQkJICBMRU5HVEgoYEBgKSA+IEA</bytes> <int key="connectionID">421</int> </object> <object class="IBConnectionRecord"> - <object class="IBActionConnection" key="connection"> - <string key="label">closeKeySheet:</string> - <reference key="source" ref="103234030"/> - <reference key="destination" ref="1033996434"/> - </object> - <int key="connectionID">422</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBActionConnection" key="connection"> - <string key="label">closeKeySheet:</string> - <reference key="source" ref="103234030"/> - <reference key="destination" ref="516472893"/> - </object> - <int key="connectionID">423</int> - </object> - <object class="IBConnectionRecord"> <object class="IBOutletConnection" key="connection"> <string key="label">copyTableNameField</string> <reference key="source" ref="438574515"/> @@ -16168,6 +16141,22 @@ bGQgTmFtZQkgID0gQAoJCQkJICBMRU5HVEgoYEBgKSA+IEA</bytes> </object> <int key="connectionID">7670</int> </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">closeSheet:</string> + <reference key="source" ref="103234030"/> + <reference key="destination" ref="1033996434"/> + </object> + <int key="connectionID">7671</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">closeSheet:</string> + <reference key="source" ref="103234030"/> + <reference key="destination" ref="516472893"/> + </object> + <int key="connectionID">7672</int> + </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -25814,7 +25803,7 @@ bGQgTmFtZQkgID0gQAoJCQkJICBMRU5HVEgoYEBgKSA+IEA</bytes> </object> </object> <nil key="sourceID"/> - <int key="maxID">7670</int> + <int key="maxID">7672</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> diff --git a/Source/SPTableStructure.h b/Source/SPTableStructure.h index fe13b944..c7b47e1a 100644 --- a/Source/SPTableStructure.h +++ b/Source/SPTableStructure.h @@ -75,6 +75,7 @@ NSArray *typeSuggestions; NSArray *extraFieldSuggestions; BOOL isCurrentExtraAutoIncrement; + NSString *autoIncrementIndex; BOOL isEditingRow, isEditingNewRow, isSavingRow, alertSheetOpened; } @@ -96,9 +97,6 @@ // Index sheet methods - (IBAction)closeSheet:(id)sender; -// Key sheet methods -- (IBAction)closeKeySheet:(id)sender; - // Additional methods - (void)setConnection:(MCPConnection *)theConnection; - (NSArray *)fetchResultAsArray:(MCPResult *)theResult; diff --git a/Source/SPTableStructure.m b/Source/SPTableStructure.m index 2392c108..86b4a84a 100644 --- a/Source/SPTableStructure.m +++ b/Source/SPTableStructure.m @@ -61,6 +61,7 @@ extraFieldSuggestions = nil; currentlyEditingRow = -1; isCurrentExtraAutoIncrement = NO; + autoIncrementIndex = nil; fieldValidation = [[SPTableFieldValidation alloc] init]; @@ -337,6 +338,7 @@ [[self onMainThread] setTableDetails:tableDetails]; isCurrentExtraAutoIncrement = [tableDataInstance tableHasAutoIncrementField]; + autoIncrementIndex = nil; // Send the query finished/work complete notification [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance]; @@ -718,6 +720,7 @@ } isEditingRow = NO; isCurrentExtraAutoIncrement = [tableDataInstance tableHasAutoIncrementField]; + autoIncrementIndex = nil; [tableSourceView reloadData]; currentlyEditingRow = -1; [[tableDocumentInstance parentWindow] makeFirstResponder:tableSourceView]; @@ -732,6 +735,7 @@ [tablesIndexesSplitView setPosition:[tablesIndexesSplitView frame].size.height-130 ofDividerAtIndex:0]; } + #pragma mark - #pragma mark Index sheet methods @@ -744,14 +748,6 @@ [[sender window] orderOut:self]; } -/** - * Closes the key sheet. - */ -- (IBAction)closeKeySheet:(id)sender -{ - [NSApp stopModalWithCode:[sender tag]]; -} - #pragma mark - #pragma mark Additional methods @@ -1047,66 +1043,53 @@ } } - // Asks the user to add an index to query if AUTO_INCREMENT is set and field isn't indexed - if ([theRowExtra isEqualToString:@"AUTO_INCREMENT"] && (![theRow objectForKey:@"Key"] || [[theRow objectForKey:@"Key"] isEqualToString:@""])) - { - [chooseKeyButton selectItemAtIndex:0]; - - [NSApp beginSheet:keySheet - modalForWindow:[tableDocumentInstance parentWindow] modalDelegate:self - didEndSelector:nil - contextInfo:nil]; - - code = [NSApp runModalForWindow:keySheet]; - - [NSApp endSheet:keySheet]; - [keySheet orderOut:nil]; - - if (code) { - // User wants to add PRIMARY KEY - if ([chooseKeyButton indexOfSelectedItem] == 0) { - [queryString appendString:@"\n PRIMARY KEY"]; + // Process index if given for fields set to AUTO_INCREMENT + if (autoIncrementIndex) { + // User wants to add PRIMARY KEY + if ([autoIncrementIndex isEqualToString:@"PRIMARY KEY"]) { + [queryString appendString:@"\n PRIMARY KEY"]; + + // If the field isn't set to be unsigned and we're making it the primary key then make it unsigned + if (![[theRow objectForKey:@"unsigned"] boolValue]) { - // If the field isn't set to be unsigned and we're making it the primary key then make it unsigned - if (![[theRow objectForKey:@"unsigned"] boolValue]) { - - // Find the occurrence of the table name and data type so we know where to insert the - // UNSIGNED keyword. - NSRange range = [queryString rangeOfString:[NSString stringWithFormat:@"%@ %@", [[theRow objectForKey:@"name"] backtickQuotedString], theRowType] options:NSLiteralSearch]; - - NSInteger index = (range.location + range.length); - - // If the field definition's data type includes the length then we must take this into - // account when inserting the UNSIGNED keyword. Add 2 to the index to accommodate the - // parentheses used. - if (fieldDefIncludesLen) { - index += ([[theRow objectForKey:@"length"] length] + 2); - } - - [queryString insertString:@" UNSIGNED" atIndex:index]; - } - - // Add AFTER ... only if the user added a new field - if (isEditingNewRow) { - [queryString appendFormat:@"\n AFTER %@", [[[tableFields objectAtIndex:(currentlyEditingRow -1)] objectForKey:@"name"] backtickQuotedString]]; + // Find the occurrence of the table name and data type so we know where to insert the + // UNSIGNED keyword. + NSRange range = [queryString rangeOfString:[NSString stringWithFormat:@"%@ %@", [[theRow objectForKey:@"name"] backtickQuotedString], theRowType] options:NSLiteralSearch]; + + NSInteger index = (range.location + range.length); + + // If the field definition's data type includes the length then we must take this into + // account when inserting the UNSIGNED keyword. Add 2 to the index to accommodate the + // parentheses used. + if (fieldDefIncludesLen) { + index += ([[theRow objectForKey:@"length"] length] + 2); } + + [queryString insertString:@" UNSIGNED" atIndex:index]; } - else { - // Add AFTER ... only if the user added a new field - if (isEditingNewRow) { - [queryString appendFormat:@"\n AFTER %@", [[[tableFields objectAtIndex:(currentlyEditingRow -1)] objectForKey:@"name"] backtickQuotedString]]; - } - - [queryString appendFormat:@"\n, ADD %@ (%@)", [chooseKeyButton titleOfSelectedItem], [[theRow objectForKey:@"name"] backtickQuotedString]]; + + // Add AFTER ... only if the user added a new field + if (isEditingNewRow) { + [queryString appendFormat:@"\n AFTER %@", [[[tableFields objectAtIndex:(currentlyEditingRow -1)] objectForKey:@"name"] backtickQuotedString]]; + } + } + else { + // Add AFTER ... only if the user added a new field + if (isEditingNewRow) { + [queryString appendFormat:@"\n AFTER %@", [[[tableFields objectAtIndex:(currentlyEditingRow -1)] objectForKey:@"name"] backtickQuotedString]]; } + + [queryString appendFormat:@"\n, ADD %@ (%@)", autoIncrementIndex, [[theRow objectForKey:@"name"] backtickQuotedString]]; } } + // Add AFTER ... only if the user added a new field else if (isEditingNewRow) { [queryString appendFormat:@"\n AFTER %@", [[[tableFields objectAtIndex:(currentlyEditingRow -1)] objectForKey:@"name"] backtickQuotedString]]; } isCurrentExtraAutoIncrement = NO; + autoIncrementIndex = nil; // Execute query [mySQLConnection queryString:queryString]; @@ -1233,6 +1216,18 @@ [[sheet window] orderOut:nil]; alertSheetOpened = NO; + + if(contextInfo && [contextInfo isEqualToString:@"autoincrementindex"]) { + if(returnCode) { + autoIncrementIndex = [chooseKeyButton titleOfSelectedItem]; + } else { + autoIncrementIndex = nil; + if([tableSourceView selectedRow] > -1 && [extraFieldSuggestions count]) + [[tableFields objectAtIndex:[tableSourceView selectedRow]] setObject:[extraFieldSuggestions objectAtIndex:0] forKey:@"Extra"]; + [tableSourceView reloadData]; + isCurrentExtraAutoIncrement = NO; + } + } } /** diff --git a/Source/SPTableStructureDelegate.m b/Source/SPTableStructureDelegate.m index bdc3cb3f..84c0a80c 100644 --- a/Source/SPTableStructureDelegate.m +++ b/Source/SPTableStructureDelegate.m @@ -114,8 +114,20 @@ if(![[currentRow objectForKey:@"Extra"] isEqualToString:anObject]) { isCurrentExtraAutoIncrement = [[[anObject stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString] isEqualToString:@"AUTO_INCREMENT"]; - if(isCurrentExtraAutoIncrement) + if(isCurrentExtraAutoIncrement) { [currentRow setObject:[NSNumber numberWithInteger:0] forKey:@"null"]; + // Asks the user to add an index to query if AUTO_INCREMENT is set and field isn't indexed + if ((![currentRow objectForKey:@"Key"] || [[currentRow objectForKey:@"Key"] isEqualToString:@""])) { + [chooseKeyButton selectItemAtIndex:0]; + + [NSApp beginSheet:keySheet + modalForWindow:[tableDocumentInstance parentWindow] modalDelegate:self + didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) + contextInfo:@"autoincrementindex" ]; + } + } else { + autoIncrementIndex = nil; + } id dataCell = [aTableColumn dataCell]; [dataCell removeAllItems]; |