diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/TableSource.h | 24 | ||||
-rw-r--r-- | Source/TableSource.m | 67 |
2 files changed, 7 insertions, 84 deletions
diff --git a/Source/TableSource.h b/Source/TableSource.h index 66149586..9776620e 100644 --- a/Source/TableSource.h +++ b/Source/TableSource.h @@ -28,9 +28,8 @@ #import "CMMCPConnection.h" #import "CMMCPResult.h" - -@interface TableSource : NSObject { - +@interface TableSource : NSObject +{ IBOutlet id tablesListInstance; IBOutlet id tableDataInstance; @@ -48,15 +47,14 @@ IBOutlet id indexNameField; IBOutlet id indexedColumnsField; IBOutlet id chooseKeyButton; - IBOutlet id tableTypeButton; IBOutlet id structureGrabber; + IBOutlet id editTableButton; CMMCPConnection *mySQLConnection; CMMCPResult *tableSourceResult; CMMCPResult *indexResult; NSString *selectedTable; - NSString *tableType; NSMutableArray *tableFields, *indexes; NSMutableDictionary *oldRow, *enumFields; NSDictionary *defaultValues; @@ -75,7 +73,6 @@ - (IBAction)addIndex:(id)sender; - (IBAction)removeField:(id)sender; - (IBAction)removeIndex:(id)sender; -- (IBAction)typeChanged:(id)sender; //index sheet methods - (IBAction)openIndexSheet:(id)sender; @@ -91,7 +88,6 @@ - (NSArray *)fetchResultAsArray:(CMMCPResult *)theResult; - (BOOL)saveRowOnDeselect; - (BOOL)addRowToDB; -- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(NSString *)contextInfo; //getter methods - (NSString *)defaultValueForField:(NSString *)field; @@ -99,16 +95,6 @@ - (NSDictionary *)enumFields; - (NSArray *)tableStructureForPrint; -//tableView datasource methods -- (int)numberOfRowsInTableView:(NSTableView *)aTableView; -- (id)tableView:(NSTableView *)aTableView - objectValueForTableColumn:(NSTableColumn *)aTableColumn - row:(int)rowIndex; -- (void)tableView:(NSTableView *)aTableView - setObjectValue:(id)anObject - forTableColumn:(NSTableColumn *)aTableColumn - row:(int)rowIndex; - //tableView drag&drop datasource methods - (BOOL)tableView:(NSTableView *)tv writeRows:(NSArray*)rows toPasteboard:(NSPasteboard*)pboard; - (NSDragOperation)tableView:(NSTableView*)tv validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row @@ -126,8 +112,4 @@ - (float)splitView:(NSSplitView *)sender constrainMinCoordinate:(float)proposedMin ofSubviewAt:(int)offset; - (NSRect)splitView:(NSSplitView *)splitView additionalEffectiveRectOfDividerAtIndex:(int)dividerIndex; -//last but not least -- (id)init; -- (void)dealloc; - @end diff --git a/Source/TableSource.m b/Source/TableSource.m index cf7a7232..8ed241b8 100644 --- a/Source/TableSource.m +++ b/Source/TableSource.m @@ -70,15 +70,14 @@ loads aTable, put it in an array, update the tableViewColumns and reload the tab [removeFieldButton setEnabled:NO]; [addIndexButton setEnabled:NO]; [removeIndexButton setEnabled:NO]; - - // set the table type menu back to the default, and disable it - [tableTypeButton selectItemAtIndex:0]; - [tableTypeButton setEnabled:NO]; - tableType = nil; + [editTableButton setEnabled:NO]; return; } + // Enable edit table button + [editTableButton setEnabled:YES]; + //query started [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryWillBePerformed" object:self]; @@ -95,10 +94,6 @@ loads aTable, put it in an array, update the tableViewColumns and reload the tab // [indexes setArray:[[self fetchResultAsArray:indexResult] retain]]; [indexes setArray:[self fetchResultAsArray:indexResult]]; [indexResult release]; - - // Retrieve the table type via the table data's status cache (which automatically maps Type to Engine) - [tableType release]; - tableType = [[NSString stringWithString:[tableDataInstance statusValueForKey:@"Engine"]] retain]; //get table default values if ( defaultValues ) { @@ -176,15 +171,6 @@ loads aTable, put it in an array, update the tableViewColumns and reload the tab [field setObject:length forKey:@"Length"]; } - // Determine the table type - if ( ![tableType isKindOfClass:[NSNull class]] && [tablesListInstance tableType] != SP_TABLETYPE_VIEW) { - [tableTypeButton selectItemWithTitle:tableType]; - [tableTypeButton setEnabled:YES]; - } else { - [tableTypeButton selectItemWithTitle:@"--"]; - [tableTypeButton setEnabled:NO]; - } - // If a view is selected, disable the buttons; otherwise enable. BOOL editingEnabled = ([tablesListInstance tableType] == SP_TABLETYPE_TABLE); [addFieldButton setEnabled:editingEnabled]; @@ -398,51 +384,6 @@ reloads the table (performing a new mysql-query) [alert beginSheetModalForWindow:tableWindow modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:@"removeindex"]; } -- (IBAction)typeChanged:(id)sender -{ - // Check whether a save of the current row is required. - if ( ![self saveRowOnDeselect] ) { - [sender selectItemWithTitle:tableType]; - return; - } - - NSString* selectedItem = [sender titleOfSelectedItem]; - if([selectedItem isEqualToString:@"--"] || [tableType isEqualToString:selectedItem]) { - [sender selectItemWithTitle:tableType]; - } else { - // alert any listeners that we are about to perform a query. - [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryWillBePerformed" object:self]; - - NSString *query = [NSString stringWithFormat:@"ALTER TABLE %@ TYPE = %@",[selectedTable backtickQuotedString],selectedItem]; - [mySQLConnection queryString:query]; - - // The query is now complete. - [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:self]; - - // Did the alter work? If so, we need to record the new data. If not, we must revert back to - // the previous state. - if([mySQLConnection getLastErrorID] == 0) - { - // Make sure "tableType" is changed and the status tab is flagged for reload... - [tableType release]; - tableType = selectedItem; - [tableType retain]; - -// [[NSNotificationCenter defaultCenter] postNotificationName:@"SelectedTableStatusHasChanged" object:self]; - - // Mark the content table for refresh and update column caches - [tablesListInstance setContentRequiresReload:YES]; - [tableDataInstance resetColumnData]; - } else { - [sender selectItemWithTitle:tableType]; - NSBeginAlertSheet(NSLocalizedString(@"Error changing table type", @"error changing table type message"), - NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil, - [NSString stringWithFormat:NSLocalizedString(@"An error occurred when trying to change the table to '%@' from '%@'.\n\nMySQL said: %@", @"error changing table type informative message"), selectedItem, tableType, [mySQLConnection getLastErrorMessage]]); - } - } -} - - #pragma mark Index sheet methods /* |