aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Interfaces/English.lproj/DBView.xib81
-rw-r--r--Source/TableSource.h7
-rw-r--r--Source/TableSource.m362
-rw-r--r--Source/TablesList.m2
4 files changed, 234 insertions, 218 deletions
diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib
index 0412d077..fbc8ee83 100644
--- a/Interfaces/English.lproj/DBView.xib
+++ b/Interfaces/English.lproj/DBView.xib
@@ -281,6 +281,7 @@
</object>
<string key="NSFrameSize">{212, 26}</string>
<reference key="NSSuperview" ref="299440250"/>
+ <reference key="NSNextKeyView" ref="687169829"/>
<reference key="NSDocView" ref="687169829"/>
<object class="NSColor" key="NSBGColor" id="1024678221">
<int key="NSColorSpace">6</int>
@@ -313,6 +314,7 @@
</object>
<string key="NSFrameSize">{212, 26}</string>
<reference key="NSSuperview" ref="801427893"/>
+ <reference key="NSNextKeyView" ref="965350222"/>
<int key="NSsFlags">0</int>
<reference key="NSVScroller" ref="622721581"/>
<reference key="NSHScroller" ref="367421094"/>
@@ -410,6 +412,7 @@
</object>
<string key="NSFrameSize">{212, 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>
@@ -436,6 +439,7 @@
</object>
<string key="NSFrameSize">{212, 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"/>
@@ -571,6 +575,7 @@
</object>
<string key="NSFrameSize">{212, 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>
@@ -597,6 +602,7 @@
</object>
<string key="NSFrameSize">{212, 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"/>
@@ -1383,6 +1389,7 @@
</object>
<string key="NSFrame">{{1, 17}, {688, 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>
@@ -1415,6 +1422,7 @@
</object>
<string key="NSFrame">{{1, 0}, {688, 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>
@@ -1423,6 +1431,7 @@
</object>
<string key="NSFrame">{{-1, 22}, {690, 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"/>
@@ -1968,6 +1977,7 @@
</object>
<string key="NSFrame">{{1, 17}, {688, 142}}</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>
@@ -2000,6 +2010,7 @@
</object>
<string key="NSFrame">{{1, 0}, {688, 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>
@@ -2008,6 +2019,7 @@
</object>
<string key="NSFrame">{{-1, 22}, {690, 160}}</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"/>
@@ -5793,7 +5805,7 @@
<string key="NSWindowContentMaxSize">{600, 127}</string>
<string key="NSWindowContentMinSize">{260, 127}</string>
<object class="NSView" key="NSWindowView" id="653204527">
- <reference key="NSNextResponder"/>
+ <nil key="NSNextResponder"/>
<int key="NSvFlags">256</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -5802,7 +5814,6 @@
<int key="NSvFlags">266</int>
<string key="NSFrame">{{17, 93}, {226, 14}}</string>
<reference key="NSSuperview" ref="653204527"/>
- <reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="604072019">
<int key="NSCellFlags">67239488</int>
@@ -5819,7 +5830,6 @@
<int key="NSvFlags">258</int>
<string key="NSFrame">{{20, 67}, {220, 18}}</string>
<reference key="NSSuperview" ref="653204527"/>
- <reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="870160310">
<int key="NSCellFlags">-1804468671</int>
@@ -5837,7 +5847,6 @@
<int key="NSvFlags">292</int>
<string key="NSFrame">{{19, 43}, {189, 18}}</string>
<reference key="NSSuperview" ref="653204527"/>
- <reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="575635343">
<int key="NSCellFlags">67239424</int>
@@ -5859,7 +5868,6 @@
<int key="NSvFlags">289</int>
<string key="NSFrame">{{158, 13}, {87, 28}}</string>
<reference key="NSSuperview" ref="653204527"/>
- <reference key="NSWindow"/>
<int key="NSTag">1</int>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="834960254">
@@ -5883,7 +5891,6 @@
<int key="NSvFlags">289</int>
<string key="NSFrame">{{80, 13}, {80, 28}}</string>
<reference key="NSSuperview" ref="653204527"/>
- <reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="1048025876">
<int key="NSCellFlags">67239424</int>
@@ -5902,8 +5909,6 @@
</object>
</object>
<string key="NSFrameSize">{260, 127}</string>
- <reference key="NSSuperview"/>
- <reference key="NSWindow"/>
</object>
<string key="NSScreenRect">{{0, 0}, {1440, 878}}</string>
<string key="NSMinSize">{260, 149}</string>
@@ -6257,6 +6262,7 @@
<int key="NSvFlags">256</int>
<string key="NSFrame">{{172, 13}, {80, 28}}</string>
<reference key="NSSuperview" ref="329225443"/>
+ <int key="NSTag">1</int>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="178381476">
<int key="NSCellFlags">67239424</int>
@@ -6315,7 +6321,7 @@
<string key="NSWindowContentMaxSize">{3.40282e+38, 3.40282e+38}</string>
<string key="NSWindowContentMinSize">{213, 107}</string>
<object class="NSView" key="NSWindowView" id="234287744">
- <reference key="NSNextResponder"/>
+ <nil key="NSNextResponder"/>
<int key="NSvFlags">256</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -6324,7 +6330,6 @@
<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>
@@ -6342,7 +6347,6 @@ 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>
@@ -6424,7 +6428,6 @@ 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">
@@ -6448,7 +6451,6 @@ 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>
@@ -6469,8 +6471,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
</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>
@@ -7909,7 +7909,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<string key="NSWindowContentMaxSize">{3.40282e+38, 3.40282e+38}</string>
<string key="NSWindowContentMinSize">{213, 107}</string>
<object class="NSView" key="NSWindowView" id="860968037">
- <reference key="NSNextResponder"/>
+ <nil key="NSNextResponder"/>
<int key="NSvFlags">256</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -7918,7 +7918,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<int key="NSvFlags">264</int>
<string key="NSFrame">{{20, 233}, {140, 14}}</string>
<reference key="NSSuperview" ref="860968037"/>
- <reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="326519111">
<int key="NSCellFlags">67239424</int>
@@ -7945,7 +7944,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<int key="NSvFlags">2322</int>
<string key="NSFrameSize">{352, 14}</string>
<reference key="NSSuperview" ref="158897172"/>
- <reference key="NSWindow"/>
<object class="NSTextContainer" key="NSTextContainer" id="197710090">
<object class="NSLayoutManager" key="NSLayoutManager">
<object class="NSTextStorage" key="NSTextStorage">
@@ -7995,7 +7993,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
</object>
<string key="NSFrame">{{1, 1}, {352, 178}}</string>
<reference key="NSSuperview" ref="972781700"/>
- <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="347971361"/>
<reference key="NSDocView" ref="347971361"/>
<reference key="NSBGColor" ref="449903125"/>
@@ -8007,7 +8004,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<int key="NSvFlags">256</int>
<string key="NSFrame">{{353, 1}, {11, 178}}</string>
<reference key="NSSuperview" ref="972781700"/>
- <reference key="NSWindow"/>
<int key="NSsFlags">256</int>
<reference key="NSTarget" ref="972781700"/>
<string key="NSAction">_doScroller:</string>
@@ -8018,7 +8014,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<int key="NSvFlags">-2147483392</int>
<string key="NSFrame">{{-100, -100}, {87, 18}}</string>
<reference key="NSSuperview" ref="972781700"/>
- <reference key="NSWindow"/>
<int key="NSsFlags">257</int>
<reference key="NSTarget" ref="972781700"/>
<string key="NSAction">_doScroller:</string>
@@ -8028,7 +8023,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
</object>
<string key="NSFrame">{{20, 45}, {365, 180}}</string>
<reference key="NSSuperview" ref="860968037"/>
- <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="158897172"/>
<int key="NSsFlags">18</int>
<reference key="NSVScroller" ref="84024470"/>
@@ -8040,7 +8034,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<int key="NSvFlags">257</int>
<string key="NSFrame">{{314, 13}, {76, 28}}</string>
<reference key="NSSuperview" ref="860968037"/>
- <reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="693776804">
<int key="NSCellFlags">67239424</int>
@@ -8059,8 +8052,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
</object>
</object>
<string key="NSFrameSize">{405, 267}</string>
- <reference key="NSSuperview"/>
- <reference key="NSWindow"/>
</object>
<string key="NSScreenRect">{{0, 0}, {1440, 878}}</string>
<string key="NSMinSize">{213, 129}</string>
@@ -11629,22 +11620,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<int key="connectionID">339</int>
</object>
<object class="IBConnectionRecord">
- <object class="IBActionConnection" key="connection">
- <string key="label">addIndex:</string>
- <reference key="source" ref="103234030"/>
- <reference key="destination" ref="480365509"/>
- </object>
- <int key="connectionID">342</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBActionConnection" key="connection">
- <string key="label">closeIndexSheet:</string>
- <reference key="source" ref="103234030"/>
- <reference key="destination" ref="121996550"/>
- </object>
- <int key="connectionID">343</int>
- </object>
- <object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">indexTypeField</string>
<reference key="source" ref="103234030"/>
@@ -15249,6 +15224,22 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
</object>
<int key="connectionID">6640</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">closeSheet:</string>
+ <reference key="source" ref="103234030"/>
+ <reference key="destination" ref="121996550"/>
+ </object>
+ <int key="connectionID">6641</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">closeSheet:</string>
+ <reference key="source" ref="103234030"/>
+ <reference key="destination" ref="480365509"/>
+ </object>
+ <int key="connectionID">6642</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -23322,9 +23313,9 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<integer value="1"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<integer value="1"/>
- <string>{{427, 328}, {267, 139}}</string>
+ <string>{{769, 253}, {267, 139}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{427, 328}, {267, 139}}</string>
+ <string>{{769, 253}, {267, 139}}</string>
<integer value="1"/>
<integer value="0"/>
<integer value="1"/>
@@ -24841,7 +24832,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">6640</int>
+ <int key="maxID">6642</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -26110,8 +26101,8 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<string>addField:</string>
<string>addIndex:</string>
<string>chooseIndexType:</string>
- <string>closeIndexSheet:</string>
<string>closeKeySheet:</string>
+ <string>closeSheet:</string>
<string>copyField:</string>
<string>openIndexSheet:</string>
<string>reloadTable:</string>
diff --git a/Source/TableSource.h b/Source/TableSource.h
index c30a70bd..52030cdb 100644
--- a/Source/TableSource.h
+++ b/Source/TableSource.h
@@ -71,13 +71,12 @@
// Edit methods
- (IBAction)addField:(id)sender;
- (IBAction)copyField:(id)sender;
-- (IBAction)addIndex:(id)sender;
- (IBAction)removeField:(id)sender;
- (IBAction)removeIndex:(id)sender;
// Index sheet methods
- (IBAction)openIndexSheet:(id)sender;
-- (IBAction)closeIndexSheet:(id)sender;
+- (IBAction)closeSheet:(id)sender;
- (IBAction)chooseIndexType:(id)sender;
- (void)closeAlertSheet;
@@ -97,7 +96,7 @@
- (NSArray *)tableStructureForPrint;
// Task interaction
-- (void) startDocumentTaskForTab:(NSNotification *)aNotification;
-- (void) endDocumentTaskForTab:(NSNotification *)aNotification;
+- (void)startDocumentTaskForTab:(NSNotification *)aNotification;
+- (void)endDocumentTaskForTab:(NSNotification *)aNotification;
@end
diff --git a/Source/TableSource.m b/Source/TableSource.m
index d6e0af75..70f45100 100644
--- a/Source/TableSource.m
+++ b/Source/TableSource.m
@@ -32,6 +32,13 @@
#import "SPArrayAdditions.h"
#import "SPConstants.h"
+@interface TableSource (PrivateAPI)
+
+- (void)_addIndex;
+- (void)_removeIndex;
+
+@end
+
@implementation TableSource
/*
@@ -314,58 +321,6 @@ reloads the table (performing a new mysql-query)
}
/**
- * adds the index to the mysql-db and stops modal session with code 1 when success, 0 when error and -1 when no columns specified
- */
-- (IBAction)addIndex:(id)sender
-{
- NSString *indexName;
- NSArray *indexedColumns;
- NSMutableArray *tempIndexedColumns = [NSMutableArray array];
- NSEnumerator *enumerator;
- NSString *string;
-
- // Check whether a save of the current fields row is required.
- if ( ![self saveRowOnDeselect] ) return;
-
- if ( [[indexedColumnsField stringValue] isEqualToString:@""] ) {
- [NSApp stopModalWithCode:-1];
- } else {
- if ( [[indexNameField stringValue] isEqualToString:@"PRIMARY"] ) {
- indexName = @"";
- } else {
- if ( [[indexNameField stringValue] isEqualToString:@""] )
- {
- indexName = @"";
- } else {
- indexName = [[indexNameField stringValue] backtickQuotedString];
- }
- }
- indexedColumns = [[indexedColumnsField stringValue] componentsSeparatedByString:@","];
- enumerator = [indexedColumns objectEnumerator];
- while ( (string = [enumerator nextObject]) ) {
- if ( ([string characterAtIndex:0] == ' ') ) {
- [tempIndexedColumns addObject:[string substringWithRange:NSMakeRange(1,([string length]-1))]];
- } else {
- [tempIndexedColumns addObject:[NSString stringWithString:string]];
- }
- }
-
- [mySQLConnection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ ADD %@ %@ (%@)",
- [selectedTable backtickQuotedString], [indexTypeField titleOfSelectedItem], indexName,
- [tempIndexedColumns componentsJoinedAndBacktickQuoted]]];
-
- if ( [[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) {
- [tableDataInstance resetAllData];
- [tablesListInstance setStatusRequiresReload:YES];
- [self loadTable:selectedTable];
- [NSApp stopModalWithCode:1];
- } else {
- [NSApp stopModalWithCode:0];
- }
- }
-}
-
-/**
* Ask the user to confirm that they really want to remove the selected field.
*/
- (IBAction)removeField:(id)sender
@@ -374,8 +329,7 @@ reloads the table (performing a new mysql-query)
return;
// Check whether a save of the current row is required.
- if (![self saveRowOnDeselect])
- return;
+ if (![self saveRowOnDeselect]) return;
// Check if the user tries to delete the last defined field in table
if ([tableSourceView numberOfRows] < 2) {
@@ -415,12 +369,10 @@ reloads the table (performing a new mysql-query)
*/
- (IBAction)removeIndex:(id)sender
{
- if (![indexView numberOfSelectedRows])
- return;
+ if (![indexView numberOfSelectedRows]) return;
// Check whether a save of the current fields row is required.
- if (![self saveRowOnDeselect])
- return;
+ if (![self saveRowOnDeselect]) return;
NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Delete Index?", @"delete index message")
defaultButton:NSLocalizedString(@"Cancel", @"cancel button")
@@ -437,21 +389,24 @@ reloads the table (performing a new mysql-query)
[[buttons objectAtIndex:0] setKeyEquivalent:@""];
[[buttons objectAtIndex:1] setKeyEquivalent:@"\r"];
- [alert beginSheetModalForWindow:tableWindow modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:@"removeindex"];
+ [alert beginSheetModalForWindow:tableWindow
+ modalDelegate:self
+ didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
+ contextInfo:@"removeIndex"];
}
#pragma mark -
#pragma mark Index sheet methods
-/*
-opens the indexSheet
-*/
+/**
+ * Opens the add new index sheet.
+ */
- (IBAction)openIndexSheet:(id)sender
{
- int i, code = 0;
+ int i;
// Check whether a save of the current field row is required.
- if ( ![self saveRowOnDeselect] ) return;
+ if (![self saveRowOnDeselect]) return;
// Set sheet defaults - key type PRIMARY, key name PRIMARY and disabled, and blank indexed columns
[indexTypeField selectItemAtIndex:0];
@@ -461,7 +416,8 @@ opens the indexSheet
[indexSheet makeFirstResponder:indexedColumnsField];
// Check to see whether a primary key already exists for the table, and if so select an INDEX instead
- for (i = 0; i < [tableFields count]; i++) {
+ for (i = 0; i < [tableFields count]; i++)
+ {
if ([[[tableFields objectAtIndex:i] objectForKey:@"Key"] isEqualToString:@"PRI"]) {
[indexTypeField selectItemAtIndex:1];
[indexNameField setEnabled:YES];
@@ -473,31 +429,19 @@ opens the indexSheet
// Begin the sheet
[NSApp beginSheet:indexSheet
- modalForWindow:tableWindow modalDelegate:self
- didEndSelector:nil contextInfo:nil];
- code = [NSApp runModalForWindow:indexSheet];
-
- [NSApp endSheet:indexSheet];
- [indexSheet orderOut:nil];
-
- //code == -1 -> no columns specified
- //code == 0 -> error while adding index
- //code == 1 -> index added with succes OR sheet closed without adding index
- if ( code == 0 ) {
- NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil,
- nil, nil, [NSString stringWithFormat:NSLocalizedString(@"Couldn't add index.\nMySQL said: %@", @"message of panel when index cannot be created"), [mySQLConnection getLastErrorMessage]]);
- } else if ( code == -1 ) {
- NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil,
- @selector(closeAlertSheet), nil, NSLocalizedString(@"Please insert the columns you want to index.", @"message of panel when no columns are specified to be indexed"));
- }
+ modalForWindow:tableWindow
+ modalDelegate:self
+ didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
+ contextInfo:@"addIndex"];
}
-/*
-closes the indexSheet without adding the index (stops modal session with code 1)
-*/
-- (IBAction)closeIndexSheet:(id)sender
+/**
+ * Closes the current sheet and stops the modal session
+ */
+- (IBAction)closeSheet:(id)sender
{
- [NSApp stopModalWithCode:1];
+ [NSApp endSheet:[sender window] returnCode:[sender tag]];
+ [[sender window] orderOut:self];
}
/*
@@ -858,87 +802,6 @@ fetches the result as an array with a dictionary for each row in it
}
}
-- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(NSString *)contextInfo
-{
- /*
- if contextInfo == addrow: remain in edit-mode if user hits OK, otherwise cancel editing
- if contextInfo == removefield: removes row from mysql-db if user hits ok
- if contextInfo == removeindex: removes index from mysql-db if user hits ok
- if contextInfo == cannotremovefield: do nothing
- */
-
- if ( [contextInfo isEqualToString:@"addrow"] ) {
- [sheet orderOut:self];
-
- alertSheetOpened = NO;
- if ( returnCode == NSAlertDefaultReturn ) {
- //problem: reentering edit mode for first cell doesn't function
- [tableSourceView editColumn:0 row:[tableSourceView selectedRow] withEvent:nil select:YES];
- } else {
- if ( !isEditingNewRow ) {
- [tableFields replaceObjectAtIndex:[tableSourceView selectedRow]
- withObject:[NSMutableDictionary dictionaryWithDictionary:oldRow]];
- isEditingRow = NO;
- } else {
- [tableFields removeObjectAtIndex:[tableSourceView selectedRow]];
- isEditingRow = NO;
- isEditingNewRow = NO;
- }
- currentlyEditingRow = -1;
- }
- [tableSourceView reloadData];
- } else if ( [contextInfo isEqualToString:@"removefield"] ) {
- if ( returnCode == NSAlertDefaultReturn ) {
- //remove row
- [mySQLConnection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ DROP %@",
- [selectedTable backtickQuotedString], [[[tableFields objectAtIndex:[tableSourceView selectedRow]] objectForKey:@"Field"] backtickQuotedString]]];
-
- if ( [[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) {
- [tableDataInstance resetAllData];
- [tablesListInstance setStatusRequiresReload:YES];
- [self loadTable:selectedTable];
-
- // Mark the content table cache for refresh
- [tablesListInstance setContentRequiresReload:YES];
- } else {
- [self performSelector:@selector(showErrorSheetWith:)
- withObject:[NSArray arrayWithObjects:NSLocalizedString(@"Error", @"error"),
- [NSString stringWithFormat:NSLocalizedString(@"Couldn't remove field %@.\nMySQL said: %@", @"message of panel when field cannot be removed"),
- [[tableFields objectAtIndex:[tableSourceView selectedRow]] objectForKey:@"Field"],
- [mySQLConnection getLastErrorMessage]],
- nil]
- afterDelay:0.3];
- }
- }
- } else if ( [contextInfo isEqualToString:@"removeindex"] ) {
- if ( returnCode == NSAlertAlternateReturn ) {
- //remove index
- if ( [[[indexes objectAtIndex:[indexView selectedRow]] objectForKey:@"Key_name"] isEqualToString:@"PRIMARY"] ) {
- [mySQLConnection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ DROP PRIMARY KEY", [selectedTable backtickQuotedString]]];
- } else {
- [mySQLConnection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ DROP INDEX %@",
- [selectedTable backtickQuotedString], [[[indexes objectAtIndex:[indexView selectedRow]] objectForKey:@"Key_name"] backtickQuotedString]]];
- }
-
- if ( [[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) {
- [tableDataInstance resetAllData];
- [tablesListInstance setStatusRequiresReload:YES];
- [self loadTable:selectedTable];
- } else {
- [self performSelector:@selector(showErrorSheetWith:)
- withObject:[NSArray arrayWithObjects:NSLocalizedString(@"Error", @"error"),
- [NSString stringWithFormat:NSLocalizedString(@"Couldn't remove index.\nMySQL said: %@", @"message of panel when index cannot be removed"),
- [mySQLConnection getLastErrorMessage]],
- nil]
- afterDelay:0.3];
- }
- }
- } else if ( [contextInfo isEqualToString:@"cannotremovefield"]) {
- ;
- }
-
-}
-
/*
* Show Error sheet (can be called from inside of a endSheet selector)
* via [self performSelector:@selector(showErrorSheetWithTitle:) withObject: afterDelay:]
@@ -986,6 +849,84 @@ fetches the result as an array with a dictionary for each row in it
}
#pragma mark -
+#pragma mark Alert sheet methods
+
+/**
+ * Called whenever a sheet is dismissed.
+ *
+ * if contextInfo == addrow: remain in edit-mode if user hits OK, otherwise cancel editing
+ * if contextInfo == removefield: removes row from mysql-db if user hits ok
+ * if contextInfo == removeindex: removes index from mysql-db if user hits ok
+ * if contextInfo == addIndex: adds and index to the mysql-db if user hits ok
+ * if contextInfo == cannotremovefield: do nothing
+ */
+- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(NSString *)contextInfo
+{
+ // Order out current sheet to suppress overlapping of sheets
+ if ([sheet respondsToSelector:@selector(orderOut:)]) [sheet orderOut:nil];
+
+ if ([contextInfo isEqualToString:@"addrow"]) {
+
+ alertSheetOpened = NO;
+ if ( returnCode == NSAlertDefaultReturn ) {
+
+ // Problem: reentering edit mode for first cell doesn't function
+ [tableSourceView editColumn:0 row:[tableSourceView selectedRow] withEvent:nil select:YES];
+ } else {
+ if ( !isEditingNewRow ) {
+ [tableFields replaceObjectAtIndex:[tableSourceView selectedRow]
+ withObject:[NSMutableDictionary dictionaryWithDictionary:oldRow]];
+ isEditingRow = NO;
+ } else {
+ [tableFields removeObjectAtIndex:[tableSourceView selectedRow]];
+ isEditingRow = NO;
+ isEditingNewRow = NO;
+ }
+ currentlyEditingRow = -1;
+ }
+ [tableSourceView reloadData];
+ }
+ else if ([contextInfo isEqualToString:@"removefield"]) {
+ if (returnCode == NSAlertDefaultReturn) {
+
+ // Remove row
+ [mySQLConnection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ DROP %@",
+ [selectedTable backtickQuotedString], [[[tableFields objectAtIndex:[tableSourceView selectedRow]] objectForKey:@"Field"] backtickQuotedString]]];
+
+ if ( [[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) {
+ [tableDataInstance resetAllData];
+ [tablesListInstance setStatusRequiresReload:YES];
+ [self loadTable:selectedTable];
+
+ // Mark the content table cache for refresh
+ [tablesListInstance setContentRequiresReload:YES];
+ } else {
+ [self performSelector:@selector(showErrorSheetWith:)
+ withObject:[NSArray arrayWithObjects:NSLocalizedString(@"Error", @"error"),
+ [NSString stringWithFormat:NSLocalizedString(@"Couldn't remove field %@.\nMySQL said: %@", @"message of panel when field cannot be removed"),
+ [[tableFields objectAtIndex:[tableSourceView selectedRow]] objectForKey:@"Field"],
+ [mySQLConnection getLastErrorMessage]],
+ nil]
+ afterDelay:0.3];
+ }
+ }
+ }
+ else if ([contextInfo isEqualToString:@"addIndex"]) {
+ if (returnCode == NSOKButton) {
+ [self _addIndex];
+ }
+ }
+ else if ([contextInfo isEqualToString:@"removeIndex"]) {
+ if (returnCode == NSAlertAlternateReturn) {
+ [self _removeIndex];
+ }
+ }
+ else if ([contextInfo isEqualToString:@"cannotremovefield"]) {
+ ;
+ }
+}
+
+#pragma mark -
#pragma mark Getter methods
/*
@@ -1492,3 +1433,88 @@ would result in a position change.
}
@end
+
+@implementation TableSource (PrivateAPI)
+
+/**
+ * Adds an index to the current table.
+ */
+- (IBAction)_addIndex;
+{
+ NSString *indexName;
+ NSArray *indexedColumns;
+ NSMutableArray *tempIndexedColumns = [NSMutableArray array];
+ NSString *string;
+
+ // Check whether a save of the current fields row is required.
+ if (![self saveRowOnDeselect]) return;
+
+ if (![[indexedColumnsField stringValue] isEqualToString:@""]) {
+
+ if ([[indexNameField stringValue] isEqualToString:@"PRIMARY"]) {
+ indexName = @"";
+ }
+ else {
+ indexName = ([[indexNameField stringValue] isEqualToString:@""]) ? @"" : [[indexNameField stringValue] backtickQuotedString];
+ }
+
+ indexedColumns = [[indexedColumnsField stringValue] componentsSeparatedByString:@","];
+
+ NSEnumerator *enumerator = [indexedColumns objectEnumerator];
+
+ while ((string = [enumerator nextObject]))
+ {
+ if (([string characterAtIndex:0] == ' ')) {
+ [tempIndexedColumns addObject:[string substringWithRange:NSMakeRange(1, ([string length] - 1))]];
+ }
+ else {
+ [tempIndexedColumns addObject:[NSString stringWithString:string]];
+ }
+ }
+
+ // Execute the query
+ [mySQLConnection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ ADD %@ %@ (%@)",
+ [selectedTable backtickQuotedString], [indexTypeField titleOfSelectedItem], indexName,
+ [tempIndexedColumns componentsJoinedAndBacktickQuoted]]];
+
+ // Check for errors
+ if ([[mySQLConnection getLastErrorMessage] isEqualToString:@""]) {
+ [tableDataInstance resetAllData];
+ [tablesListInstance setStatusRequiresReload:YES];
+ [self loadTable:selectedTable];
+ }
+ else {
+ NSBeginAlertSheet(NSLocalizedString(@"Unable to add index", @"add index error message"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil,
+ [NSString stringWithFormat:NSLocalizedString(@"An error occured while trying to add the index.\n\nMySQL said: %@", @"add index error informative message"), [mySQLConnection getLastErrorMessage]]);
+ }
+ }
+}
+
+/**
+ * Removes an index from the current table.
+ */
+- (void)_removeIndex
+{
+ if ([[[indexes objectAtIndex:[indexView selectedRow]] objectForKey:@"Key_name"] isEqualToString:@"PRIMARY"]) {
+ [mySQLConnection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ DROP PRIMARY KEY", [selectedTable backtickQuotedString]]];
+ }
+ else {
+ [mySQLConnection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ DROP INDEX %@",
+ [selectedTable backtickQuotedString], [[[indexes objectAtIndex:[indexView selectedRow]] objectForKey:@"Key_name"] backtickQuotedString]]];
+ }
+
+ // Check for errors
+ if ([[mySQLConnection getLastErrorMessage] isEqualToString:@""]) {
+ [tableDataInstance resetAllData];
+ [tablesListInstance setStatusRequiresReload:YES];
+ [self loadTable:selectedTable];
+ }
+ else {
+ [self performSelector:@selector(showErrorSheetWith:)
+ withObject:[NSArray arrayWithObjects:NSLocalizedString(@"Unable to remove index", @"error removing index message"),
+ [NSString stringWithFormat:NSLocalizedString(@"An error occured while trying to remove the index.\n\nMySQL said: %@", @"error removing index informative message"), [mySQLConnection getLastErrorMessage]], nil]
+ afterDelay:0.3];
+ }
+}
+
+@end
diff --git a/Source/TablesList.m b/Source/TablesList.m
index c5102121..e35b65e1 100644
--- a/Source/TablesList.m
+++ b/Source/TablesList.m
@@ -497,7 +497,7 @@
- (void)sheetDidEnd:(id)sheet returnCode:(int)returnCode contextInfo:(NSString *)contextInfo
{
// Order out current sheet to suppress overlapping of sheets
- if([sheet respondsToSelector:@selector(orderOut:)])
+ if ([sheet respondsToSelector:@selector(orderOut:)])
[sheet orderOut:nil];
if ([contextInfo isEqualToString:@"addRow"]) {